mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT > Class Template Reference

template<typename _derivedT, typename _storedT, typename _indexT>
class mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >

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.

Template Parameters
_derivedTthe child class type
_storedTthe type stored in teh circular buffer
_indexTthe 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.
storedToperator[] (indexT idx)
 Get the entry at a given index.
const storedToperator[] (indexT idx) const
storedTat (indexT refEntry, indexT idx)
 Get the entry at a given index relative a fixed reference entry.
const storedTat (indexT refEntry, indexT idx) const
 Get the entry at a given index relative a fixed start entry, const version.

Protected Attributes

std::vector< storedTm_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 }

Member Typedef Documentation

◆ derivedT

template<typename _derivedT, typename _storedT, typename _indexT>
typedef _derivedT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::derivedT

The child class.

Definition at line 82 of file circularBuffer.hpp.

◆ indexT

template<typename _derivedT, typename _storedT, typename _indexT>
typedef _indexT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::indexT

The index type, also used for sizes.

Definition at line 85 of file circularBuffer.hpp.

◆ storedT

template<typename _derivedT, typename _storedT, typename _indexT>
typedef _storedT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::storedT

The type stored in the circular buffer.

Definition at line 84 of file circularBuffer.hpp.

Constructor & Destructor Documentation

◆ circularBufferBase() [1/2]

template<class derivedT, typename storedT, typename indexT>
mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::circularBufferBase ( )

Default c'tor.

Definition at line 200 of file circularBuffer.hpp.

◆ circularBufferBase() [2/2]

template<class derivedT, typename storedT, typename indexT>
mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::circularBufferBase ( indexT maxEnt)
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.

Parameters
[in]maxEntthe maximum number of entries this buffer will hold

Definition at line 205 of file circularBuffer.hpp.

References maxEntries().

Member Function Documentation

◆ at() [1/2]

template<class derivedT, typename storedT, typename indexT>
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

Returns
a reference to the indicated entry in the circular buffer.
Parameters
[in]refEntrythe entry to start counting from
[in]idxthe index of the entry to access

Definition at line 313 of file circularBuffer.hpp.

◆ at() [2/2]

template<class derivedT, typename storedT, typename indexT>
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.

Returns
a const reference to the indicated entry in the circular buffer.
Parameters
[in]refEntrythe entry to start counting from
[in]idxthe index of the entry to access

Definition at line 319 of file circularBuffer.hpp.

◆ earliest()

template<class derivedT, typename storedT, typename indexT>
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().

◆ latest()

template<class derivedT, typename storedT, typename indexT>
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().

◆ maxEntries() [1/2]

template<class derivedT, typename storedT, typename indexT>
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.

Returns
the maximum size of the buffer, m_maxEntries

Definition at line 226 of file circularBuffer.hpp.

References m_maxEntries.

◆ maxEntries() [2/2]

template<class derivedT, typename storedT, typename indexT>
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.

Parameters
[in]maxEntthe 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().

◆ nextEntry() [1/2]

template<class derivedT, typename storedT, typename indexT>
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.

◆ nextEntry() [2/2]

template<class derivedT, typename storedT, typename indexT>
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.

Parameters
[in]newEntthe 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().

◆ operator[]() [1/2]

template<class derivedT, typename storedT, typename indexT>
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

Returns
a reference to the indicated entry in the circular buffer.
Parameters
[in]idxthe index of the entry to access

Definition at line 301 of file circularBuffer.hpp.

References m_nextEntry.

◆ operator[]() [2/2]

template<class derivedT, typename storedT, typename indexT>
const storedT & mx::sigproc::circularBufferBase< derivedT, storedT, indexT >::operator[] ( indexT idx) const
Parameters
[in]idxthe index of the entry to access

Definition at line 307 of file circularBuffer.hpp.

References m_nextEntry.

◆ size()

template<class derivedT, typename storedT, typename indexT>
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.

Member Data Documentation

◆ m_buffer

template<typename _derivedT, typename _storedT, typename _indexT>
std::vector<storedT> mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::m_buffer
protected

The circular buffer storage.

Definition at line 90 of file circularBuffer.hpp.

Referenced by maxEntries(), nextEntry(), nextEntry(), and size().

◆ m_latest

template<typename _derivedT, typename _storedT, typename _indexT>
indexT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::m_latest { 0 }
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().

◆ m_maxEntries

template<typename _derivedT, typename _storedT, typename _indexT>
indexT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::m_maxEntries { 0 }
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().

◆ m_mono

template<typename _derivedT, typename _storedT, typename _indexT>
uint64_t mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::m_mono { 0 }
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().

◆ m_nextEntry

template<typename _derivedT, typename _storedT, typename _indexT>
indexT mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >::m_nextEntry { 0 }
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[]().


The documentation for this class was generated from the following file: