diff options
author | Max Kellermann <max@musicpd.org> | 2019-05-29 13:31:54 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-05-29 13:31:54 +0200 |
commit | 971450f0d4970b03668cdc527d27948d7166cb72 (patch) | |
tree | bf6d63c85756427316ede3f0997e52ac83ecb208 /src/input | |
parent | 40a48cfba0ab5f654373eb4c82a15851f5c94e3b (diff) |
input/InputStream: make IsEOF() and IsAvailable() const
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/AsyncInputStream.cxx | 4 | ||||
-rw-r--r-- | src/input/AsyncInputStream.hxx | 4 | ||||
-rw-r--r-- | src/input/BufferedInputStream.cxx | 4 | ||||
-rw-r--r-- | src/input/BufferedInputStream.hxx | 4 | ||||
-rw-r--r-- | src/input/BufferingInputStream.cxx | 2 | ||||
-rw-r--r-- | src/input/BufferingInputStream.hxx | 6 | ||||
-rw-r--r-- | src/input/FailingInputStream.hxx | 2 | ||||
-rw-r--r-- | src/input/InputStream.cxx | 4 | ||||
-rw-r--r-- | src/input/InputStream.hxx | 6 | ||||
-rw-r--r-- | src/input/ProxyInputStream.cxx | 4 | ||||
-rw-r--r-- | src/input/ProxyInputStream.hxx | 4 | ||||
-rw-r--r-- | src/input/RewindInputStream.cxx | 2 | ||||
-rw-r--r-- | src/input/ThreadInputStream.cxx | 4 | ||||
-rw-r--r-- | src/input/ThreadInputStream.hxx | 6 | ||||
-rw-r--r-- | src/input/plugins/CdioParanoiaInputPlugin.cxx | 4 | ||||
-rw-r--r-- | src/input/plugins/FfmpegInputPlugin.cxx | 4 | ||||
-rw-r--r-- | src/input/plugins/FileInputPlugin.cxx | 2 | ||||
-rw-r--r-- | src/input/plugins/SmbclientInputPlugin.cxx | 2 |
18 files changed, 35 insertions, 33 deletions
diff --git a/src/input/AsyncInputStream.cxx b/src/input/AsyncInputStream.cxx index 817922ecb..12b03aac1 100644 --- a/src/input/AsyncInputStream.cxx +++ b/src/input/AsyncInputStream.cxx @@ -88,7 +88,7 @@ AsyncInputStream::Check() } bool -AsyncInputStream::IsEOF() noexcept +AsyncInputStream::IsEOF() const noexcept { return (KnownSize() && offset >= size) || (!open && buffer.empty()); @@ -164,7 +164,7 @@ AsyncInputStream::ReadTag() noexcept } bool -AsyncInputStream::IsAvailable() noexcept +AsyncInputStream::IsAvailable() const noexcept { return postponed_exception || IsEOF() || diff --git a/src/input/AsyncInputStream.hxx b/src/input/AsyncInputStream.hxx index 2577cd9fa..8d3fc7c5e 100644 --- a/src/input/AsyncInputStream.hxx +++ b/src/input/AsyncInputStream.hxx @@ -82,11 +82,11 @@ public: /* virtual methods from InputStream */ void Check() final; - bool IsEOF() noexcept final; + bool IsEOF() const noexcept final; void Seek(std::unique_lock<Mutex> &lock, offset_type new_offset) final; std::unique_ptr<Tag> ReadTag() noexcept final; - bool IsAvailable() noexcept final; + bool IsAvailable() const noexcept final; size_t Read(std::unique_lock<Mutex> &lock, void *ptr, size_t read_size) final; diff --git a/src/input/BufferedInputStream.cxx b/src/input/BufferedInputStream.cxx index ae99a2913..d5896e6a4 100644 --- a/src/input/BufferedInputStream.cxx +++ b/src/input/BufferedInputStream.cxx @@ -53,13 +53,13 @@ BufferedInputStream::Seek(std::unique_lock<Mutex> &, } bool -BufferedInputStream::IsEOF() noexcept +BufferedInputStream::IsEOF() const noexcept { return InputStream::offset == BufferingInputStream::size(); } bool -BufferedInputStream::IsAvailable() noexcept +BufferedInputStream::IsAvailable() const noexcept { return BufferingInputStream::IsAvailable(offset); } diff --git a/src/input/BufferedInputStream.hxx b/src/input/BufferedInputStream.hxx index 74b2ef492..863a91508 100644 --- a/src/input/BufferedInputStream.hxx +++ b/src/input/BufferedInputStream.hxx @@ -55,10 +55,10 @@ public: have been copied already in our constructor */ //void Update() noexcept; void Seek(std::unique_lock<Mutex> &lock, offset_type offset) override; - bool IsEOF() noexcept override; + bool IsEOF() const noexcept override; /* we don't support tags */ // std::unique_ptr<Tag> ReadTag() override; - bool IsAvailable() noexcept override; + bool IsAvailable() const noexcept override; size_t Read(std::unique_lock<Mutex> &lock, void *ptr, size_t size) override; diff --git a/src/input/BufferingInputStream.cxx b/src/input/BufferingInputStream.cxx index feca9f68e..8888f597c 100644 --- a/src/input/BufferingInputStream.cxx +++ b/src/input/BufferingInputStream.cxx @@ -56,7 +56,7 @@ BufferingInputStream::Check() } bool -BufferingInputStream::IsAvailable(size_t offset) noexcept +BufferingInputStream::IsAvailable(size_t offset) const noexcept { if (offset >= size() || error) return true; diff --git a/src/input/BufferingInputStream.hxx b/src/input/BufferingInputStream.hxx index 57abe10cf..6f94575c6 100644 --- a/src/input/BufferingInputStream.hxx +++ b/src/input/BufferingInputStream.hxx @@ -57,7 +57,9 @@ class BufferingInputStream : InputStreamHandler { bool stop = false; - size_t want_offset = INVALID_OFFSET; + /* must be mutable because IsAvailable() acts as a hint to + modify this attribute */ + mutable size_t want_offset = INVALID_OFFSET; std::exception_ptr error, seek_error; @@ -100,7 +102,7 @@ public: * Check whether data is available in the buffer at the given * offset.. */ - bool IsAvailable(size_t offset) noexcept; + bool IsAvailable(size_t offset) const noexcept; /** * Copy data from the buffer into the given pointer. diff --git a/src/input/FailingInputStream.hxx b/src/input/FailingInputStream.hxx index f150fd972..bb3ea5ea3 100644 --- a/src/input/FailingInputStream.hxx +++ b/src/input/FailingInputStream.hxx @@ -49,7 +49,7 @@ public: std::rethrow_exception(error); } - bool IsEOF() noexcept override { + bool IsEOF() const noexcept override { return false; } diff --git a/src/input/InputStream.cxx b/src/input/InputStream.cxx index f808fb5ee..439c2c178 100644 --- a/src/input/InputStream.cxx +++ b/src/input/InputStream.cxx @@ -105,7 +105,7 @@ InputStream::LockReadTag() noexcept } bool -InputStream::IsAvailable() noexcept +InputStream::IsAvailable() const noexcept { return true; } @@ -153,7 +153,7 @@ InputStream::LockReadFull(void *ptr, size_t _size) } bool -InputStream::LockIsEOF() noexcept +InputStream::LockIsEOF() const noexcept { const std::lock_guard<Mutex> protect(mutex); return IsEOF(); diff --git a/src/input/InputStream.hxx b/src/input/InputStream.hxx index 3a2fc3ce7..82609e14a 100644 --- a/src/input/InputStream.hxx +++ b/src/input/InputStream.hxx @@ -310,14 +310,14 @@ public: * The caller must lock the mutex. */ gcc_pure - virtual bool IsEOF() noexcept = 0; + virtual bool IsEOF() const noexcept = 0; /** * Wrapper for IsEOF() which locks and unlocks the mutex; the * caller must not be holding it already. */ gcc_pure - bool LockIsEOF() noexcept; + bool LockIsEOF() const noexcept; /** * Reads the tag from the stream. @@ -343,7 +343,7 @@ public: * The caller must lock the mutex. */ gcc_pure - virtual bool IsAvailable() noexcept; + virtual bool IsAvailable() const noexcept; /** * Reads data from the stream into the caller-supplied buffer. diff --git a/src/input/ProxyInputStream.cxx b/src/input/ProxyInputStream.cxx index 746612fbd..25a72103c 100644 --- a/src/input/ProxyInputStream.cxx +++ b/src/input/ProxyInputStream.cxx @@ -99,7 +99,7 @@ ProxyInputStream::Seek(std::unique_lock<Mutex> &lock, } bool -ProxyInputStream::IsEOF() noexcept +ProxyInputStream::IsEOF() const noexcept { return input && input->IsEOF(); } @@ -114,7 +114,7 @@ ProxyInputStream::ReadTag() noexcept } bool -ProxyInputStream::IsAvailable() noexcept +ProxyInputStream::IsAvailable() const noexcept { return input && input->IsAvailable(); } diff --git a/src/input/ProxyInputStream.hxx b/src/input/ProxyInputStream.hxx index d030e16ed..bac7700cf 100644 --- a/src/input/ProxyInputStream.hxx +++ b/src/input/ProxyInputStream.hxx @@ -62,9 +62,9 @@ public: void Update() noexcept override; void Seek(std::unique_lock<Mutex> &lock, offset_type new_offset) override; - bool IsEOF() noexcept override; + bool IsEOF() const noexcept override; std::unique_ptr<Tag> ReadTag() noexcept override; - bool IsAvailable() noexcept override; + bool IsAvailable() const noexcept override; size_t Read(std::unique_lock<Mutex> &lock, void *ptr, size_t read_size) override; diff --git a/src/input/RewindInputStream.cxx b/src/input/RewindInputStream.cxx index cb760adb1..19b4a28aa 100644 --- a/src/input/RewindInputStream.cxx +++ b/src/input/RewindInputStream.cxx @@ -56,7 +56,7 @@ public: ProxyInputStream::Update(); } - bool IsEOF() noexcept override { + bool IsEOF() const noexcept override { return !ReadingFromBuffer() && ProxyInputStream::IsEOF(); } diff --git a/src/input/ThreadInputStream.cxx b/src/input/ThreadInputStream.cxx index e1be3ecdc..ac3aa37cb 100644 --- a/src/input/ThreadInputStream.cxx +++ b/src/input/ThreadInputStream.cxx @@ -122,7 +122,7 @@ ThreadInputStream::Check() } bool -ThreadInputStream::IsAvailable() noexcept +ThreadInputStream::IsAvailable() const noexcept { assert(!thread.IsInside()); @@ -160,7 +160,7 @@ ThreadInputStream::Read(std::unique_lock<Mutex> &lock, } bool -ThreadInputStream::IsEOF() noexcept +ThreadInputStream::IsEOF() const noexcept { assert(!thread.IsInside()); diff --git a/src/input/ThreadInputStream.hxx b/src/input/ThreadInputStream.hxx index 3c946e12a..46e6c39f0 100644 --- a/src/input/ThreadInputStream.hxx +++ b/src/input/ThreadInputStream.hxx @@ -91,9 +91,9 @@ public: void Start(); /* virtual methods from InputStream */ - void Check() override final; - bool IsEOF() noexcept final; - bool IsAvailable() noexcept final; + void Check() final; + bool IsEOF() const noexcept final; + bool IsAvailable() const noexcept final; size_t Read(std::unique_lock<Mutex> &lock, void *ptr, size_t size) override final; diff --git a/src/input/plugins/CdioParanoiaInputPlugin.cxx b/src/input/plugins/CdioParanoiaInputPlugin.cxx index 9178f8a4a..8a8a51572 100644 --- a/src/input/plugins/CdioParanoiaInputPlugin.cxx +++ b/src/input/plugins/CdioParanoiaInputPlugin.cxx @@ -90,7 +90,7 @@ class CdioParanoiaInputStream final : public InputStream { } /* virtual methods from InputStream */ - bool IsEOF() noexcept override; + bool IsEOF() const noexcept override; size_t Read(std::unique_lock<Mutex> &lock, void *ptr, size_t size) override; void Seek(std::unique_lock<Mutex> &lock, offset_type offset) override; @@ -344,7 +344,7 @@ CdioParanoiaInputStream::Read(std::unique_lock<Mutex> &, } bool -CdioParanoiaInputStream::IsEOF() noexcept +CdioParanoiaInputStream::IsEOF() const noexcept { return lsn_from + lsn_relofs > lsn_to; } diff --git a/src/input/plugins/FfmpegInputPlugin.cxx b/src/input/plugins/FfmpegInputPlugin.cxx index febc44872..e08caef73 100644 --- a/src/input/plugins/FfmpegInputPlugin.cxx +++ b/src/input/plugins/FfmpegInputPlugin.cxx @@ -48,7 +48,7 @@ public: } /* virtual methods from InputStream */ - bool IsEOF() noexcept override; + bool IsEOF() const noexcept override; size_t Read(std::unique_lock<Mutex> &lock, void *ptr, size_t size) override; void Seek(std::unique_lock<Mutex> &lock, @@ -96,7 +96,7 @@ FfmpegInputStream::Read(std::unique_lock<Mutex> &, } bool -FfmpegInputStream::IsEOF() noexcept +FfmpegInputStream::IsEOF() const noexcept { return io.IsEOF(); } diff --git a/src/input/plugins/FileInputPlugin.cxx b/src/input/plugins/FileInputPlugin.cxx index a61c94c2b..3fc069e0d 100644 --- a/src/input/plugins/FileInputPlugin.cxx +++ b/src/input/plugins/FileInputPlugin.cxx @@ -44,7 +44,7 @@ public: /* virtual methods from InputStream */ - bool IsEOF() noexcept override { + bool IsEOF() const noexcept override { return GetOffset() >= GetSize(); } diff --git a/src/input/plugins/SmbclientInputPlugin.cxx b/src/input/plugins/SmbclientInputPlugin.cxx index 361d0e18e..08ba7f715 100644 --- a/src/input/plugins/SmbclientInputPlugin.cxx +++ b/src/input/plugins/SmbclientInputPlugin.cxx @@ -52,7 +52,7 @@ public: /* virtual methods from InputStream */ - bool IsEOF() noexcept override { + bool IsEOF() const noexcept override { return offset >= size; } |