QDaq  0.2.6
Qt-based Data Aqcuisition
 All Classes Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Public Member Functions | List of all members
math::circular_buffer< T > Class Template Reference

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_toperator<< (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
 

Detailed Description

template<class T>
class math::circular_buffer< T >

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.


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