|
My Project
|
A fixed-capacity ring buffer (circular buffer). More...
#include <ring_buffer.hpp>
Public Member Functions | |
| RingBuffer (size_t capacity=0) | |
| Constructs a RingBuffer with a given capacity. More... | |
| void | set_capacity (size_t capacity) |
| Resizes and resets the buffer. More... | |
| void | push_back (const T &val) |
| Pushes a new element into the buffer. More... | |
| T & | operator[] (size_t i) |
| Access element by logical index (0 is oldest). More... | |
| const T & | operator[] (size_t i) const |
| Construct element by logical index (0 is oldest). More... | |
| T & | back () |
| Access the newest element. More... | |
| const T & | back () const |
| Access the newest element (const). More... | |
| size_t | size () const |
| Returns the number of elements currently stored. More... | |
| bool | empty () const |
| Checks if the buffer is empty. More... | |
| bool | full () const |
| Checks if the buffer is full. More... | |
| void | clear () |
| Clears the buffer content. More... | |
| void | reserve (size_t n) |
| Reserve capacity (resets buffer if new capacity > old capacity). More... | |
A fixed-capacity ring buffer (circular buffer).
Efficiently stores a sliding window of elements. Pushing back when full overwrites the oldest element (logical index 0). Accessing index i corresponds to the (i)-th oldest element.
|
inlineexplicit |
Constructs a RingBuffer with a given capacity.
| capacity | Maximum number of elements to store. |
|
inline |
Access the newest element.

|
inline |
Access the newest element (const).
|
inline |
Clears the buffer content.

|
inline |
Checks if the buffer is empty.

|
inline |
Checks if the buffer is full.
|
inline |
Access element by logical index (0 is oldest).
| i | Index. |
|
inline |
Construct element by logical index (0 is oldest).
| i | Index. |
|
inline |
Pushes a new element into the buffer.
If the buffer is full, the oldest element is overwritten.
| val | The value to push. |

|
inline |
Reserve capacity (resets buffer if new capacity > old capacity).
| n | New capacity. |

|
inline |
Resizes and resets the buffer.
| capacity | New capacity. |

|
inline |
Returns the number of elements currently stored.
