aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-03-15 23:29:07 +0100
committerMax Kellermann <max@duempel.org>2014-03-16 00:28:42 +0100
commit328860c8ba572fd9b8032e6ed07704d79f62234e (patch)
treeaf43c49241a2bf8b910008da7e127d70b924541a /src
parent89ac111853eb4bae2fc358087c4c4657939321c0 (diff)
downloadmpd-328860c8ba572fd9b8032e6ed07704d79f62234e.tar.gz
mpd-328860c8ba572fd9b8032e6ed07704d79f62234e.tar.xz
mpd-328860c8ba572fd9b8032e6ed07704d79f62234e.zip
util/CircularBuffer: add method GetSpace()
Diffstat (limited to '')
-rw-r--r--src/util/CircularBuffer.hxx12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/util/CircularBuffer.hxx b/src/util/CircularBuffer.hxx
index 0321b91f6..da6f412a5 100644
--- a/src/util/CircularBuffer.hxx
+++ b/src/util/CircularBuffer.hxx
@@ -108,6 +108,18 @@ public:
}
/**
+ * Returns the number of elements that can be added to this
+ * buffer.
+ */
+ constexpr size_type GetSpace() const {
+ /* space = capacity - size - 1 */
+ return (head <= tail
+ ? capacity - tail + head
+ : head - tail)
+ - 1;
+ }
+
+ /**
* Prepares writing. Returns a buffer range which may be written.
* When you are finished, call Append().
*/