|
Simpatico
v1.10
|
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... | |
| RingBuffer & | operator= (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... | |
| Util::RingBuffer< Data >::RingBuffer | ( | ) |
Contructor.
Definition at line 140 of file RingBuffer.h.
| Util::RingBuffer< Data >::RingBuffer | ( | const RingBuffer< Data > & | other | ) |
|
virtual |
Destructor.
Definition at line 219 of file RingBuffer.h.
| RingBuffer< Data > & Util::RingBuffer< Data >::operator= | ( | const RingBuffer< Data > & | other | ) |
Assignment.
| other | object to be assigned. |
Definition at line 182 of file RingBuffer.h.
References Util::RingBuffer< Data >::isAllocated(), and UTIL_THROW.
| 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.
| capacity | number 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().
|
inline |
Set previously allocated buffer to empty state.
Definition at line 245 of file RingBuffer.h.
|
inline |
Add a new value to the buffer.
| value | new value to be added. |
Definition at line 256 of file RingBuffer.h.
|
inline |
Return number of values currently in the buffer.
Definition at line 277 of file RingBuffer.h.
|
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().
|
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().
|
inline |
Return true if full (if size == capacity), false otherwise.
Definition at line 301 of file RingBuffer.h.
|
inline |
Retrieve a const value, a specified number of time steps ago.
| offset | number of steps back in time (offset=0 is current value). |
Definition at line 309 of file RingBuffer.h.
References UTIL_THROW.
|
inline |
Retrieve a value, a specified number of time steps ago.
| offset | number of steps back in time (offset=0 is current value). |
Definition at line 327 of file RingBuffer.h.
References UTIL_THROW.
| void Util::RingBuffer< Data >::serialize | ( | Archive & | ar, |
| const unsigned int | version | ||
| ) |
Serialize a RingBuffer to/from an Archive.
| ar | archive |
| version | archive 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.
1.8.11