Simpatico  v1.10
List of all members | Public Member Functions
Util::RingBuffer< Data > Class Template Reference

Detailed Description

template<class Data>
class Util::RingBuffer< Data >

Class for storing history of previous values in an array.

Data is stored in a circular buffer, in which, once the array is full, the newest data value overwrites the oldest.

Definition at line 26 of file RingBuffer.h.

#include <RingBuffer.h>

Public Member Functions

 RingBuffer ()
 Contructor. More...
 
 RingBuffer (const RingBuffer< Data > &other)
 Copy contructor. More...
 
RingBufferoperator= (const RingBuffer< Data > &other)
 Assignment. More...
 
virtual ~RingBuffer ()
 Destructor. More...
 
void allocate (int capacity)
 Allocate a new empty buffer. More...
 
void clear ()
 Set previously allocated buffer to empty state. More...
 
void append (Data value)
 Add a new value to the buffer. More...
 
int size () const
 Return number of values currently in the buffer. More...
 
int capacity () const
 Return the capacity of the buffer. More...
 
bool isAllocated () const
 Return true if the RingBuffer has been allocated, false otherwise. More...
 
bool isFull () const
 Return true if full (if size == capacity), false otherwise. More...
 
const Data & operator[] (int offset) const
 Retrieve a const value, a specified number of time steps ago. More...
 
Data & operator[] (int offset)
 Retrieve a value, a specified number of time steps ago. More...
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 Serialize a RingBuffer to/from an Archive. More...
 

Constructor & Destructor Documentation

template<class Data >
Util::RingBuffer< Data >::RingBuffer ( )

Contructor.

Definition at line 140 of file RingBuffer.h.

template<class Data>
Util::RingBuffer< Data >::RingBuffer ( const RingBuffer< Data > &  other)

Copy contructor.

Parameters
otherobject to be copied.

Definition at line 155 of file RingBuffer.h.

template<class Data >
Util::RingBuffer< Data >::~RingBuffer ( )
virtual

Destructor.

Definition at line 219 of file RingBuffer.h.

Member Function Documentation

template<class Data>
RingBuffer< Data > & Util::RingBuffer< Data >::operator= ( const RingBuffer< Data > &  other)

Assignment.

Parameters
otherobject to be assigned.

Definition at line 182 of file RingBuffer.h.

References Util::RingBuffer< Data >::isAllocated(), and UTIL_THROW.

template<class Data >
void Util::RingBuffer< Data >::allocate ( int  capacity)

Allocate a new empty buffer.

Allocate a new array containing capacity elements.

Throw an Exception if this RingBuffer has already been allocated - a RingBuffer can only be allocated once.

Parameters
capacitynumber of elements to allocate.

Definition at line 228 of file RingBuffer.h.

References Util::RingBuffer< Data >::capacity(), and UTIL_THROW.

Referenced by Util::RingBuffer< Data >::serialize().

template<class Data >
void Util::RingBuffer< Data >::clear ( )
inline

Set previously allocated buffer to empty state.

Definition at line 245 of file RingBuffer.h.

template<class Data>
void Util::RingBuffer< Data >::append ( Data  value)
inline

Add a new value to the buffer.

Parameters
valuenew value to be added.

Definition at line 256 of file RingBuffer.h.

template<class Data >
int Util::RingBuffer< Data >::size ( ) const
inline

Return number of values currently in the buffer.

Definition at line 277 of file RingBuffer.h.

template<class Data >
int Util::RingBuffer< Data >::capacity ( ) const
inline

Return the capacity of the buffer.

Definition at line 285 of file RingBuffer.h.

Referenced by Util::RingBuffer< Data >::allocate(), and Util::RingBuffer< Data >::serialize().

template<class Data >
bool Util::RingBuffer< Data >::isAllocated ( ) const
inline

Return true if the RingBuffer has been allocated, false otherwise.

Definition at line 293 of file RingBuffer.h.

Referenced by Util::RingBuffer< Data >::operator=(), and Util::RingBuffer< Data >::serialize().

template<class Data >
bool Util::RingBuffer< Data >::isFull ( ) const
inline

Return true if full (if size == capacity), false otherwise.

Definition at line 301 of file RingBuffer.h.

template<class Data >
const Data & Util::RingBuffer< Data >::operator[] ( int  offset) const
inline

Retrieve a const value, a specified number of time steps ago.

Parameters
offsetnumber of steps back in time (offset=0 is current value).

Definition at line 309 of file RingBuffer.h.

References UTIL_THROW.

template<class Data >
Data & Util::RingBuffer< Data >::operator[] ( int  offset)
inline

Retrieve a value, a specified number of time steps ago.

Parameters
offsetnumber of steps back in time (offset=0 is current value).

Definition at line 327 of file RingBuffer.h.

References UTIL_THROW.

template<class Data >
template<class Archive >
void Util::RingBuffer< Data >::serialize ( Archive &  ar,
const unsigned int  version 
)

Serialize a RingBuffer to/from an Archive.

Parameters
ararchive
versionarchive version id

Definition at line 345 of file RingBuffer.h.

References Util::RingBuffer< Data >::allocate(), Util::RingBuffer< Data >::capacity(), Util::RingBuffer< Data >::isAllocated(), and UTIL_THROW.


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