From 89ac111853eb4bae2fc358087c4c4657939321c0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 15 Mar 2014 23:11:13 +0100 Subject: util/CircularBuffer: add method GetSize() --- src/util/CircularBuffer.hxx | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/util/CircularBuffer.hxx b/src/util/CircularBuffer.hxx index 67b60e198..0321b91f6 100644 --- a/src/util/CircularBuffer.hxx +++ b/src/util/CircularBuffer.hxx @@ -98,6 +98,15 @@ public: return Next(tail) == head; } + /** + * Returns the number of elements stored in this buffer. + */ + constexpr size_type GetSize() const { + return head <= tail + ? tail - head + : capacity - head + tail; + } + /** * Prepares writing. Returns a buffer range which may be written. * When you are finished, call Append(). -- cgit v1.2.3