30 #ifndef CIRCULAR_BUFFER_HPP
31 #define CIRCULAR_BUFFER_HPP
73 :head(0), tail(0), capacity(_capacity), data(_data) {}
78 constexpr size_type
Next(size_type i)
const {
79 return i + 1 == capacity
107 : capacity - head +
tail;
117 ? capacity - tail + head
127 assert(head < capacity);
128 assert(tail < capacity);
130 size_type end = tail < head
135 : capacity - (head == 0);
137 return Range(data + tail, end - tail);
145 assert(head < capacity);
146 assert(tail < capacity);
147 assert(n < capacity);
148 assert(tail + n <= capacity);
149 assert(head <= tail || tail + n < head);
153 if (tail == capacity) {
164 assert(head < capacity);
165 assert(tail < capacity);
167 return Range(data + head, (tail < head ? capacity : tail) - head);
174 assert(head < capacity);
175 assert(tail < capacity);
176 assert(n < capacity);
177 assert(head + n <= capacity);
178 assert(tail < head || head + n <= tail);
181 if (head == capacity)
size_type head
The next index to be read.
Range::pointer_type pointer_type
A reference to a memory area that is writable.
WritableBuffer< T > Range
void Consume(size_type n)
Marks a chunk as consumed.
Range Read()
Return a buffer range which may be read.
Range Write()
Prepares writing.
constexpr size_type GetSpace() const
Returns the number of elements that can be added to this buffer.
constexpr bool IsFull() const
constexpr bool IsEmpty() const
void Append(size_type n)
Expands the tail of the buffer, after data has been written to the buffer returned by Write()...
size_type tail
The next index to be written to.
constexpr size_type GetSize() const
Returns the number of elements stored in this buffer.
Range::size_type size_type
constexpr size_type GetCapacity() const
constexpr size_type Next(size_type i) const
constexpr CircularBuffer(pointer_type _data, size_type _capacity)