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

#include <circular_buffer.h>

Public Member Functions

bool empty () const
 
bool full () const
 
void reset ()
 Reset the indexes to empty.
 
void push ()
 
void pop ()
 
index_t front () const
 
index_t back () const
 
index_t count () const
 

Static Public Attributes

static constexpr bool size_is_power2 = !(size & (size - 1))
 

Static Protected Member Functions

static index_t mask (index_t cursor)
 
static index_t next (index_t cursor)
 

Protected Attributes

index_t tail
 cursor of the element to read (pop/extract) from the buffer
 
index_t head
 cursor of the empty spot or element insertion (write)
 

Detailed Description

template<typename index_t = uint_fast8_t, index_t size = 16>
class CircularIndex< index_t, size >

A generic circular index class which can be used to build circular buffers Can hold up to size elements

Parameters
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 index positions. 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

◆ back()

template<typename index_t = uint_fast8_t, index_t size = 16>
index_t CircularIndex< index_t, size >::back ( ) const
inline
Returns
return the head index from the buffer. Does not perform any range checks for performance reasons, should be preceeded by if(!empty()) in the user code

◆ count()

template<typename index_t = uint_fast8_t, index_t size = 16>
index_t CircularIndex< index_t, size >::count ( ) const
inline
Returns
number of elements in the buffer

◆ empty()

template<typename index_t = uint_fast8_t, index_t size = 16>
bool CircularIndex< index_t, size >::empty ( ) const
inline
Returns
true if empty

◆ front()

template<typename index_t = uint_fast8_t, index_t size = 16>
index_t CircularIndex< index_t, size >::front ( ) const
inline
Returns
return the tail index from the buffer. Does not perform any range checks for performance reasons, should be preceeded by if(!empty()) in the user code

◆ full()

template<typename index_t = uint_fast8_t, index_t size = 16>
bool CircularIndex< index_t, size >::full ( ) const
inline
Returns
true if full

◆ mask()

template<typename index_t = uint_fast8_t, index_t size = 16>
static index_t CircularIndex< index_t, size >::mask ( index_t  cursor)
inlinestaticprotected
Returns
the index position given a cursor

◆ next()

template<typename index_t = uint_fast8_t, index_t size = 16>
static index_t CircularIndex< index_t, size >::next ( index_t  cursor)
inlinestaticprotected
Returns
next cursor for internal comparisons

◆ pop()

template<typename index_t = uint_fast8_t, index_t size = 16>
void CircularIndex< index_t, size >::pop ( )
inline

Advance the tail index from the buffer. No checks are performed. empty() needs to be queried beforehand.

◆ push()

template<typename index_t = uint_fast8_t, index_t size = 16>
void CircularIndex< index_t, size >::push ( )
inline

Advance the head index of the buffer. No checks are performed. full() needs to be queried beforehand.


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