#include <ringbuffer.h>
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()
T | The data type held by the buffer |
Definition at line 38 of file ringbuffer.h.
Public Member Functions | |
RingBuffer (int size=0) | |
RingBuffer (int size, const T &t) | |
~RingBuffer () | |
void | resize (int size) |
int | size () const |
T & | operator[] (int i) |
const T & | operator[] (int i) const |
void | advance (int n=1) |
CVD::RingBuffer< T >::RingBuffer | ( | int | size = 0 |
) | [inline] |
Constructor.
size | The size of the ringbuffer |
Definition at line 42 of file ringbuffer.h.
References CVD::RingBuffer< T >::size().
CVD::RingBuffer< T >::RingBuffer | ( | int | size, | |
const T & | t | |||
) | [inline] |
Constructor.
size | The size of the ringbuffer | |
t | The default value for all elements in the ringbuffer |
Definition at line 50 of file ringbuffer.h.
void CVD::RingBuffer< T >::resize | ( | int | size | ) | [inline] |
Resize the buffer.
size | The size of the ringbuffer |
Definition at line 60 of file ringbuffer.h.
int CVD::RingBuffer< T >::size | ( | ) | const [inline] |
What is the size of the buffer?
Definition at line 65 of file ringbuffer.h.
Referenced by CVD::RingBuffer< T >::RingBuffer().
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).
i | The element number |
Definition at line 73 of file ringbuffer.h.
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).
i | The element number |
Definition at line 81 of file ringbuffer.h.
void CVD::RingBuffer< T >::advance | ( | int | n = 1 |
) | [inline] |
Step the current element on by one.
n | The number of slots to advance by (default is 1) |
Definition at line 87 of file ringbuffer.h.