util/CircularBuffer: add method GetSpace()

This commit is contained in:
Max Kellermann
2014-03-15 23:29:07 +01:00
parent 89ac111853
commit 328860c8ba
2 changed files with 22 additions and 0 deletions

View File

@@ -107,6 +107,18 @@ public:
: capacity - head + tail;
}
/**
* 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().