v2.0.0
Loading...
Searching...
No Matches
UTILSLIB::CircularBuffer< T > Class Template Reference

Thread-safe lock-free circular (ring) buffer for producer-consumer data exchange between threads. More...

#include <circularbuffer.h>

Public Types

typedef QSharedPointer< CircularBuffer > SPtr
typedef QSharedPointer< const CircularBuffer > ConstSPtr

Public Member Functions

 CircularBuffer (unsigned int uiMaxNumElements)
 ~CircularBuffer ()
bool push (const T *pArray, unsigned int size)
bool push (const T &newElement)
bool pop (T &element)
void clear ()
void pause (bool)
int getFreeElementsRead ()
int getFreeElementsWrite ()

Detailed Description

template<typename T>
class UTILSLIB::CircularBuffer< T >

Thread-safe lock-free circular (ring) buffer for producer-consumer data exchange between threads.

TEMPLATE CIRCULAR BUFFER

Definition at line 72 of file circularbuffer.h.

Member Typedef Documentation

◆ ConstSPtr

template<typename T>
typedef QSharedPointer<const CircularBuffer> UTILSLIB::CircularBuffer< T >::ConstSPtr

Const shared pointer type for CircularBuffer.

Definition at line 76 of file circularbuffer.h.

◆ SPtr

template<typename T>
typedef QSharedPointer<CircularBuffer> UTILSLIB::CircularBuffer< T >::SPtr

Shared pointer type for CircularBuffer.

Definition at line 75 of file circularbuffer.h.

Constructor & Destructor Documentation

◆ CircularBuffer()

template<typename T>
UTILSLIB::CircularBuffer< T >::CircularBuffer ( unsigned int uiMaxNumElements)
explicit

Constructs a CircularBuffer.

Parameters
[in]uiMaxNumElementslength of buffer.

Definition at line 178 of file circularbuffer.h.

◆ ~CircularBuffer()

template<typename T>
UTILSLIB::CircularBuffer< T >::~CircularBuffer ( )
default

Destroys the CircularBuffer.

Member Function Documentation

◆ clear()

template<typename T>
void UTILSLIB::CircularBuffer< T >::clear ( )
inline

Clears the buffer.

Definition at line 266 of file circularbuffer.h.

◆ getFreeElementsRead()

template<typename T>
int UTILSLIB::CircularBuffer< T >::getFreeElementsRead ( )
inline

Returns the number of free elements for thread safe reading.

Returns
Number of elements currently available to pop.

Definition at line 286 of file circularbuffer.h.

◆ getFreeElementsWrite()

template<typename T>
int UTILSLIB::CircularBuffer< T >::getFreeElementsWrite ( )
inline

Returns the number of free elements for thread safe reading.

Returns
Number of free slots currently available to push into.

Definition at line 294 of file circularbuffer.h.

◆ pause()

template<typename T>
void UTILSLIB::CircularBuffer< T >::pause ( bool bPause)
inline

Pauses the buffer. Skpis any incoming matrices and only pops zero matrices.

Parameters
[in]bPauseTrue to pause the buffer, false to resume it.

Definition at line 278 of file circularbuffer.h.

◆ pop()

template<typename T>
bool UTILSLIB::CircularBuffer< T >::pop ( T & element)
inline

Returns the first element (first in first out).

Parameters
[out]elementReceives the first element; left unchanged on failure.
Returns
True if an element was popped, false if the buffer is paused or empty within the timeout.

Definition at line 238 of file circularbuffer.h.

◆ push() [1/2]

template<typename T>
bool UTILSLIB::CircularBuffer< T >::push ( const T & newElement)
inline

Adds an element at the end of the buffer.

Parameters
[in]newElementpointer to an Array which should be apend to the end.
Returns
True if the element was written, false if the buffer is paused or no space freed up within the timeout.

Definition at line 219 of file circularbuffer.h.

◆ push() [2/2]

template<typename T>
bool UTILSLIB::CircularBuffer< T >::push ( const T * pArray,
unsigned int size )
inline

Adds a whole array at the end buffer.

Parameters
[in]pArraypointer to an Array which should be apend to the end.
[in]sizenumber of elements containing the array.
Returns
True if all elements were written, false if the buffer is paused or no space freed up within the timeout.

Definition at line 198 of file circularbuffer.h.


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