|
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 79 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 82 of file circularBuffer.hpp.
| typedef _indexT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::indexT |
The index type, also used for sizes.
Definition at line 85 of file circularBuffer.hpp.
| typedef _storedT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::storedT |
The type stored in the circular buffer.
Definition at line 84 of file circularBuffer.hpp.
| mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::circularBufferBase | ( | ) |
Default c'tor.
Definition at line 200 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 205 of file circularBuffer.hpp.
References maxEntries().
| 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 313 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 319 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 283 of file circularBuffer.hpp.
References m_nextEntry.
Referenced by TEST_CASE().
| indexT mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::latest | ( | ) |
Returns the index of the latest entry.
Definition at line 289 of file circularBuffer.hpp.
References m_latest.
Referenced by TEST_CASE().
| 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 226 of file circularBuffer.hpp.
References m_maxEntries.
| 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 211 of file circularBuffer.hpp.
References m_buffer, m_latest, m_maxEntries, m_mono, and m_nextEntry.
Referenced by circularBufferBase(), and TEST_CASE().
| 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 261 of file circularBuffer.hpp.
References m_buffer, m_latest, m_maxEntries, m_mono, and m_nextEntry.
| 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 238 of file circularBuffer.hpp.
References m_buffer, m_latest, m_maxEntries, m_mono, and m_nextEntry.
Referenced by TEST_CASE().
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 301 of file circularBuffer.hpp.
References m_nextEntry.
| const storedT & mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::operator[] | ( | indexT | idx | ) | const |
| [in] | idx | the index of the entry to access |
Definition at line 307 of file circularBuffer.hpp.
References m_nextEntry.
| 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 232 of file circularBuffer.hpp.
References m_buffer.
|
protected |
The circular buffer storage.
Definition at line 90 of file circularBuffer.hpp.
Referenced by maxEntries(), nextEntry(), nextEntry(), and size().
|
protected |
Index into m_buff of the latest entry. This is the newest entry in the buffer.
Definition at line 94 of file circularBuffer.hpp.
Referenced by latest(), maxEntries(), nextEntry(), and nextEntry().
|
protected |
The maximum number of entries to allow in the buffer before wrapping.
Definition at line 92 of file circularBuffer.hpp.
Referenced by maxEntries(), maxEntries(), nextEntry(), and nextEntry().
|
protected |
A monotonic counter, which is incremented for each new entry, and reset on call to maxEntries.
Definition at line 96 of file circularBuffer.hpp.
Referenced by maxEntries(), nextEntry(), and nextEntry().
|
protected |
Index into m_buffer of the next entry. This is the oldest entry in the buffer.
Definition at line 93 of file circularBuffer.hpp.
Referenced by earliest(), maxEntries(), nextEntry(), nextEntry(), operator[](), and operator[]().