CuteLogger
Fast and simple logging solution for Qt based applications
DataQueue< T > Class Template Reference

The DataQueue provides a thread safe container for passing data between objects. More...

#include <dataqueue.h>

Public Types

enum  OverflowMode { OverflowModeDiscardOldest = 0 , OverflowModeDiscardNewest , OverflowModeWait }
 Overflow behavior modes. More...
 

Public Member Functions

 DataQueue (int maxSize, OverflowMode mode)
 
virtual ~DataQueue ()
 Destructs a DataQueue.
 
void push (const T &item)
 
pop ()
 
int count () const
 Returns the number of items in the queue.
 

Detailed Description

template<class T>
class DataQueue< T >

The DataQueue provides a thread safe container for passing data between objects.

\threadsafe

DataQueue provides a limited size container for passing data between objects. One object can add data to the queue by calling push() while another object can remove items from the queue by calling pop().

DataQueue provides configurable behavior for handling overflows. It can discard the oldest, discard the newest or block the object calling push() until room has been freed in the queue by another object calling pop().

DataQueue is threadsafe and is therefore most appropriate when passing data between objects operating in different thread contexts.

Member Enumeration Documentation

◆ OverflowMode

template<class T >
enum DataQueue::OverflowMode

Overflow behavior modes.

Enumerator
OverflowModeDiscardOldest 

Discard oldest items.

OverflowModeDiscardNewest 

Discard newest items.

OverflowModeWait 

Wait for space to be free.

Constructor & Destructor Documentation

◆ DataQueue()

template<class T >
DataQueue< T >::DataQueue ( int maxSize,
OverflowMode mode )
explicit

Constructs a DataQueue.

The size will be the maximum queue size and the mode will dictate overflow behavior.

Member Function Documentation

◆ pop()

template<class T >
T DataQueue< T >::pop ( )

Pops an item from the queue.

If the queue is empty then this function will block. If blocking is undesired, then check the return of count() before calling pop().

◆ push()

template<class T >
void DataQueue< T >::push ( const T & item)

Pushes an item into the queue.

If the queue is full and overflow mode is OverflowModeWait then this function will block until pop() is called.


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