#include <ringbuffer.h>
Public Member Functions | |
void | advance (int n=1) |
const T & | operator[] (int i) const |
T & | operator[] (int i) |
void | resize (int size) |
RingBuffer (int size, const T &t) | |
RingBuffer (int size=0) | |
int | size () const |
What is the size of the buffer? | |
~RingBuffer () | |
Private Attributes | |
std::vector< T > | my_buffer |
int | my_start |
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()
T | The data type held by the buffer |
Definition at line 38 of file ringbuffer.h.
CVD::RingBuffer< T >::RingBuffer | ( | int | size = 0 |
) | [inline] |
Constructor.
size | The size of the ringbuffer |
Definition at line 42 of file ringbuffer.h.
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.
CVD::RingBuffer< T >::~RingBuffer | ( | ) | [inline] |
Definition at line 55 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.
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.
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.
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.
std::vector<T> CVD::RingBuffer< T >::my_buffer [private] |
Definition at line 92 of file ringbuffer.h.
int CVD::RingBuffer< T >::my_start [private] |
Definition at line 93 of file ringbuffer.h.