CVD 0.8
Public Member Functions
CVD::RingBuffer< T > Class Template Reference

Implements a ringbuffer based on std::vector. More...

#include <ringbuffer.h>

List of all members.

Public Member Functions

 RingBuffer (int size=0)
 RingBuffer (int size, const T &t)
void resize (int size)
int size () const
T & operator[] (int i)
const T & operator[] (int i) const
void advance (int n=1)

Detailed Description

template<typename T>
class CVD::RingBuffer< T >

Implements a ringbuffer based on std::vector.

A ringbuffer is a circular buffer i.e. once the end of the buffer is reached, reading or writing continues from the start of the buffer. The buffer maintains a notion of a 'current' element, which is buffer[0], and one can access elements before this or after this (using [-n] or [n] respectively), as well as advancing the current element slot by calling advance()

Parameters:
TThe data type held by the buffer

Definition at line 38 of file ringbuffer.h.


Constructor & Destructor Documentation

template<typename T >
CVD::RingBuffer< T >::RingBuffer ( int  size = 0) [inline]

Constructor.

Parameters:
sizeThe size of the ringbuffer

Definition at line 42 of file ringbuffer.h.

References CVD::RingBuffer< T >::size().

template<typename T >
CVD::RingBuffer< T >::RingBuffer ( int  size,
const T &  t 
) [inline]

Constructor.

Parameters:
sizeThe size of the ringbuffer
tThe default value for all elements in the ringbuffer

Definition at line 50 of file ringbuffer.h.


Member Function Documentation

template<typename T >
void CVD::RingBuffer< T >::resize ( int  size) [inline]

Resize the buffer.

Parameters:
sizeThe size of the ringbuffer

Definition at line 60 of file ringbuffer.h.

template<typename T >
T& CVD::RingBuffer< T >::operator[] ( int  i) [inline]

Access an element from the ringbuffer.

The [0] element is the current element, and one can use [-n] to access previous values in the ringbuffer (up to a limit of -size(), naturally).

Parameters:
iThe element number

Definition at line 73 of file ringbuffer.h.

template<typename T >
const T& CVD::RingBuffer< T >::operator[] ( int  i) const [inline]

Access an element from the ringbuffer.

The [0] element is the current element, and one can use [-n] to access previous values in the ringbuffer (up to a limit of -size(), naturally).

Parameters:
iThe element number

Definition at line 81 of file ringbuffer.h.

template<typename T >
void CVD::RingBuffer< T >::advance ( int  n = 1) [inline]

Step the current element on by one.

Parameters:
nThe number of slots to advance by (default is 1)

Definition at line 87 of file ringbuffer.h.


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