Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::CircularBuffer< T, Size > Class Template Reference

#include <CircularBuffer.h>

Public Member Functions

 CircularBuffer ()
 
virtual ~CircularBuffer ()
 
T & put (const T &elem)
 Puts a copy of the element in the buffer.
 
T & get (unsigned int i=0)
 Gets an element from the buffer, without removing it.
 
T & last ()
 Returns the last element added in the buffer.
 
const T & pop ()
 Pops the first element in the buffer.
 
size_t count () const
 Counts the elements in the buffer.
 
bool isEmpty () const
 
bool isFull () const
 
size_t getSize () const
 Returns the maximum number of elements that can be stored in the buffer.
 

Protected Attributes

buffer [Size]
 
size_t writePtr = 0
 
size_t readPtr = 0
 
bool empty = true
 

Detailed Description

template<typename T, unsigned int Size>
class Boardcore::CircularBuffer< T, Size >

Implementation of an non-synchronized circular buffer.

Definition at line 38 of file CircularBuffer.h.

Constructor & Destructor Documentation

◆ CircularBuffer()

template<typename T , unsigned int Size>
Boardcore::CircularBuffer< T, Size >::CircularBuffer ( )
inline

Definition at line 43 of file CircularBuffer.h.

◆ ~CircularBuffer()

template<typename T , unsigned int Size>
virtual Boardcore::CircularBuffer< T, Size >::~CircularBuffer ( )
inlinevirtual

Definition at line 45 of file CircularBuffer.h.

Member Function Documentation

◆ count()

template<typename T , unsigned int Size>
size_t Boardcore::CircularBuffer< T, Size >::count ( ) const
inline

Counts the elements in the buffer.

Returns
Number of elements in the buffer.

Definition at line 138 of file CircularBuffer.h.

◆ get()

template<typename T , unsigned int Size>
T & Boardcore::CircularBuffer< T, Size >::get ( unsigned int i = 0)
inline

Gets an element from the buffer, without removing it.

Index starts from the oldest element in the buffer. get() returns the first element.

Warning
Remember to catch the exception!
Exceptions
range_errorif index >= count().
Parameters
iIndex of the element to get, starting from the oldest.
Returns
The element.

Definition at line 81 of file CircularBuffer.h.

◆ getSize()

template<typename T , unsigned int Size>
size_t Boardcore::CircularBuffer< T, Size >::getSize ( ) const
inline

Returns the maximum number of elements that can be stored in the buffer.

Returns
Buffer size.

Definition at line 162 of file CircularBuffer.h.

◆ isEmpty()

template<typename T , unsigned int Size>
bool Boardcore::CircularBuffer< T, Size >::isEmpty ( ) const
inline

Definition at line 148 of file CircularBuffer.h.

◆ isFull()

template<typename T , unsigned int Size>
bool Boardcore::CircularBuffer< T, Size >::isFull ( ) const
inline

Definition at line 150 of file CircularBuffer.h.

◆ last()

template<typename T , unsigned int Size>
T & Boardcore::CircularBuffer< T, Size >::last ( )
inline

Returns the last element added in the buffer.

Warning
Remember to catch the exception!
Exceptions
range_errorif buffer is empty.
Returns
The element.

Definition at line 107 of file CircularBuffer.h.

◆ pop()

template<typename T , unsigned int Size>
const T & Boardcore::CircularBuffer< T, Size >::pop ( )
inline

Pops the first element in the buffer.

Warning
Remember to catch the exception!
Exceptions
range_errorif buffer is empty.
Returns
The element that has been popped.

Definition at line 116 of file CircularBuffer.h.

◆ put()

template<typename T , unsigned int Size>
T & Boardcore::CircularBuffer< T, Size >::put ( const T & elem)
inline

Puts a copy of the element in the buffer.

Parameters
elemElement to be added to the queue.
Returns
The element added.

Definition at line 53 of file CircularBuffer.h.

Member Data Documentation

◆ buffer

template<typename T , unsigned int Size>
T Boardcore::CircularBuffer< T, Size >::buffer[Size]
protected

Definition at line 165 of file CircularBuffer.h.

◆ empty

template<typename T , unsigned int Size>
bool Boardcore::CircularBuffer< T, Size >::empty = true
protected

Definition at line 169 of file CircularBuffer.h.

◆ readPtr

template<typename T , unsigned int Size>
size_t Boardcore::CircularBuffer< T, Size >::readPtr = 0
protected

Definition at line 168 of file CircularBuffer.h.

◆ writePtr

template<typename T , unsigned int Size>
size_t Boardcore::CircularBuffer< T, Size >::writePtr = 0
protected

Definition at line 167 of file CircularBuffer.h.


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