Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
Public Member Functions | Protected Attributes | List of all members
CircularBuffer< T, index_t, size > Class Template Reference

#include <circular_buffer.h>

Collaboration diagram for CircularBuffer< T, index_t, size >:
Collaboration graph
[legend]

Public Member Functions

bool empty () const
 
bool full () const
 
void reset ()
 Reset the circular buffer to empty.
 
bool push (T elem)
 
front () const
 
bool pop (T &elem)
 
index_t count () const
 

Protected Attributes

data [size]
 array of stored elements
 
CircularIndex< index_t, size > index
 circular index
 

Detailed Description

template<typename T = uint8_t, typename index_t = uint_fast8_t, size_t size = 16>
class CircularBuffer< T, index_t, size >

A generic circular buffer class Can hold up to size elements

Parameters
Tdata type of stored elements
index_tdata type of indices into array of elements (recommended to keep uint8_fast8_t as single byte operations are atomical on the AVR)
sizenumber of elements to store It is recommended to keep a power of 2 to allow for optimal code generation on the AVR (there is no HW modulo instruction)

Member Function Documentation

◆ front()

template<typename T = uint8_t, typename index_t = uint_fast8_t, size_t size = 16>
T CircularBuffer< T, index_t, size >::front ( ) const
inline
Returns
peeks the current element to extract from the buffer, however the element is left in the buffer Does not perform any range checks for performance reasons, should be preceeded by if(!empty()) in the user code

◆ pop()

template<typename T = uint8_t, typename index_t = uint_fast8_t, size_t size = 16>
bool CircularBuffer< T, index_t, size >::pop ( T &  elem)
inline

Extracts the current element from the buffer

Returns
true in case there was an element for extraction (i.e. the buffer was not empty)

◆ push()

template<typename T = uint8_t, typename index_t = uint_fast8_t, size_t size = 16>
bool CircularBuffer< T, index_t, size >::push ( elem)
inline

Insert an element into the buffer. Checks for empty spot for the element and does not change the buffer content in case the buffer is full.

Returns
true if the insertion was successful (i.e. there was an empty spot for the element)

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