PSCF v1.1
|
Class for storing history of previous values in an array. More...
#include <RingBuffer.h>
Public Member Functions | |
RingBuffer () | |
Contructor. More... | |
RingBuffer (RingBuffer< Data > const &other) | |
Copy contructor. More... | |
RingBuffer & | operator= (RingBuffer< Data > const &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 const &value) |
Add a new value to the buffer. More... | |
void | advance () |
Advances the pointer to an added element without assigning a value. 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... | |
Data const & | 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... | |
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.
Util::RingBuffer< Data >::RingBuffer |
Contructor.
Definition at line 169 of file RingBuffer.h.
Util::RingBuffer< Data >::RingBuffer | ( | RingBuffer< Data > const & | other | ) |
|
virtual |
Destructor.
Definition at line 248 of file RingBuffer.h.
RingBuffer< Data > & Util::RingBuffer< Data >::operator= | ( | RingBuffer< Data > const & | other | ) |
Assignment.
other | object to be assigned. |
Definition at line 211 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 257 of file RingBuffer.h.
References UTIL_THROW.
|
inline |
Set previously allocated buffer to empty state.
Definition at line 274 of file RingBuffer.h.
|
inline |
Add a new value to the buffer.
This function updates the pointer to the most recent element and then uses an assignment (=) operator to assign argument "value" to this element of the underlying array.
value | new value to be added |
Definition at line 285 of file RingBuffer.h.
|
inline |
Advances the pointer to an added element without assigning a value.
This function advances the pointer that identifies the the newest element but does not assign a value to that element. Immediately after applying this function to a RingBuffer<T> named buffer, the value of the most recently added element, buffer[0], is undefined. A call to RingBuffer<T>::advance must be thus always be followed by code that assigns this value. The simplest usage for a Ringbuffer<T> named buffer would thus be:
where "value" is an object of type T. This combination is equivalent to buffer.append(value).
Rationale: This is designed as an alternative to the append memmber function for cases in which type T is a large object. This avoids the need to construct and assign a value to a T object outside the buffer which must then be re-assigned to an array element inside the RingBuffer<T>::append function.
Definition at line 306 of file RingBuffer.h.
|
inline |
Return number of values currently in the buffer.
Definition at line 325 of file RingBuffer.h.
Referenced by pscfpp.file.File::__eq__(), pscfpp.text.Record::__init__(), pscfpp.file.File::__init__(), pscfpp.file.File::__repr__(), and pscfpp.text.Record::__str__().
|
inline |
Return the capacity of the buffer.
Definition at line 333 of file RingBuffer.h.
|
inline |
Return true if the RingBuffer has been allocated, false otherwise.
Definition at line 341 of file RingBuffer.h.
Referenced by Util::RingBuffer< Data >::operator=().
|
inline |
Return true if full (if size == capacity), false otherwise.
Definition at line 349 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 357 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 375 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 393 of file RingBuffer.h.
References UTIL_THROW.