pabigot
0.1.1
C++ support classes
|
A basic round-robin (circular) homogeneous buffer with externally-allocated capacity. More...
#include </mnt/devel/pabigot-cxx/include/pabigot/container.hpp>
Public Types | |
using | value_type = T |
Type alias for the elements of the buffer. | |
using | size_type = uint16_t |
Type alias for representing the size of the buffer. More... | |
using | ssize_type = std::make_signed< size_type >::type |
Type alias for signed size values. | |
Public Member Functions | |
constexpr | rr_adaptor (value_type *data, size_type count) |
Create an adaptor for round-robin access to a fixed buffer. More... | |
rr_adaptor (const rr_adaptor &)=delete | |
rr_adaptor & | operator= (const rr_adaptor &)=delete |
rr_adaptor (rr_adaptor &&)=delete | |
rr_adaptor & | operator= (rr_adaptor &&)=delete |
bool | empty () const noexcept |
true iff the buffer has no data in it. | |
bool | full () const noexcept |
true if the buffer cannot receive more data without discarding an element. | |
size_type | max_size () const noexcept |
The maximum number of values that can be stored in the buffer. More... | |
size_type | size () const noexcept |
The number of values currently stored in the buffer. | |
bool | push (value_type v) noexcept |
Push a new value at the front of the buffer. More... | |
value_type | pop () noexcept |
Pop a value from the back of the buffer. More... | |
void | clear () noexcept |
Restore the buffer to an empty state. | |
Static Public Attributes | |
static constexpr size_type | EMPTY_HEAD = -1 |
Marker value stored in #head_ to indicate that the buffer is empty. | |
A basic round-robin (circular) homogeneous buffer with externally-allocated capacity.
Intended for use in embedded systems. You don't get to make copies or move them so you probably want a static allocation as a global variable instead of defining one on a stack somewhere.
T | the type of the elements in the buffer. |
using pabigot::container::rr_adaptor< T >::size_type = uint16_t |
Type alias for representing the size of the buffer.
This class is intended to be used in embedded systems, so the capacity is limited. Most applications would work with a maximum of 255 elements, but none should require more than 65535.
Really, if you want bigger buffers you should be using std::queue.
|
inlineconstexpr |
Create an adaptor for round-robin access to a fixed buffer.
data | pointer to a contiguous sequence of count instances of value_type. |
count | the number of instances of value_type available for storage. |
|
inlinenoexcept |
|
inlinenoexcept |
Pop a value from the back of the buffer.
If the buffer is empty() this returns a default-initialized object of value_type.
|
inlinenoexcept |
Push a new value at the front of the buffer.
If the buffer is full() this overwrites a previously-pushed value. The caller is responsible for preventing that if desired.
true
iff the store resulted in discarding a previously-pushed value.