Simple ring-buffer template. More...
#include <Radiant/RingBuffer.hpp>
Public Member Functions | |
| TElem * | data () |
| Get a raw pointer to data. More... | |
| const TElem * | data () const |
| Get a raw pointer to data. More... | |
| int | elemSize () const |
| Get the size of a sample in bytes. More... | |
| TElem & | getIndex (unsigned nIndex) |
| Get a sample from the buffer. More... | |
| const TElem & | getIndex (unsigned nIndex) const |
| Get a sample from the buffer. More... | |
| const TElem & | getIndexConst (unsigned nIndex) const |
| Get a sample from the buffer. More... | |
| unsigned | mask () const |
| Report mask used for address translation. More... | |
| RingBuffer< TElem > & | operator= (const RingBuffer &xrBuffer) |
| Deep copy operator. More... | |
| TElem & | operator[] (unsigned nIndex) |
| Get the sample with the given index. More... | |
| const TElem & | operator[] (unsigned nIndex) const |
| Get the sample with the given index. More... | |
| bool | resize (unsigned nBufSize) |
| Resize the buffer. More... | |
| RingBuffer () | |
| Create an empty ring buffer. | |
| RingBuffer (unsigned nSize) | |
| Create a ring-buffer with given minimum size. More... | |
| RingBuffer (const RingBuffer &xrBuffer) | |
| Create a deep copy. More... | |
| void | setAll (TElem xVal) |
| Set all buffer values. More... | |
| void | setIndex (unsigned nIndex, const TElem &xVal) |
| Set a sample of the buffer. More... | |
| unsigned | size () const |
| Get buffer size. More... | |
| unsigned | sizeOf () const |
| Get buffer size in bytes. More... | |
| virtual | ~RingBuffer () |
| Destroy the ring-buffer and free memory. | |
Static Public Member Functions | |
| static unsigned | targetSize (unsigned nBufSize) |
| Calculate the real size of the buffer if the required number of samples is nBufSize. More... | |
Protected Attributes | |
| TElem * | m_line |
| Data buffer. | |
| unsigned | m_mask |
| Mask for determining index. | |
| unsigned | m_size |
| Real size. | |
Simple ring-buffer template.
The operations are optimized and thus there are few safety checks.
Buffer size must always be a power-of-two.
The elements of this class need to be numeric: float, double, int, long etc.
|
inline |
Create a ring-buffer with given minimum size.
The actual buffer might be larger than the given value.
| nSize | minimum buffer size |
|
inline |
Create a deep copy.
| xrBuffer | buffer to copy |
|
inline |
Get a raw pointer to data.
|
inline |
Get a raw pointer to data.
|
inline |
Get the size of a sample in bytes.
|
inline |
Get a sample from the buffer.
| nIndex | index of the sample |
|
inline |
Get a sample from the buffer.
| nIndex | index of the sample |
|
inline |
Get a sample from the buffer.
| nIndex | index of the sample |
|
inline |
Report mask used for address translation.
|
inline |
Deep copy operator.
| xrBuffer | buffer to copy |
|
inline |
Get the sample with the given index.
| nIndex | index to get |
|
inline |
Get the sample with the given index.
| nIndex | index to get |
|
inline |
Resize the buffer.
Old buffer elements are lost when the buffer is resized. If new size equals the old size the buffer is not reallocated. The new buffer will be able to hold at least nBufSize elements. The new buffer elements are by default initialized to zero.
| nBufSize | new buffer size |
|
inline |
Set all buffer values.
Fills the buffer with the given value.
| xVal | value to set |
|
inline |
Set a sample of the buffer.
| nIndex | sample index |
| xVal | sample value |
|
inline |
Get buffer size.
|
inline |
Get buffer size in bytes.
|
inlinestatic |
Calculate the real size of the buffer if the required number of samples is nBufSize.
Outsiders should not need this method too often.
| nBufSize | target buffer size |