pabigot  0.1.1
C++ support classes
Public Types | Public Member Functions | Static Public Attributes
pabigot::container::rr_adaptor< T > Class Template Reference

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_adaptoroperator= (const rr_adaptor &)=delete
 
 rr_adaptor (rr_adaptor &&)=delete
 
rr_adaptoroperator= (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.
 

Detailed Description

template<typename T = uint8_t>
class pabigot::container::rr_adaptor< T >

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.

Template Parameters
Tthe type of the elements in the buffer.

Member Typedef Documentation

◆ size_type

template<typename T = uint8_t>
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.

Constructor & Destructor Documentation

◆ rr_adaptor()

template<typename T = uint8_t>
constexpr pabigot::container::rr_adaptor< T >::rr_adaptor ( value_type data,
size_type  count 
)
inlineconstexpr

Create an adaptor for round-robin access to a fixed buffer.

Parameters
datapointer to a contiguous sequence of count instances of value_type.
countthe number of instances of value_type available for storage.

Member Function Documentation

◆ max_size()

template<typename T = uint8_t>
size_type pabigot::container::rr_adaptor< T >::max_size ( ) const
inlinenoexcept

The maximum number of values that can be stored in the buffer.

This is one fewer than provided to the constructor so we can distinguish empty() from full() without maintaining a separate flag.

◆ pop()

template<typename T = uint8_t>
value_type pabigot::container::rr_adaptor< T >::pop ( )
inlinenoexcept

Pop a value from the back of the buffer.

If the buffer is empty() this returns a default-initialized object of value_type.

◆ push()

template<typename T = uint8_t>
bool pabigot::container::rr_adaptor< T >::push ( value_type  v)
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.

Returns
true iff the store resulted in discarding a previously-pushed value.

The documentation for this class was generated from the following file: