MADARA
3.4.1
|
General purpose circular buffer container. More...
#include <CircularBuffer.h>
Classes | |
class | const_iterator |
Const input iterator for elements of a CircularBuffer. Usual semantics. More... | |
class | iterator |
Mutable input iterator for elements of a CircularBuffer. Usual semantics. More... | |
Public Member Functions | |
CircularBuffer ()=default | |
Construct with zero capacity. More... | |
CircularBuffer (CircularBuffer &&other) noexcept | |
Move constructor. More... | |
CircularBuffer (const CircularBuffer &other) | |
Copy constructor. More... | |
CircularBuffer (size_t capacity, size_t initial_index=0) | |
Initialize with given capacity. More... | |
~CircularBuffer () noexcept | |
Destructor. More... | |
size_t | actual (size_t i) const |
Convert an actual index, to the modulused actual index within buffer. More... | |
T & | at (size_t i) |
Get a reference to ith element. More... | |
const T & | at (size_t i) const |
Get a const reference to ith element. More... | |
T & | back () |
Get a reference to the back element. Undefined behavior if empty. More... | |
const T & | back () const |
Get a const reference to the back element. Undefined behavior if empty. More... | |
size_t | back_actual () const |
Actual index of back within the buffer. More... | |
size_t | back_index () const |
Index of back element. More... | |
iterator | begin () |
Create a mutable iterator to the front of the buffer. More... | |
const_iterator | begin () const |
Create a const iterator to the front of the buffer. More... | |
size_t | capacity () const |
Number of elements this buffer can hold without dropping any. More... | |
const_iterator | cbegin () const |
Create a const iterator to the back of the buffer. More... | |
const_iterator | cend () const |
Create a const iterator to the back of the buffer. More... | |
ssize_t | check_range (size_t i) const |
Compares given index relative to existing range of elements (front_index() to back_index()) More... | |
void | clear () |
Empty the buffer, destructing all elements. More... | |
void | discard_back () |
Remove the back element and discard it. More... | |
void | discard_front () |
Remove the front element and discard it. More... | |
template<typename... Args> | |
T & | emplace_back (Args &&... args) |
Construct a new element in-place in the back of the buffer. More... | |
bool | empty () const |
Is this CircularBuffer empty? More... | |
iterator | end () |
Create a mutable iterator to the back of the buffer. More... | |
const_iterator | end () const |
Create a const iterator to the back of the buffer. More... | |
T & | front () |
Get a reference to the front element. Undefined behavior if empty. More... | |
const T & | front () const |
Get a const reference to the front element. Undefined behavior if empty. More... | |
size_t | front_actual () const |
Actual index of front within the buffer. More... | |
size_t | front_index () const |
Index of front element. More... | |
T | get_back () |
Get a copy of the front element, or a default constructed value if the buffer is empty. More... | |
T | get_front () |
Get a copy of the front element, or a default constructed value if the buffer is empty. More... | |
CircularBuffer & | operator= (CircularBuffer &&other) noexcept |
Move assignment operator. More... | |
CircularBuffer & | operator= (const CircularBuffer &other) |
Copy assignment operator. More... | |
T & | operator[] (size_t i) |
Get a reference to the ith element. More... | |
const T & | operator[] (size_t i) const |
Get a const reference to the ith element. More... | |
T | pop_back () |
Remove the back element and return it. More... | |
T | pop_front () |
Remove the front element and return it. More... | |
T & | push_back (const T &val) |
Copy the value val to the back of the buffer. More... | |
T & | push_back (T &&val) |
Move the value val to the back of the buffer. More... | |
void | reserve (size_t size) |
Change the capacity of this CircularBuffer. More... | |
size_t | size () const |
Number of elements this buffer currently holds, up to capacity. More... | |
void | swap (CircularBuffer &other) noexcept |
Swaps contents with another CircularBuffer, without copying elements. More... | |
Private Member Functions | |
void | throw_out_of_range (const char *func, size_t i) const |
Private Attributes | |
size_t | back_ = 0 |
size_t | cap_ = 0 |
T * | data_ = nullptr |
size_t | front_ = 0 |
Friends | |
class | const_iterator |
class | iterator |
General purpose circular buffer container.
Differs from some implementations in that it tracks an always-growing index, enabling multiple independent consumers. Overwritten elements are safely seen as missing, and will not silently alias the newer elements overwriting them.
Definition at line 31 of file CircularBuffer.h.
|
default |
Construct with zero capacity.
Not useful in this state. Does not allocate to the heap.
|
inlineexplicit |
Initialize with given capacity.
Up to that many contiguous elements will be held at once. If more than that many elements are added to the back of the buffer, elements from the front will silently be removed.
Definition at line 45 of file CircularBuffer.h.
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Convert an actual index, to the modulused actual index within buffer.
Definition at line 165 of file CircularBuffer.h.
|
inline |
Get a reference to ith element.
Throws std::out_of_range if this index does not currently exist.
Definition at line 624 of file CircularBuffer.h.
|
inline |
Get a const reference to ith element.
Throws std::out_of_range if this index does not currently exist.
Definition at line 634 of file CircularBuffer.h.
|
inline |
Get a reference to the back element. Undefined behavior if empty.
Definition at line 550 of file CircularBuffer.h.
|
inline |
Get a const reference to the back element. Undefined behavior if empty.
Definition at line 556 of file CircularBuffer.h.
|
inline |
Actual index of back within the buffer.
Definition at line 177 of file CircularBuffer.h.
|
inline |
Index of back element.
Definition at line 159 of file CircularBuffer.h.
|
inline |
Create a mutable iterator to the front of the buffer.
Definition at line 488 of file CircularBuffer.h.
|
inline |
Create a const iterator to the front of the buffer.
Definition at line 500 of file CircularBuffer.h.
|
inline |
Number of elements this buffer can hold without dropping any.
Definition at line 141 of file CircularBuffer.h.
|
inline |
Create a const iterator to the back of the buffer.
Definition at line 512 of file CircularBuffer.h.
|
inline |
Create a const iterator to the back of the buffer.
Definition at line 518 of file CircularBuffer.h.
|
inline |
Compares given index relative to existing range of elements (front_index() to back_index())
i | the index to check for existence within range |
Definition at line 584 of file CircularBuffer.h.
|
inline |
Empty the buffer, destructing all elements.
Definition at line 183 of file CircularBuffer.h.
|
inline |
Remove the back element and discard it.
Definition at line 666 of file CircularBuffer.h.
|
inline |
Remove the front element and discard it.
Definition at line 643 of file CircularBuffer.h.
|
inline |
Construct a new element in-place in the back of the buffer.
Will discard the front element if size() already equals capacity().
Definition at line 693 of file CircularBuffer.h.
|
inline |
Is this CircularBuffer empty?
Definition at line 135 of file CircularBuffer.h.
|
inline |
Create a mutable iterator to the back of the buffer.
Definition at line 494 of file CircularBuffer.h.
|
inline |
Create a const iterator to the back of the buffer.
Definition at line 506 of file CircularBuffer.h.
|
inline |
Get a reference to the front element. Undefined behavior if empty.
Definition at line 538 of file CircularBuffer.h.
|
inline |
Get a const reference to the front element. Undefined behavior if empty.
Definition at line 544 of file CircularBuffer.h.
|
inline |
Actual index of front within the buffer.
Definition at line 171 of file CircularBuffer.h.
|
inline |
Index of front element.
Definition at line 153 of file CircularBuffer.h.
|
inline |
Get a copy of the front element, or a default constructed value if the buffer is empty.
Definition at line 570 of file CircularBuffer.h.
|
inline |
Get a copy of the front element, or a default constructed value if the buffer is empty.
Definition at line 563 of file CircularBuffer.h.
|
inlinenoexcept |
Move assignment operator.
Abides by typical semantics.
Definition at line 86 of file CircularBuffer.h.
|
inline |
Copy assignment operator.
Abides by typical semantics.
Definition at line 76 of file CircularBuffer.h.
|
inline |
Get a reference to the ith element.
Undefined behavior if empty, or if index is outside front_index() and back_index().
Definition at line 525 of file CircularBuffer.h.
|
inline |
Get a const reference to the ith element.
Undefined behavior if empty, or if index is outside front_index() and back_index().
Definition at line 532 of file CircularBuffer.h.
|
inline |
Remove the back element and return it.
Definition at line 675 of file CircularBuffer.h.
|
inline |
Remove the front element and return it.
Definition at line 652 of file CircularBuffer.h.
|
inline |
Copy the value val to the back of the buffer.
Will discard the front element if size() already equals capacity().
Definition at line 710 of file CircularBuffer.h.
|
inline |
Move the value val to the back of the buffer.
Will discard the front element if size() already equals capacity().
Definition at line 721 of file CircularBuffer.h.
|
inline |
Change the capacity of this CircularBuffer.
Unlike vectors, this operation will always set capacity to exactly the size given. This operation always moves each element individually.
Definition at line 118 of file CircularBuffer.h.
|
inline |
Number of elements this buffer currently holds, up to capacity.
Definition at line 147 of file CircularBuffer.h.
|
inlinenoexcept |
Swaps contents with another CircularBuffer, without copying elements.
Definition at line 104 of file CircularBuffer.h.
|
inlineprivate |
Definition at line 600 of file CircularBuffer.h.
|
friend |
Definition at line 735 of file CircularBuffer.h.
|
friend |
Definition at line 734 of file CircularBuffer.h.
|
private |
Definition at line 728 of file CircularBuffer.h.
|
private |
Definition at line 732 of file CircularBuffer.h.
|
private |
Definition at line 730 of file CircularBuffer.h.
|
private |
Definition at line 727 of file CircularBuffer.h.