|
sdi_toolBox
|
#include <circularBuffer.h>
Fixed-size circular buffer with compile-time capacity and no-overwrite behavior.
This template wraps a RingBuffer and prevents new elements from being written when the buffer is full. Existing data is never overwritten; push() simply fails and returns false when capacity is reached.
| T | Element type stored in the buffer. |
| CAPACITY | Compile-time buffer capacity. Must be > 0. |
Definition at line 48 of file circularBuffer.h.
Public Member Functions | |
Write operations | |
| bool | push (const T &value) |
| Try to append a value to the buffer. | |
Read operations | |
| std::optional< T > | pop () |
| Remove and return the oldest element from the buffer. | |
| bool | pop (T &value) |
| Remove the oldest element and store it in the provided reference. | |
| std::optional< T > | front () const |
| Return (without removing) the oldest element. | |
| bool | front (T &value) const |
| Copy the oldest element into the provided reference without removing it. | |
| std::optional< T > | back () const |
| Return (without removing) the newest element. | |
| bool | back (T &value) const |
| Copy the newest element into the provided reference without removing it. | |
State queries | |
| bool | empty () const |
| Check whether the buffer is empty. | |
| bool | full () const |
| Check whether the buffer is full. | |
| std::size_t | size () const |
| Number of elements currently stored in the buffer. | |
| constexpr std::size_t | capacity () const |
| Compile-time capacity of the buffer. | |
Modifiers | |
| void | clear () |
| Clear the buffer and reset internal indices. | |
| bool push | ( | const T & | value | ) |
Try to append a value to the buffer.
If the buffer is full, the value is discarded and no overwrite occurs.
| value | Value to append (copied). |
Definition at line 178 of file circularBuffer.h.
| std::optional< T > pop | ( | ) |
Remove and return the oldest element from the buffer.
Definition at line 188 of file circularBuffer.h.
| bool pop | ( | T & | value | ) |
Remove the oldest element and store it in the provided reference.
| value | Output reference that receives the removed element. |
Definition at line 196 of file circularBuffer.h.
| std::optional< T > front | ( | ) | const |
Return (without removing) the oldest element.
Definition at line 204 of file circularBuffer.h.
| bool front | ( | T & | value | ) | const |
Copy the oldest element into the provided reference without removing it.
| value | Output reference that receives the element. |
Definition at line 212 of file circularBuffer.h.
| std::optional< T > back | ( | ) | const |
Return (without removing) the newest element.
Definition at line 220 of file circularBuffer.h.
| bool back | ( | T & | value | ) | const |
Copy the newest element into the provided reference without removing it.
| value | Output reference that receives the element. |
Definition at line 228 of file circularBuffer.h.
| bool empty | ( | ) | const |
Check whether the buffer is empty.
Definition at line 235 of file circularBuffer.h.
| bool full | ( | ) | const |
Check whether the buffer is full.
Definition at line 242 of file circularBuffer.h.
| std::size_t size | ( | ) | const |
Number of elements currently stored in the buffer.
Definition at line 249 of file circularBuffer.h.
|
constexpr |
Compile-time capacity of the buffer.
Definition at line 256 of file circularBuffer.h.
| void clear | ( | ) |
Clear the buffer and reset internal indices.
After calling clear(), empty() returns true and size() returns 0.
Definition at line 263 of file circularBuffer.h.