QDaq
0.2.6
Qt-based Data Aqcuisition
|
A circular LIFO buffer class. More...
#include <math_util.h>
Public Member Functions | |
circular_buffer (unsigned int nmax=1) | |
Construct a circular_buffer with capacity nmax. | |
void | alloc (unsigned int nmax) |
allocate memory for nmax elements (nmax is adjusted to 2^N). | |
void | push (const T &v) |
insert an element. | |
self_t & | operator<< (const T &v) |
insertion operator is the same as push() | |
void | pop () |
remove the last inserted element | |
T & | operator[] (int i) |
ref to the i-th element | |
const T & | operator[] (int i) const |
const ref to the i-th element | |
const T & | last () const |
const ref to last element inserted | |
unsigned int | capacity () const |
return the buffer's capacity | |
A circular LIFO buffer class.
When the buffer becomes full, newer elements overwrite older ones.
The allocated memory for the buffer is always 2^N for maximum efficiency.
Data elements are inserted with push() or with the insertion operator<<().
The stored elements can be recalled by the c-style array operator[]. The elements are stored in LIFO order: at index 0 is the last inserted element, at 1 the one before last, etc.
The class does not keep count of the number of elements that have been inserted. The user is responsible for the neccesary book-keeping.
Definition at line 31 of file math_util.h.