|
loon
High-performance header-only C++ library for low-latency applications
|
A fixed-size circular buffer (ring buffer) with FIFO semantics. More...
#include <ring_buffer.hpp>
Public Member Functions | |
| 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. | |
| bool | push (const T &value) |
| Pushes a value to the back of the buffer. | |
| std::optional< T > | pop () |
| Removes and returns the front element. | |
| std::optional< T > | front () |
| Returns the front element without removing it. | |
| std::optional< T > | back () |
| Returns the back element without removing it. | |
| bool | discard () |
| Discards the front element without returning it. | |
| size_t | capacity () const |
| Returns the maximum capacity of the buffer. | |
| bool | empty () const |
| Checks if the buffer is empty. | |
| bool | full () const |
| Checks if the buffer is full. | |
| bool | overrides () const |
| Checks if override mode is enabled. | |
| size_t | size () const |
| Returns the current number of elements. | |
A fixed-size circular buffer (ring buffer) with FIFO semantics.
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.
| T | The element type to store. |
| N | The fixed capacity of the buffer (must be > 0). |
Definition at line 29 of file ring_buffer.hpp.
|
inlineexplicit |
Constructs an empty RingBuffer with configurable override behavior.
| override_when_full | If true, push() overwrites oldest element when full. If false, push() returns false when full. |
Definition at line 37 of file ring_buffer.hpp.
|
inline |
Returns the back element without removing it.
Definition at line 81 of file ring_buffer.hpp.
References loon::RingBuffer< T, N >::empty().
|
inline |
Returns the maximum capacity of the buffer.
Definition at line 101 of file ring_buffer.hpp.
|
inline |
Discards the front element without returning it.
Definition at line 90 of file ring_buffer.hpp.
References loon::RingBuffer< T, N >::empty().
|
inline |
Checks if the buffer is empty.
Definition at line 105 of file ring_buffer.hpp.
Referenced by loon::RingBuffer< T, N >::back(), loon::RingBuffer< T, N >::discard(), loon::RingBuffer< T, N >::front(), and loon::RingBuffer< T, N >::pop().
|
inline |
Returns the front element without removing it.
Definition at line 72 of file ring_buffer.hpp.
References loon::RingBuffer< T, N >::empty().
|
inline |
Checks if the buffer is full.
Definition at line 109 of file ring_buffer.hpp.
Referenced by loon::RingBuffer< T, N >::push().
|
inline |
Checks if override mode is enabled.
Definition at line 113 of file ring_buffer.hpp.
|
inline |
Removes and returns the front element.
Definition at line 60 of file ring_buffer.hpp.
References loon::RingBuffer< T, N >::empty().
|
inline |
Pushes a value to the back of the buffer.
| value | The value to push (copied). |
Definition at line 42 of file ring_buffer.hpp.
References loon::RingBuffer< T, N >::full().
|
inline |
Returns the current number of elements.
Definition at line 117 of file ring_buffer.hpp.