Nebula
|
#include <ringbuffer.h>
A ring buffer stores up to a maximum number of elements in a circular fashion.
If the buffer is full, the newest element overwrites the oldest element.
Public Member Functions | |
RingBuffer () | |
default constructor | |
RingBuffer (SizeT capacity) | |
constructor with size | |
RingBuffer (const RingBuffer< TYPE > &rhs) | |
copy constructor | |
RingBuffer (RingBuffer< TYPE > &&rhs) | |
move constructor | |
~RingBuffer () | |
destructor | |
void | operator= (const RingBuffer< TYPE > &rhs) |
assignment operator | |
void | operator= (RingBuffer< TYPE > &&rhs) |
mover operator | |
TYPE & | operator[] (IndexT index) const |
index operator | |
void | SetCapacity (SizeT newCapacity) |
set capacity (clear previous content) | |
SizeT | Capacity () const |
get capacity | |
SizeT | Size () const |
get number of elements in ring buffer | |
void | Add (const TYPE &elm) |
add an element to the ring buffer | |
bool | IsEmpty () const |
return true if ring buffer is empty | |
void | Reset () |
reset ring buffer, just reset the head/base indices without calling destructors | |
TYPE & | Front () const |
return reference to first element | |
TYPE & | Back () const |
return reference to last element | |
Array< TYPE > | AsArray () const |
return all values as array | |
TYPE * | GetBuffer () |
get real linear underlying buffer | |
const TYPE * | GetBuffer () const |
get real linear underlying buffer | |
Private Member Functions | |
void | Allocate (SizeT capacity) |
allocate element buffer | |
void | Delete () |
delete content | |
void | Copy (const RingBuffer< TYPE > &src) |
copy content | |
Private Attributes | |
SizeT | capacity |
SizeT | size |
IndexT | baseIndex |
IndexT | headIndex |
TYPE * | elements |
Util::RingBuffer< TYPE >::RingBuffer | ( | ) |
default constructor
Util::RingBuffer< TYPE >::RingBuffer | ( | SizeT | capacity | ) |
constructor with size
Util::RingBuffer< TYPE >::RingBuffer | ( | const RingBuffer< TYPE > & | rhs | ) |
copy constructor
Util::RingBuffer< TYPE >::RingBuffer | ( | RingBuffer< TYPE > && | rhs | ) |
move constructor
Util::RingBuffer< TYPE >::~RingBuffer | ( | ) |
destructor
void Util::RingBuffer< TYPE >::Add | ( | const TYPE & | elm | ) |
add an element to the ring buffer
|
private |
allocate element buffer
Array< TYPE > Util::RingBuffer< TYPE >::AsArray | ( | ) | const |
return all values as array
TYPE & Util::RingBuffer< TYPE >::Back | ( | ) | const |
return reference to last element
SizeT Util::RingBuffer< TYPE >::Capacity | ( | ) | const |
get capacity
|
private |
copy content
|
private |
delete content
TYPE & Util::RingBuffer< TYPE >::Front | ( | ) | const |
return reference to first element
TYPE * Util::RingBuffer< TYPE >::GetBuffer | ( | ) |
get real linear underlying buffer
const TYPE * Util::RingBuffer< TYPE >::GetBuffer | ( | ) | const |
get real linear underlying buffer
bool Util::RingBuffer< TYPE >::IsEmpty | ( | ) | const |
return true if ring buffer is empty
void Util::RingBuffer< TYPE >::operator= | ( | const RingBuffer< TYPE > & | rhs | ) |
assignment operator
void Util::RingBuffer< TYPE >::operator= | ( | RingBuffer< TYPE > && | rhs | ) |
mover operator
TYPE & Util::RingBuffer< TYPE >::operator[] | ( | IndexT | index | ) | const |
index operator
void Util::RingBuffer< TYPE >::Reset | ( | ) |
reset ring buffer, just reset the head/base indices without calling destructors
void Util::RingBuffer< TYPE >::SetCapacity | ( | SizeT | newCapacity | ) |
set capacity (clear previous content)
SizeT Util::RingBuffer< TYPE >::Size | ( | ) | const |
get number of elements in ring buffer
|
private |
|
private |
|
private |
|
private |
|
private |