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__ U foldWithIndex(U initValue, BinaryPredicateWithIndex &op) const
Definition: CircularBuffer.h:245
CircularBuffer(CircularBuffer const &iOther)
Definition: CircularBuffer.h:39
void copyToBuffer(int startOffset, T *oBuffer, int iSize)
Definition: CircularBuffer.h:85
~CircularBuffer()
Definition: CircularBuffer.h:45
T getAt(int offset) const
Definition: CircularBuffer.h:56
T * fBuf
Definition: CircularBuffer.h:275
U fold(int startOffset, int endOffsetNotIncluded, U initValue, BinaryPredicate &op) const
Definition: CircularBuffer.h:130
U fold(U initValue, BinaryPredicate &op) const
Definition: CircularBuffer.h:180
int adjustIndexFromOffset(int offset) const
Definition: CircularBuffer.h:251
void incrementHead()
Definition: CircularBuffer.h:66
void setAt(int offset, T e)
Definition: CircularBuffer.h:61
int adjustIndex(int index) const
Definition: CircularBuffer.h:259
Definition: CircularBuffer.h:29
void init(T initValue)
Definition: CircularBuffer.h:77
int fSize
Definition: CircularBuffer.h:274
int fStart
Definition: CircularBuffer.h:276
U fold(int endOffsetNotIncluded, U initValue, BinaryPredicate &op) const
Definition: CircularBuffer.h:171
U foldWithIndex(int endOffsetNotIncluded, U initValue, BinaryPredicateWithIndex &op) const
Definition: CircularBuffer.h:236
int getSize() const
Definition: CircularBuffer.h:51
void push(T e)
Definition: CircularBuffer.h:71
U foldWithIndex(int startOffset, int endOffsetNotIncluded, U initValue, BinaryPredicateWithIndex &op) const
Definition: CircularBuffer.h:192
CircularBuffer(int iSize)
Definition: CircularBuffer.h:32