18 #ifndef __PONGASOFT_UTILS_COLLECTION_CIRCULAR_BUFFER_H__ 19 #define __PONGASOFT_UTILS_COLLECTION_CIRCULAR_BUFFER_H__ 26 namespace Collection {
56 inline T
getAt(
int offset)
const 61 inline void setAt(
int offset, T e)
77 inline void init(T initValue)
79 for(
int i = 0; i <
fSize; ++i)
89 if(adjStartOffset + iSize <
fSize)
91 memcpy(oBuffer, &
fBuf[adjStartOffset], iSize *
sizeof(T));
95 int i = adjStartOffset;
96 for(
int k = 0; k < iSize; k++)
129 template<
typename U,
class BinaryPredicate>
130 inline U
fold(
int startOffset,
int endOffsetNotIncluded, U initValue, BinaryPredicate &op)
const 132 if(startOffset == endOffsetNotIncluded)
135 U resultValue = initValue;
139 if(startOffset < endOffsetNotIncluded)
141 int size = endOffsetNotIncluded - startOffset;
144 resultValue = op(resultValue,
fBuf[i]);
153 int size = startOffset - endOffsetNotIncluded;
156 resultValue = op(resultValue,
fBuf[i]);
170 template<
typename U,
class BinaryPredicate>
171 inline U
fold(
int endOffsetNotIncluded, U initValue, BinaryPredicate &op)
const 173 return fold(0, endOffsetNotIncluded, initValue, op);
179 template<
typename U,
class BinaryPredicate>
180 inline U
fold(U initValue, BinaryPredicate &op)
const 191 template<
typename U,
class BinaryPredicateWithIndex>
192 inline U
foldWithIndex(
int startOffset,
int endOffsetNotIncluded, U initValue, BinaryPredicateWithIndex &op)
const 194 if(startOffset == endOffsetNotIncluded)
197 U resultValue = initValue;
200 int index = startOffset;
202 if(startOffset < endOffsetNotIncluded)
204 int size = endOffsetNotIncluded - startOffset;
207 resultValue = op(index, resultValue,
fBuf[i]);
217 int size = startOffset - endOffsetNotIncluded;
220 resultValue = op(index, resultValue,
fBuf[i]);
235 template<
typename U,
class BinaryPredicateWithIndex>
236 inline U
foldWithIndex(
int endOffsetNotIncluded, U initValue, BinaryPredicateWithIndex &op)
const 238 return foldWithIndex(0, endOffsetNotIncluded, initValue, op);
244 template<
typename U,
class BinaryPredicateWithIndex>
268 while(index >=
fSize)
283 #endif // __PONGASOFT_UTILS_COLLECTION_CIRCULAR_BUFFER_H__ CircularBuffer(int iSize)
Definition: CircularBuffer.h:32
void copyToBuffer(int startOffset, T *oBuffer, int iSize)
Definition: CircularBuffer.h:85
U foldWithIndex(int endOffsetNotIncluded, U initValue, BinaryPredicateWithIndex &op) const
Shortcut with startOffset = 0.
Definition: CircularBuffer.h:236
U fold(int startOffset, int endOffsetNotIncluded, U initValue, BinaryPredicate &op) const
"standard" implementation of the fold algorithm starting at startOffset and ending at endOffsetNotInc...
Definition: CircularBuffer.h:130
U foldWithIndex(int startOffset, int endOffsetNotIncluded, U initValue, BinaryPredicateWithIndex &op) const
Similar to fold but BinaryPredicateWithIndex is also provided the index (starting at startOffset)
Definition: CircularBuffer.h:192
void setAt(int offset, T e)
Definition: CircularBuffer.h:61
void init(T initValue)
Definition: CircularBuffer.h:77
~CircularBuffer()
Definition: CircularBuffer.h:45
U fold(int endOffsetNotIncluded, U initValue, BinaryPredicate &op) const
Shortcut with startOffset 0.
Definition: CircularBuffer.h:171
int adjustIndexFromOffset(int offset) const
Definition: CircularBuffer.h:251
U fold(U initValue, BinaryPredicate &op) const
Shortcut for entire buffer (starting at startOffset 0)
Definition: CircularBuffer.h:180
void incrementHead()
Definition: CircularBuffer.h:66
void push(T e)
Definition: CircularBuffer.h:71
Definition: CircularBuffer.h:29
U foldWithIndex(U initValue, BinaryPredicateWithIndex &op) const
Shortcut for entire buffer (starting at startOffset 0)
Definition: CircularBuffer.h:245
int getSize() const
Definition: CircularBuffer.h:51
int fStart
Definition: CircularBuffer.h:276
T * fBuf
Definition: CircularBuffer.h:275
T getAt(int offset) const
Definition: CircularBuffer.h:56
int adjustIndex(int index) const
Definition: CircularBuffer.h:259
CircularBuffer(CircularBuffer const &iOther)
Definition: CircularBuffer.h:39
int fSize
Definition: CircularBuffer.h:274