A circular buffer of fixed size. Appending can be done indefinitely, as the index will just loop back around to the beginning. More...
#include <circularBuffer.hpp>
Public Member Functions | |
| circularBuffer () noexcept | |
| Default constructor. | |
| template<typename... ARGS> | |
| circularBuffer (const ARGS &...args) noexcept | |
| Initialize the buffer with the contents of an array. | |
| circularBuffer (TYPE default_value) noexcept | |
| Initialize all elements with a single value. | |
| size_t | size () const noexcept override |
| Get the size of the object in memory. | |
| int | length () const noexcept override |
| Get the length of the array. | |
| const TYPE & | at (const int index) const noexcept override |
| Get an element from the buffer. | |
| TYPE & | at (const int index) noexcept |
| Get a modifiable element from the buffer. | |
| void | append (const TYPE value) noexcept |
| Add a value to the buffer, and increment the current index. | |
| int | index () const noexcept |
| Get the index of the current top of the buffer. | |
| TYPE & | current () noexcept |
| Get a reference to the topmost item in the buffer. | |
| int | count () const noexcept |
| Get the total number of items in the buffer. | |
| void | prev () noexcept |
| Move current "top" to the previous spot in the buffer. | |
| void | next () noexcept |
| Move current "top" to the next spot in the buffer. | |
| circularIterator< TYPE, LEN > | begin () const noexcept override |
| Get an iterator for the first element in this object. | |
| circularIterator< TYPE, LEN > | end () const noexcept override |
| Get an iterator after the last element of this object. | |
| template<typename... ARGS> | |
| void | populate (const TYPE &first, const ARGS &...args) noexcept |
| Append an arbitrary number of elements to the buffer. | |
| void | populate (const TYPE &arg) noexcept |
| Append an element to the buffer. | |
| TYPE | minimum () const noexcept |
| Get the minimum value contained in this buffer. | |
| TYPE | maximum () const noexcept |
| Get the maximum value contained in this buffer. | |
Public Member Functions inherited from z::core::sizable | |
| virtual | ~sizable () noexcept |
| Virtual destructor. | |
Public Member Functions inherited from z::core::indexable< T > | |
| virtual | ~indexable () noexcept |
| Virtual destructor. | |
| virtual T | operator[] (int index) const |
| Function to get the object at the given index. | |
Public Member Functions inherited from z::core::iterable< ITER > | |
| virtual | ~iterable () noexcept |
| Virtual destructor. | |
A circular buffer of fixed size. Appending can be done indefinitely, as the index will just loop back around to the beginning.
|
inlinenoexcept |
Initialize the buffer with the contents of an array.
This allows for brace-enclosed initialization e.g. circularBuffer<int, 3> buffer = {1, 2, 3};
| args | A list of elements to append to the buffer. |
|
inlinenoexcept |
Initialize all elements with a single value.
| default_value | The value to initialize elements with. |
Add a value to the buffer, and increment the current index.
| value | The value to append. |
|
inlineoverridevirtualnoexcept |
Get an element from the buffer.
This method is used when we're not modifying the resultant value.
| index | The index of the value we want. |
Implements z::core::indexable< T >.
Get a modifiable element from the buffer.
This method is used when we ARE modifying the resultant value. The compiler knows the difference and will use this function only when needed.
| index | The index of the value we want. |
|
inlineoverridevirtualnoexcept |
Get an iterator for the first element in this object.
This member function should not be used directly. It is meant for C++11's range-based for loop syntax.
Implements z::core::iterable< ITER >.
|
inlinenoexcept |
Get the total number of items in the buffer.
This will return at most the maximum buffer size.
|
inlinenoexcept |
Get a reference to the topmost item in the buffer.
|
inlineoverridevirtualnoexcept |
Get an iterator after the last element of this object.
This member function should not be used directly. It is meant for C++11's range-based for loop syntax.
Implements z::core::iterable< ITER >.
|
inlinenoexcept |
Get the index of the current top of the buffer.
This index will always be a value from 0 to the length of the buffer.
|
inlineoverridevirtualnoexcept |
Get the length of the array.
Implements z::core::arrayLike< const TYPE &, circularIterator< TYPE, LEN > >.
|
inlinenoexcept |
Get the maximum value contained in this buffer.
|
inlinenoexcept |
Get the minimum value contained in this buffer.
Append an element to the buffer.
This is the tail end of calling populate() with 2 or more arguments.
| arg | The element to append. |
|
inlinenoexcept |
Append an arbitrary number of elements to the buffer.
| first | The first element to append. |
| args | All other elements to append. |
|
inlineoverridevirtualnoexcept |
Get the size of the object in memory.
Implements z::core::sizable.