Jamba C++ API  5.1.1
CircularBuffer< T > Class Template Reference

#include <CircularBuffer.h>

Public Member Functions

 CircularBuffer (int iSize)
 
 CircularBuffer (CircularBuffer const &iOther)
 
void copyToBuffer (int startOffset, T *oBuffer, int iSize)
 
template<typename U , class BinaryPredicate >
fold (int startOffset, int endOffsetNotIncluded, U initValue, BinaryPredicate &op) const
 "standard" implementation of the fold algorithm starting at startOffset and ending at endOffsetNotIncluded (which as the name hinted is NOT included). More...
 
template<typename U , class BinaryPredicate >
fold (int endOffsetNotIncluded, U initValue, BinaryPredicate &op) const
 Shortcut with startOffset 0. More...
 
template<typename U , class BinaryPredicate >
fold (U initValue, BinaryPredicate &op) const
 Shortcut for entire buffer (starting at startOffset 0) More...
 
template<typename U , class BinaryPredicateWithIndex >
foldWithIndex (int startOffset, int endOffsetNotIncluded, U initValue, BinaryPredicateWithIndex &op) const
 Similar to fold but BinaryPredicateWithIndex is also provided the index (starting at startOffset) More...
 
template<typename U , class BinaryPredicateWithIndex >
foldWithIndex (int endOffsetNotIncluded, U initValue, BinaryPredicateWithIndex &op) const
 Shortcut with startOffset = 0. More...
 
template<typename U , class BinaryPredicateWithIndex >
foldWithIndex (U initValue, BinaryPredicateWithIndex &op) const
 Shortcut for entire buffer (starting at startOffset 0) More...
 
getAt (int offset) const
 
int getSize () const
 
void incrementHead ()
 
void init (T initValue)
 
void push (T e)
 
void setAt (int offset, T e)
 
 ~CircularBuffer ()
 

Private Member Functions

int adjustIndex (int index) const
 
int adjustIndexFromOffset (int offset) const
 

Private Attributes

T * fBuf
 
int fSize
 
int fStart
 

Constructor & Destructor Documentation

◆ CircularBuffer() [1/2]

CircularBuffer ( int  iSize)
inlineexplicit

◆ CircularBuffer() [2/2]

CircularBuffer ( CircularBuffer< T > const &  iOther)
inline

◆ ~CircularBuffer()

~CircularBuffer ( )
inline

Member Function Documentation

◆ adjustIndex()

int adjustIndex ( int  index) const
inlineprivate

◆ adjustIndexFromOffset()

int adjustIndexFromOffset ( int  offset) const
inlineprivate

◆ copyToBuffer()

void copyToBuffer ( int  startOffset,
T *  oBuffer,
int  iSize 
)
inline

◆ fold() [1/3]

U fold ( int  startOffset,
int  endOffsetNotIncluded,
initValue,
BinaryPredicate &  op 
) const
inline

"standard" implementation of the fold algorithm starting at startOffset and ending at endOffsetNotIncluded (which as the name hinted is NOT included).

This implementation works fine whether startOffset is less or more than endOffsetNotIncluded (in which case the direction of iteration is reversed). It also handles properly wrapping around the buffer (potentially multiple times...).

The fold algorithm is the following:

resultValue = initValue;
resultValue = op(resultValue, fBuf[<adjusted start offset>]);
resultValue = op(resultValue, fBuf[<adjusted start offset> + 1]);
...
return resultValue;

Technically speaking the BinaryPredicate is defined like this

template<typename U>
using BinaryPredicate = U (*)(U const&, T const&);

BUT it is not really defined in the following methods because of the fact that lambda with capture cannot be converted to it... where by defining it loosely this way, it just works...

◆ fold() [2/3]

U fold ( int  endOffsetNotIncluded,
initValue,
BinaryPredicate &  op 
) const
inline

Shortcut with startOffset 0.

◆ fold() [3/3]

U fold ( initValue,
BinaryPredicate &  op 
) const
inline

Shortcut for entire buffer (starting at startOffset 0)

◆ foldWithIndex() [1/3]

U foldWithIndex ( int  startOffset,
int  endOffsetNotIncluded,
initValue,
BinaryPredicateWithIndex &  op 
) const
inline

Similar to fold but BinaryPredicateWithIndex is also provided the index (starting at startOffset)

template<typename U>
using BinaryPredicateWithIndex = U (*)(int, U const&, T const&);

◆ foldWithIndex() [2/3]

U foldWithIndex ( int  endOffsetNotIncluded,
initValue,
BinaryPredicateWithIndex &  op 
) const
inline

Shortcut with startOffset = 0.

◆ foldWithIndex() [3/3]

U foldWithIndex ( initValue,
BinaryPredicateWithIndex &  op 
) const
inline

Shortcut for entire buffer (starting at startOffset 0)

◆ getAt()

T getAt ( int  offset) const
inline

◆ getSize()

int getSize ( ) const
inline

◆ incrementHead()

void incrementHead ( )
inline

◆ init()

void init ( initValue)
inline

◆ push()

void push ( e)
inline

◆ setAt()

void setAt ( int  offset,
e 
)
inline

Member Data Documentation

◆ fBuf

T* fBuf
private

◆ fSize

int fSize
private

◆ fStart

int fStart
private

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