mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
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 (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...
 
storedToperator[] (indexT idx)
 Get the entry at a given index. More...
 
const storedToperator[] (indexT idx) const
 
storedTat (indexT refEntry, indexT idx)
 Get the entry at a given index relative a fixed reference entry. More...
 
const storedTat (indexT refEntry, indexT idx) const
 Get the entry at a given index relative a fixed start entry, const version. More...
 

Protected Attributes

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

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 75 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 78 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 77 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 187 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 192 of file circularBuffer.hpp.

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 279 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 287 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 249 of file circularBuffer.hpp.

◆ 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 255 of file circularBuffer.hpp.

◆ 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 214 of file circularBuffer.hpp.

◆ 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 198 of file circularBuffer.hpp.

◆ nextEntry()

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 226 of file circularBuffer.hpp.

◆ 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 267 of file circularBuffer.hpp.

◆ 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 273 of file circularBuffer.hpp.

◆ size()

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

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 82 of file circularBuffer.hpp.

◆ 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 86 of file circularBuffer.hpp.

◆ 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 84 of file circularBuffer.hpp.

◆ 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 88 of file circularBuffer.hpp.

◆ 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 85 of file circularBuffer.hpp.


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