MySensors Library & Examples  2.3.2
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CircularBuffer< T > Class Template Reference

Detailed Description

template<class T>
class CircularBuffer< T >

The circular buffer class. Pass the datatype to be stored in the buffer as template parameter.

Definition at line 34 of file CircularBuffer.h.

#include <CircularBuffer.h>

+ Collaboration diagram for CircularBuffer< T >:

Public Member Functions

 CircularBuffer (T *buffer, const uint8_t size)
 
void clear (void)
 
bool empty (void) const
 
bool full (void) const
 
uint8_t available (void) const
 
T * getFront (void) const
 
bool pushFront (T *record)
 
T * getBack (void) const
 
bool popBack (void)
 

Protected Member Functions

T * get (const uint8_t idx) const
 
uint8_t back (void) const
 

Protected Attributes

const uint8_t m_size
 Total number of records that can be stored in the buffer.
 
T *const m_buff
 Ptr to buffer holding all records.
 
volatile uint8_t m_front
 Index of front element (not pushed yet).
 
volatile uint8_t m_fill
 Amount of records currently pushed.
 

Constructor & Destructor Documentation

◆ CircularBuffer()

template<class T >
CircularBuffer< T >::CircularBuffer ( T *  buffer,
const uint8_t  size 
)
inline

Constructor

Parameters
bufferPreallocated buffer of at least size records.
sizeNumber of records available in the buffer.

Definition at line 42 of file CircularBuffer.h.

Member Function Documentation

◆ available()

template<class T >
uint8_t CircularBuffer< T >::available ( void  ) const
inline

Return the number of records stored in the buffer.

Returns
number of records.

Definition at line 89 of file CircularBuffer.h.

◆ back()

template<class T >
uint8_t CircularBuffer< T >::back ( void  ) const
inlineprotected

Internal getter for index of last used record in buffer.

Returns
Index of last record.

Definition at line 186 of file CircularBuffer.h.

◆ clear()

template<class T >
void CircularBuffer< T >::clear ( void  )
inline

Clear all entries in the circular buffer.

Definition at line 51 of file CircularBuffer.h.

◆ empty()

template<class T >
bool CircularBuffer< T >::empty ( void  ) const
inline

Test if the circular buffer is empty.

Returns
True, when empty.

Definition at line 63 of file CircularBuffer.h.

◆ full()

template<class T >
bool CircularBuffer< T >::full ( void  ) const
inline

Test if the circular buffer is full.

Returns
True, when full.

Definition at line 76 of file CircularBuffer.h.

◆ get()

template<class T >
T* CircularBuffer< T >::get ( const uint8_t  idx) const
inlineprotected

Internal getter for records.

Parameters
idxRecord index in buffer.
Returns
Ptr to record.

Definition at line 177 of file CircularBuffer.h.

◆ getBack()

template<class T >
T* CircularBuffer< T >::getBack ( void  ) const
inline

Aquire record on back of the buffer, for reading. After reading the record, it has to be pop'ed to actually remove it from the buffer.

Returns
Pointer to record, or NULL when buffer is empty.

Definition at line 144 of file CircularBuffer.h.

◆ getFront()

template<class T >
T* CircularBuffer< T >::getFront ( void  ) const
inline

Aquire unused record on front of the buffer, for writing. After filling the record, it has to be pushed to actually add it to the buffer.

Returns
Pointer to record, or NULL when buffer is full.

Definition at line 104 of file CircularBuffer.h.

◆ popBack()

template<class T >
bool CircularBuffer< T >::popBack ( void  )
inline

Remove record from back of the buffer.

Returns
True, when record was pop'ed successfully.

Definition at line 159 of file CircularBuffer.h.

◆ pushFront()

template<class T >
bool CircularBuffer< T >::pushFront ( T *  record)
inline

Push record to front of the buffer.

Parameters
recordRecord to push. If record was aquired previously (using getFront) its data will not be copied as it is already present in the buffer.
Returns
True, when record was pushed successfully.

Definition at line 121 of file CircularBuffer.h.


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