Some useful stuff

Dependents:   FtEncoder FtControlSet

Embed: (wiki syntax)

« Back to documentation index

Buffer< T, N > Class Template Reference

Buffer< T, N > Class Template Reference

A template for a simple buffer class holding at max N elements of type T. More...

#include <Buffer.h>

Inherited by BufferOnHeap< T, N >, and BufferOnStack< T, N >.

Public Member Functions

bool push (const T &element)
 If used as queue or stack, use this function to insert new element to the buffer.
void pushCircular (const T &element)
 If used as ring buffer, use this function to insert new elements to the Buffer.
const T & popLatest ()
 Pop the latest element from buffer. Returns a default instance of type T if empty.
const T & popOldest ()
 Pop the oldest element from buffer. Returns a default instance of type T if empty.
bool empty () const
 Returns true if buffer is empty.
bool full () const
 Returns true if buffer is full.
uint32_t size () const
 Retuns number of currently stored elements.
uint32_t maxSize () const
 returns maximum number of storable elements
void clear ()
 Clear the Buffer.
const T & operator[] (uint32_t idx)
 Read only access operator: Element with index 0 is the oldest and the one with index size()-1 the latest.
Bufferoperator= (const Buffer &buf)
 assignment operator ...
virtual ~Buffer ()
 virtual destructor

Protected Member Functions

 Buffer ()
 Guess what: a constructor! But this class is kind of abstract, so it has been declared protected to remove it from the public interface.

Protected Attributes

T * elements
 The buffer for the stored elements, initialized in the concrete specializations.

Detailed Description

template<typename T, uint32_t N>
class Buffer< T, N >

A template for a simple buffer class holding at max N elements of type T.

Can be used as stack, queue or ring buffer This is kind of an abstract base class. There are heap and a stack based based concrete specializations.

Definition at line 11 of file Buffer.h.


Constructor & Destructor Documentation

Buffer (  ) [protected]

Guess what: a constructor! But this class is kind of abstract, so it has been declared protected to remove it from the public interface.

Called by the ctor of concrete specializations.

Definition at line 20 of file Buffer.h.

virtual ~Buffer (  ) [virtual]

virtual destructor

Definition at line 143 of file Buffer.h.


Member Function Documentation

void clear (  )

Clear the Buffer.

Definition at line 116 of file Buffer.h.

bool empty (  ) const

Returns true if buffer is empty.

Definition at line 96 of file Buffer.h.

bool full (  ) const

Returns true if buffer is full.

Definition at line 101 of file Buffer.h.

uint32_t maxSize (  ) const

returns maximum number of storable elements

Definition at line 111 of file Buffer.h.

Buffer& operator= ( const Buffer< T, N > &  buf )

assignment operator ...

does not care about the concrete type of the source Buffer as long as T and N template parameters are identical.

Definition at line 132 of file Buffer.h.

const T& operator[] ( uint32_t  idx )

Read only access operator: Element with index 0 is the oldest and the one with index size()-1 the latest.

Definition at line 123 of file Buffer.h.

const T& popLatest (  )

Pop the latest element from buffer. Returns a default instance of type T if empty.

Definition at line 79 of file Buffer.h.

const T& popOldest (  )

Pop the oldest element from buffer. Returns a default instance of type T if empty.

Definition at line 87 of file Buffer.h.

bool push ( const T &  element )

If used as queue or stack, use this function to insert new element to the buffer.

Returns true on success and false if Buffer is full

Definition at line 56 of file Buffer.h.

void pushCircular ( const T &  element )

If used as ring buffer, use this function to insert new elements to the Buffer.

If buffer is full, this function overwrites the oldest element.

Definition at line 68 of file Buffer.h.

uint32_t size (  ) const

Retuns number of currently stored elements.

Definition at line 106 of file Buffer.h.


Field Documentation

T* elements [protected]

The buffer for the stored elements, initialized in the concrete specializations.

Definition at line 15 of file Buffer.h.