VR-Forces 4.0.4 Class Documentation
Public Member Functions | Protected Member Functions | Protected Attributes
makVrv::DtLockedBufferedQueue< T > Class Template Reference

A locked buffered queue which allows multiple writers and a single reader. More...

Inheritance diagram for makVrv::DtLockedBufferedQueue< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 DtLockedBufferedQueue ()
 ~DtLockedBufferedQueue ()
 DTOR If the type T is a pointer memory must be explicitly deleting by iterating throug both vectors call getForReading twice.
unsigned int push (T value)
 Add a value to to the buffer.
unsigned int push (std::vector< T > &valueVector)
 Add several values to to the buffer.
void getForReading (std::vector< T > *&output)
 Get a vector for reading.
void deleteAllPointers ()
 Helper function for deleting all member pointers in both buffers.
void clearBuffers ()
 Helper function to clear all the buffers, if the buffers contain pointers call deleteAllPointers() first.

Protected Member Functions

void swapBuffers ()
 Internal function for swapping buffers and clearing the write buffer.

Protected Attributes

std::vector< T > myFirstBuffer
std::vector< T > mySecondBuffer
std::vector< T > * myCurrentBuffer
DtMutex myBufferMutex

Detailed Description

template<typename T>
class makVrv::DtLockedBufferedQueue< T >

A locked buffered queue which allows multiple writers and a single reader.

Internally the queue is stored as a double buffered vector. Ideally the vector will not shrink in size so frequent calls getForReading is advised.


Constructor & Destructor Documentation

template<typename T>
makVrv::DtLockedBufferedQueue< T >::DtLockedBufferedQueue ( )
template<typename T>
makVrv::DtLockedBufferedQueue< T >::~DtLockedBufferedQueue ( )

DTOR If the type T is a pointer memory must be explicitly deleting by iterating throug both vectors call getForReading twice.


Member Function Documentation

template<typename T>
unsigned int makVrv::DtLockedBufferedQueue< T >::push ( value)

Add a value to to the buffer.

This function is thread safe and reentrant. The return value is the current size of the buffer. This is useful when throttling writing speed due to insufficient reads.

template<typename T>
unsigned int makVrv::DtLockedBufferedQueue< T >::push ( std::vector< T > &  valueVector)

Add several values to to the buffer.

This function is thread safe and reentrant. The return value is the current size of the buffer. This is useful when throttling writing speed due to insufficient reads.

template<typename T>
void makVrv::DtLockedBufferedQueue< T >::getForReading ( std::vector< T > *&  output)

Get a vector for reading.

This function should only be called by the reader thread. The pointer reference is written to, and can be initially null. The pointer is guaranteed to be valid and not NULL after a call to getForReading. The pointer is only valid until the next call to getForReading. There is no need to clear the buffer when reading is done. The contents of the output will not change until the next call to getForReading. All iterators are invalidated with the next call to getForReading.

 void printInt(int i) { std::cout << i << std::endl;}
 ...
 std::vector<int>* readVector(0);
 myQueue.getForReading(readVector);
 //Print each integer, 
 std::for_each(readVector->begin(),readVector->end(),&printInt);
 //Not necessary but not a bad idea either.
 readVector = 0;
template<typename T>
void makVrv::DtLockedBufferedQueue< T >::deleteAllPointers ( )

Helper function for deleting all member pointers in both buffers.

This function is not valid if T is not a pointer type, of the pointers are not allocated using 'new' or if they used new[]

Warning:
This function is not thread safe.!!!!
template<typename T>
void makVrv::DtLockedBufferedQueue< T >::clearBuffers ( )

Helper function to clear all the buffers, if the buffers contain pointers call deleteAllPointers() first.

Warning:
This function is not thread safe.!!!!
template<typename T>
void makVrv::DtLockedBufferedQueue< T >::swapBuffers ( ) [protected]

Internal function for swapping buffers and clearing the write buffer.


Member Data Documentation

template<typename T>
std::vector<T> makVrv::DtLockedBufferedQueue< T >::myFirstBuffer [protected]
template<typename T>
std::vector<T> makVrv::DtLockedBufferedQueue< T >::mySecondBuffer [protected]
template<typename T>
std::vector<T>* makVrv::DtLockedBufferedQueue< T >::myCurrentBuffer [protected]
template<typename T>
DtMutex makVrv::DtLockedBufferedQueue< T >::myBufferMutex [protected]

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

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)