39 #include <util/atomic.h> 60 template<
typename T,
typename N,
unsigned int SIZE >
class RingBufferT 70 : mSize( SIZE ), mLength( 0 ), mIndex( 0 )
86 ATOMIC_BLOCK( ATOMIC_RESTORESTATE )
90 element = mBuffer[ mIndex ];
92 if ( mIndex >= mSize )
118 ATOMIC_BLOCK( ATOMIC_RESTORESTATE )
120 element = mBuffer[ ( mIndex + index ) % mSize ];
136 ATOMIC_BLOCK( ATOMIC_RESTORESTATE )
138 if ( mLength < mSize )
140 mBuffer[ ( mIndex + mLength ) % mSize ] = element;
157 return !
static_cast<bool>( mLength );
168 return static_cast<bool>( mLength );
179 ATOMIC_BLOCK( ATOMIC_RESTORESTATE )
181 return ( mSize - mLength ) <= 0;
193 ATOMIC_BLOCK( ATOMIC_RESTORESTATE )
195 return ( mSize - mLength ) > 0;
207 ATOMIC_BLOCK( ATOMIC_RESTORESTATE )
209 if ( nbrElements < mLength )
211 mIndex += nbrElements;
212 if( mIndex >= mSize )
216 mLength -= nbrElements;
232 ATOMIC_BLOCK( ATOMIC_RESTORESTATE )
T pull()
Extract the next (first) element from the ring buffer.
Definition: RingBufferT.h:83
bool isFull()
Determine if the buffer is full and cannot accept more bytes.
Definition: RingBufferT.h:177
void clear()
Clear the ring buffer, leaving it empty.
Definition: RingBufferT.h:230
bool isNotEmpty()
Determine if the buffer is not empty.
Definition: RingBufferT.h:166
bool isEmpty()
Determine if the buffer is empty .
Definition: RingBufferT.h:155
a template-based ring buffer class that can store different kinds of objects in buffers of whatever s...
Definition: RingBufferT.h:60
void discardFromFront(N nbrElements)
discard a number of elements from the front of the ring buffer.
Definition: RingBufferT.h:205
T peek(N index=0)
Examine an element in the ring buffer.
Definition: RingBufferT.h:115
bool isNotFull()
Determine if the buffer is not full and can accept more bytes.
Definition: RingBufferT.h:191
bool push(T element)
Push an element into the ring buffer. The element is appended to the back of the buffer.
Definition: RingBufferT.h:134
RingBufferT()
Construct a ring buffer to store elements of type T indexed by integer type N, with size SIZE...
Definition: RingBufferT.h:69