![]() |
CommRaT 2.0.0
C++20 Real-Time Messaging Framework
|
Thread-safe timestamped ring buffer with getData lookup. More...
#include <commrat/mailbox/timestamped_ring_buffer.hpp>
Public Types | |
| using | value_type = T |
| using | size_type = std::size_t |
Public Member Functions | |
| TimestampedRingBuffer (std::chrono::milliseconds default_tolerance=std::chrono::milliseconds(50)) | |
| Constructor with optional sync tolerance. | |
| size_type | size () const |
| Get current number of stored messages. | |
| bool | empty () const |
| Check if buffer is empty. | |
| bool | full () const |
| Check if buffer is full. | |
| void | clear () |
| Clear all messages from buffer. | |
| void | push (const T &message) |
| Push new message with timestamp. | |
| void | push (T &&message) |
| Push new message via move. | |
| std::optional< T > | getData (uint64_t timestamp, std::chrono::milliseconds tolerance=std::chrono::milliseconds(-1), InterpolationMode mode=InterpolationMode::NEAREST) const |
| std::pair< uint64_t, uint64_t > | getTimestampRange () const |
| Get timestamp range currently in buffer. | |
Static Public Member Functions | |
| static constexpr size_type | capacity () |
| Get maximum capacity. | |
Thread-safe timestamped ring buffer with getData lookup.
Wraps SeRTial::RingBuffer with:
| T | Message type (must have .timestamp member) |
| MaxSize | Maximum capacity (default: 100 messages) |
Requirements for T:
Thread Safety:
Example:
Definition at line 102 of file timestamped_ring_buffer.hpp.
| using commrat::TimestampedRingBuffer< T, MaxSize >::size_type = std::size_t |
Definition at line 108 of file timestamped_ring_buffer.hpp.
| using commrat::TimestampedRingBuffer< T, MaxSize >::value_type = T |
Definition at line 107 of file timestamped_ring_buffer.hpp.
|
inlineexplicit |
Constructor with optional sync tolerance.
| default_tolerance | Default tolerance for timestamp matching (ms) |
Definition at line 118 of file timestamped_ring_buffer.hpp.
|
inlinestaticconstexpr |
Get maximum capacity.
Definition at line 140 of file timestamped_ring_buffer.hpp.
|
inline |
Clear all messages from buffer.
Definition at line 168 of file timestamped_ring_buffer.hpp.
|
inline |
Check if buffer is empty.
Definition at line 149 of file timestamped_ring_buffer.hpp.
|
inline |
Check if buffer is full.
Definition at line 159 of file timestamped_ring_buffer.hpp.
|
inline |
Definition at line 276 of file timestamped_ring_buffer.hpp.
References commrat::AFTER, commrat::BEFORE, commrat::INTERPOLATE, and commrat::NEAREST.
|
inline |
Get timestamp range currently in buffer.
Definition at line 329 of file timestamped_ring_buffer.hpp.
|
inline |
Push new message with timestamp.
Messages must be pushed in timestamp order (monotonically increasing). If buffer is full, overwrites oldest message.
| message | Message to store (must have .timestamp field) |
Definition at line 191 of file timestamped_ring_buffer.hpp.
References commrat::TimestampAccessor< T >::get().
|
inline |
Push new message via move.
| message | Message to move into buffer |
Definition at line 219 of file timestamped_ring_buffer.hpp.
References commrat::TimestampAccessor< T >::get().
|
inline |
Get current number of stored messages.
Definition at line 131 of file timestamped_ring_buffer.hpp.