Class loon::RingBuffer¶
template <typename T, size_t N>
ClassList > loon > RingBuffer
A fixed-size circular buffer (ring buffer) with FIFO semantics. More...
#include <ring_buffer.hpp>
Public Functions¶
| Type | Name |
|---|---|
| RingBuffer () = default Constructs an empty RingBuffer with default behavior (reject when full). |
|
| RingBuffer (bool override_when_full) Constructs an empty RingBuffer with configurable override behavior. |
|
| std::optional< T > | back () Returns the back element without removing it. |
| size_t | capacity () const Returns the maximum capacity of the buffer. |
| bool | discard () Discards the front element without returning it. |
| bool | empty () const Checks if the buffer is empty. |
| std::optional< T > | front () Returns the front element without removing it. |
| bool | full () const Checks if the buffer is full. |
| bool | overrides () const Checks if override mode is enabled. |
| std::optional< T > | pop () Removes and returns the front element. |
| bool | push (const T & value) Pushes a value to the back of the buffer. |
| size_t | size () const Returns the current number of elements. |
Detailed Description¶
RingBuffer provides O(1) push and pop operations with a compile-time fixed capacity. When full, it can either reject new elements or override the oldest element depending on configuration.
Template parameters:
TThe element type to store.NThe fixed capacity of the buffer (must be > 0).
** **
loon::RingBuffer<int, 10> buffer;
buffer.push(42);
buffer.push(43);
auto val = buffer.pop(); // returns 42
Public Functions Documentation¶
function RingBuffer [1/2]¶
Constructs an empty RingBuffer with default behavior (reject when full).
function RingBuffer [2/2]¶
Constructs an empty RingBuffer with configurable override behavior.
Parameters:
override_when_fullIf true, push() overwrites oldest element when full. If false, push() returns false when full.
function back¶
Returns the back element without removing it.
Returns:
The back element, or std::nullopt if empty.
function capacity¶
Returns the maximum capacity of the buffer.
Returns:
The compile-time capacity N.
function discard¶
Discards the front element without returning it.
Returns:
true if an element was discarded, false if buffer was empty.
function empty¶
Checks if the buffer is empty.
Returns:
true if the buffer contains no elements.
function front¶
Returns the front element without removing it.
Returns:
The front element, or std::nullopt if empty.
function full¶
Checks if the buffer is full.
Returns:
true if the buffer contains N elements.
function overrides¶
Checks if override mode is enabled.
Returns:
true if push() will override oldest element when full.
function pop¶
Removes and returns the front element.
Returns:
The front element, or std::nullopt if empty.
function push¶
Pushes a value to the back of the buffer.
Parameters:
valueThe value to push (copied).
Returns:
true if the value was added, false if buffer is full and override is disabled.
function size¶
Returns the current number of elements.
Returns:
The number of elements in the buffer.
The documentation for this class was generated from the following file include/loon/ring_buffer.hpp