CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
CircularBuffer< T > Class Template Reference

Fixed-size circular data buffer More...

#include <cc/CircularBuffer>

Public Member Functions

 CircularBuffer (Dim< 1 > dim)
 Allocate a new circular buffer of capacity dim[0].
 
int size () const
 Buffer capacity.
 
int fill () const
 Current fill level.
 
at (int i) const
 Get the i-th item from the front.
 
operator[] (int i) const
 Get the i-th item from the front.
 
first () const
 Get the first item.
 
last () const
 Get the last item.
 
front (int i=0) const
 Get the i-th item from the front.
 
back (int i=0) const
 Get the i-th item from the end.
 
void pushBack (const T &item)
 Insert item at the end.
 
void pushFront (const T &item)
 Insert item at the front.
 
void popFront ()
 Remove an item from the front.
 
void popBack ()
 Remove an item from the end.
 
void deplete ()
 Reset to an empty state.
 
CircularBufferoperator<< (const T &item)
 Insert item as a new last item.
 
CircularBufferoperator>> (T &item)
 Remove and return the first item.
 

Static Public Member Functions

static CircularBuffer allocate (int size)
 Allocate a new circular buffer of capacity size.
 

Detailed Description

template<class T>
class cc::CircularBuffer< T >

Fixed-size circular data buffer

Template Parameters
TItem type

Constructor & Destructor Documentation

◆ CircularBuffer()

template<class T >
CircularBuffer ( Dim< 1 > dim)

Allocate a new circular buffer of capacity dim[0].

Member Function Documentation

◆ allocate()

template<class T >
static CircularBuffer allocate ( int size)
static

Allocate a new circular buffer of capacity size.

◆ size()

template<class T >
int size ( ) const

Buffer capacity.

◆ fill()

template<class T >
int fill ( ) const

Current fill level.

◆ at()

template<class T >
T at ( int i) const

Get the i-th item from the front.

◆ operator[]()

template<class T >
T operator[] ( int i) const

Get the i-th item from the front.

◆ first()

template<class T >
T first ( ) const

Get the first item.

◆ last()

template<class T >
T last ( ) const

Get the last item.

◆ front()

template<class T >
T front ( int i = 0) const

Get the i-th item from the front.

◆ back()

template<class T >
T back ( int i = 0) const

Get the i-th item from the end.

◆ pushBack()

template<class T >
void pushBack ( const T & item)

Insert item at the end.

◆ pushFront()

template<class T >
void pushFront ( const T & item)

Insert item at the front.

◆ popFront()

template<class T >
void popFront ( )

Remove an item from the front.

◆ popBack()

template<class T >
void popBack ( )

Remove an item from the end.

◆ deplete()

template<class T >
void deplete ( )

Reset to an empty state.

◆ operator<<()

template<class T >
CircularBuffer & operator<< ( const T & item)

Insert item as a new last item.

◆ operator>>()

template<class T >
CircularBuffer & operator>> ( T & item)

Remove and return the first item.