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 (must be signed) |
Definition at line 78 of file circularBuffer.hpp.
#include <sigproc/circularBuffer.hpp>
Public Types | |
typedef _derivedT | derivedT |
The child class. | |
typedef _storedT | storedT |
The type stored in the circular buffer. | |
typedef _indexT | indexT |
The index type, also used for sizes. | |
Public Member Functions | |
circularBufferBase () | |
Default c'tor. | |
circularBufferBase (indexT maxEnt) | |
Sizing constructor. | |
void | maxEntries (indexT maxEnt) |
Set the maximum size of the buffer. | |
indexT | maxEntries () |
Get the maximum size of the buffer. | |
indexT | size () const |
Get the number of entries. | |
void | nextEntry (const storedT &newEnt) |
Add the next entry to the circular buffer. | |
void | nextEntry () |
Move to the next entry in the circular buffer. | |
indexT | earliest () |
Returns the index of the earliest entry. | |
indexT | latest () |
Returns the index of the latest entry. | |
storedT & | operator[] (indexT idx) |
Get the entry at a given index. | |
const storedT & | operator[] (indexT idx) const |
storedT & | at (indexT refEntry, indexT idx) |
Get the entry at a given index relative a fixed reference entry. | |
const storedT & | at (indexT refEntry, indexT idx) const |
Get the entry at a given index relative a fixed start entry, const version. | |
Protected Attributes | |
std::vector< storedT > | m_buffer |
The circular buffer storage. | |
indexT | m_maxEntries { 0 } |
The maximum number of entries to allow in the buffer before wrapping. | |
indexT | m_nextEntry { 0 } |
Index into m_buffer of the next entry. This is the oldest entry in the buffer. | |
indexT | m_latest { 0 } |
Index into m_buff of the latest entry. This is the newest entry in the buffer. | |
uint64_t | m_mono { 0 } |
typedef _derivedT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::derivedT |
The child class.
Definition at line 81 of file circularBuffer.hpp.
typedef _indexT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::indexT |
The index type, also used for sizes.
Definition at line 84 of file circularBuffer.hpp.
typedef _storedT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::storedT |
The type stored in the circular buffer.
Definition at line 83 of file circularBuffer.hpp.
mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::circularBufferBase | ( | ) |
Default c'tor.
Definition at line 199 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 204 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 312 of file circularBuffer.hpp.
Referenced by mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::operator[]().
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 318 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 282 of file circularBuffer.hpp.
indexT mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::latest | ( | ) |
Returns the index of the latest entry.
Definition at line 288 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 225 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 210 of file circularBuffer.hpp.
void mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::nextEntry | ( | ) |
Move to the next entry in the circular buffer.
If not yet at maxEntries entries, this emplaces a new default constructed entry. Otherwise it increments counters so that the old latest entry is now the newest entry.
Definition at line 260 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 237 of file circularBuffer.hpp.
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 300 of file circularBuffer.hpp.
References mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::at().
const storedT & mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::operator[] | ( | indexT | idx | ) | const |
[in] | idx | the index of the entry to access |
Definition at line 306 of file circularBuffer.hpp.
indexT mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::size | ( | ) | const |
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 231 of file circularBuffer.hpp.
|
protected |
The circular buffer storage.
Definition at line 89 of file circularBuffer.hpp.
|
protected |
Index into m_buff of the latest entry. This is the newest entry in the buffer.
Definition at line 93 of file circularBuffer.hpp.
|
protected |
The maximum number of entries to allow in the buffer before wrapping.
Definition at line 91 of file circularBuffer.hpp.
|
protected |
A monotonic counter, which is incremented for each new entry, and reset on call to maxEntries.
Definition at line 95 of file circularBuffer.hpp.
|
protected |
Index into m_buffer of the next entry. This is the oldest entry in the buffer.
Definition at line 92 of file circularBuffer.hpp.