Comms CCF
This is a simple communication layer based on COBS, CBOR and FNV-1A
Loading...
Searching...
No Matches
CircularBuffer< Value, Size, MaxPacketSize > Class Template Reference

Classes

class  Frame
class  Iterator

Public Types

using value_type = Value

Public Member Functions

constexpr size_t capacity () const
size_t size () const
size_t readable () const
size_t unnotified () const
bool empty () const
bool full () const
bool dropping () const
template<typename Value_>
requires std::same_as<std::remove_cvref_t<Value>, std::remove_cvref_t<Value_>>
void push_back (Value_ &&v)
void pop_front ()
 Drop the first element from the queue.
Value & front ()
const Value & front () const
void reset_dropped ()
void notify ()
bool get_frame (std::optional< Frame > &frame)
void reset ()
 Reset the queue to the initial, empty state.

Static Public Attributes

static constexpr size_t sizeBytes = sizeof(SmallestTypeT<MaxPacketSize>)

Member Typedef Documentation

◆ value_type

template<typename Value, size_t Size, size_t MaxPacketSize>
using CircularBuffer< Value, Size, MaxPacketSize >::value_type = Value

The wraparound of the index needs to be divisible by the size of the container, so that when index wraps to 0, it also maps to index % Size to 0.

Member Function Documentation

◆ front() [1/2]

template<typename Value, size_t Size, size_t MaxPacketSize>
Value & CircularBuffer< Value, Size, MaxPacketSize >::front ( )
inline

Return the element at the front of the queue. Does not check for overflows.

◆ front() [2/2]

template<typename Value, size_t Size, size_t MaxPacketSize>
const Value & CircularBuffer< Value, Size, MaxPacketSize >::front ( ) const
inline

Return the element at the front of the queue. Does not check for overflows.

◆ get_frame()

template<typename Value, size_t Size, size_t MaxPacketSize>
bool CircularBuffer< Value, Size, MaxPacketSize >::get_frame ( std::optional< Frame > & frame)
inline

Gets the oldest frame, dropping any current frame in the given optional (for FIFO behaviour).

Read once

◆ notify()

template<typename Value, size_t Size, size_t MaxPacketSize>
void CircularBuffer< Value, Size, MaxPacketSize >::notify ( )
inline

Delimit the elements pushed since the most recent frame as one packet. The consumer can then use get_frame to get a range onto the queue. Note: you may want to only notify if dropping() is false, otherwise you are notifying of a know partial packet. If dropping(), then reset_dropped() will drop the partial packet.

◆ push_back()

template<typename Value, size_t Size, size_t MaxPacketSize>
template<typename Value_>
requires std::same_as<std::remove_cvref_t<Value>, std::remove_cvref_t<Value_>>
void CircularBuffer< Value, Size, MaxPacketSize >::push_back ( Value_ && v)
inline

Put an element onto the back of the queue. Using perfect forwarding to work for const Value & and also Value && references.

◆ reset_dropped()

template<typename Value, size_t Size, size_t MaxPacketSize>
void CircularBuffer< Value, Size, MaxPacketSize >::reset_dropped ( )
inline

Discards the partial packet and sets the buffer back to receive mode. You will want to call this when you have a frame delimiter and know you are about to receive a full packet.


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