mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
CRTP base class for all circular buffers, providing the underlying memory management and accessors.
The CRTP derived classes implement a standard interface based on how they handle wrapping from the end to the beginning of the buffer.
_derivedT | the child class type |
_storedT | the type stored in teh circular buffer |
_indexT | the index type, also used for sizes (can be unsigned) |
Definition at line 71 of file circularBuffer.hpp.
#include <sigproc/circularBuffer.hpp>
Public Types | |
typedef _derivedT | derivedT |
The child class. More... | |
typedef _storedT | storedT |
The type stored in the circular buffer. More... | |
typedef _indexT | indexT |
The index type, also used for sizes. More... | |
Public Member Functions | |
circularBufferBase () | |
Default c'tor. More... | |
circularBufferBase (indexT maxEnt) | |
Sizing constructor. More... | |
void | maxEntries (indexT maxEnt) |
Set the maximum size of the buffer. More... | |
indexT | maxEntries () |
Get the maximum size of the buffer. More... | |
indexT | size () const |
Get the number of entries. More... | |
void | nextEntry (const storedT &newEnt) |
Add the next entry to the circular buffer. More... | |
indexT | earliest () |
Returns the index of the earliest entry. More... | |
indexT | latest () |
Returns the index of the latest entry. More... | |
storedT & | operator[] (indexT idx) |
Get the entry at a given index. More... | |
const storedT & | operator[] (indexT idx) const |
storedT & | at (indexT refEntry, indexT idx) |
Get the entry at a given index relative a fixed reference entry. More... | |
const storedT & | at (indexT refEntry, indexT idx) const |
Get the entry at a given index relative a fixed start entry, const version. More... | |
Protected Attributes | |
std::vector< storedT > | m_buffer |
The circular buffer storage. More... | |
indexT | m_maxEntries {0} |
The maximum number of entries to allow in the buffer before wrapping. More... | |
indexT | m_nextEntry {0} |
Index into m_buffer of the next entry. This is the oldest entry in the buffer. More... | |
indexT | m_latest {0} |
Index into m_buff of the latest entry. This is the newest entry in the buffer. More... | |
uint64_t | m_mono {0} |
A monotonic counter, which is incremented for each new entry, and reset on call to maxEntries. More... | |
typedef _derivedT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::derivedT |
The child class.
Definition at line 75 of file circularBuffer.hpp.
typedef _indexT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::indexT |
The index type, also used for sizes.
Definition at line 78 of file circularBuffer.hpp.
typedef _storedT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::storedT |
The type stored in the circular buffer.
Definition at line 77 of file circularBuffer.hpp.
mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::circularBufferBase |
Default c'tor.
Definition at line 187 of file circularBuffer.hpp.
|
explicit |
Sizing constructor.
Sets the maximum size of the buffer. Note that this will not be the size until a full set of entries have been added to the buffer.
[in] | maxEnt | the maximum number of entries this buffer will hold |
Definition at line 192 of file circularBuffer.hpp.
storedT & mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::at | ( | indexT | refEntry, |
indexT | idx | ||
) |
Get the entry at a given index relative a fixed reference entry.
idx=0
is the entry at refEntry. idx=1
is the one after that. I.e., this counts forward from the oldest data
[in] | refEntry | the entry to start counting from |
[in] | idx | the index of the entry to access |
Definition at line 279 of file circularBuffer.hpp.
const storedT & mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::at | ( | indexT | refEntry, |
indexT | idx | ||
) | const |
Get the entry at a given index relative a fixed start entry, const version.
idx=0
is the entry at refEntry. idx=1
is the one after that. I.e., this counts forward from the oldest data
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | refEntry | the entry to start counting from |
[in] | idx | the index of the entry to access |
Definition at line 287 of file circularBuffer.hpp.
indexT mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::earliest |
Returns the index of the earliest entry.
This is particularly useful for accessing entries with the at() function over an unchanging sequence if asynchronous updates are possible.
Definition at line 249 of file circularBuffer.hpp.
indexT mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::latest |
Returns the index of the latest entry.
Definition at line 255 of file circularBuffer.hpp.
indexT mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::maxEntries |
Get the maximum size of the buffer.
Note that this is not the current size of the buffer until at least maxEntries have been added. Use size() to check current size.
Definition at line 214 of file circularBuffer.hpp.
void mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::maxEntries | ( | indexT | maxEnt | ) |
Set the maximum size of the buffer.
Note that this will not be the size until a full set of entries have been added to the buffer.
[in] | maxEnt | the maximum number of entries this buffer will hold |
Definition at line 198 of file circularBuffer.hpp.
void mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::nextEntry | ( | const storedT & | newEnt | ) |
Add the next entry to the circular buffer.
Adds the entry (will incur a deep copy) and updates the wrapping system.
[in] | newEnt | the new entry to add to the buffer |
Definition at line 226 of file circularBuffer.hpp.
storedT & mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::operator[] | ( | indexT | idx | ) |
Get the entry at a given index.
idx=0
is the earliest entry in the buffer. idx=1
is the one after that. I.e., this counts forward from the oldest data
[in] | idx | the index of the entry to access |
Definition at line 267 of file circularBuffer.hpp.
const storedT & mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::operator[] | ( | indexT | idx | ) | const |
[in] | idx | the index of the entry to access |
Definition at line 273 of file circularBuffer.hpp.
indexT mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::size |
Get the number of entries.
Note that this is the current size. It will not be the same as maxEntries() until at least maxEntries have been added.
Definition at line 220 of file circularBuffer.hpp.
|
protected |
The circular buffer storage.
Definition at line 82 of file circularBuffer.hpp.
|
protected |
Index into m_buff of the latest entry. This is the newest entry in the buffer.
Definition at line 86 of file circularBuffer.hpp.
|
protected |
The maximum number of entries to allow in the buffer before wrapping.
Definition at line 84 of file circularBuffer.hpp.
|
protected |
A monotonic counter, which is incremented for each new entry, and reset on call to maxEntries.
Definition at line 88 of file circularBuffer.hpp.
|
protected |
Index into m_buffer of the next entry. This is the oldest entry in the buffer.
Definition at line 85 of file circularBuffer.hpp.