TINC
Toolkit for Interactive Computation
tinc::DeferredComputation< DataType > Class Template Reference

#include <DeferredComputation.hpp>

Inheritance diagram for tinc::DeferredComputation< DataType >:
tinc::BufferManager< DataType >

Public Member Functions

 DeferredComputation (uint16_t size=2)
 
 ~DeferredComputation ()
 
template<typename Function , typename... ProcessParams>
bool process (Function func, ProcessParams... params)
 
template<typename Function , typename... ProcessParams>
void processAsync (Function &&func, ProcessParams &&... params)
 
bool processing ()
 
std::shared_ptr< DataType > get (bool markAsUsed=true)
 Get current buffer for reading. More...
 
std::shared_ptr< DataType > get (bool *isNew)
 Get current buffer for reading checking if data is new. More...
 
std::shared_ptr< DataType > getWritable ()
 Get a pointer to a writable buffer. More...
 
void doneWriting (std::shared_ptr< DataType > buffer)
 Mark a buffer as ready to read. More...
 
bool newDataAvailable ()
 Check if there are buffers that have been written but not read. More...
 

Public Attributes

std::mutex mAsyncMutex
 
std::condition_variable mAsyncSignal
 
const int mSize
 

Protected Attributes

std::vector< std::shared_ptr< DataType > > mData
 
std::mutex mDataLock
 
bool mNewData {false}
 
uint16_t mReadBuffer {0}
 
uint16_t mWriteBuffer {1}
 

Detailed Description

template<class DataType>
class tinc::DeferredComputation< DataType >

Definition at line 49 of file DeferredComputation.hpp.

Constructor & Destructor Documentation

◆ DeferredComputation()

template<class DataType >
tinc::DeferredComputation< DataType >::DeferredComputation ( uint16_t  size = 2)
inline

Definition at line 51 of file DeferredComputation.hpp.

◆ ~DeferredComputation()

template<class DataType >
tinc::DeferredComputation< DataType >::~DeferredComputation ( )
inline

Definition at line 53 of file DeferredComputation.hpp.

Member Function Documentation

◆ doneWriting()

template<class DataType >
void tinc::BufferManager< DataType >::doneWriting ( std::shared_ptr< DataType >  buffer)
inlineinherited

Mark a buffer as ready to read.

Parameters
bufferThe buffer previously received from getWritable()

The buffer provided must come from getWritable() otherwise behavior is undefined.

Definition at line 114 of file BufferManager.hpp.

◆ get() [1/2]

template<class DataType >
std::shared_ptr<DataType> tinc::BufferManager< DataType >::get ( bool *  isNew)
inlineinherited

Get current buffer for reading checking if data is new.

Parameters
isNewthis is set to true if data returned is "new", false otherwise
Returns

Definition at line 76 of file BufferManager.hpp.

◆ get() [2/2]

template<class DataType >
std::shared_ptr<DataType> tinc::BufferManager< DataType >::get ( bool  markAsUsed = true)
inlineinherited

Get current buffer for reading.

Parameters
markAsUsedif false, the returned buffer keeps its "new" status
Returns
a pointer to the data

Definition at line 63 of file BufferManager.hpp.

◆ getWritable()

template<class DataType >
std::shared_ptr<DataType> tinc::BufferManager< DataType >::getWritable ( )
inlineinherited

Get a pointer to a writable buffer.

When done writing this buffer, call doneWriting()

Definition at line 92 of file BufferManager.hpp.

◆ newDataAvailable()

template<class DataType >
bool tinc::BufferManager< DataType >::newDataAvailable ( )
inlineinherited

Check if there are buffers that have been written but not read.

Definition at line 124 of file BufferManager.hpp.

◆ process()

template<class DataType >
template<typename Function , typename... ProcessParams>
bool tinc::DeferredComputation< DataType >::process ( Function  func,
ProcessParams...  params 
)
inline

Definition at line 87 of file DeferredComputation.hpp.

◆ processAsync()

template<class DataType >
template<typename Function , typename... ProcessParams>
void tinc::DeferredComputation< DataType >::processAsync ( Function &&  func,
ProcessParams &&...  params 
)
inline

Definition at line 116 of file DeferredComputation.hpp.

◆ processing()

template<class DataType >
bool tinc::DeferredComputation< DataType >::processing ( )
inline

Definition at line 152 of file DeferredComputation.hpp.

Member Data Documentation

◆ mAsyncMutex

template<class DataType >
std::mutex tinc::DeferredComputation< DataType >::mAsyncMutex

Definition at line 134 of file DeferredComputation.hpp.

◆ mAsyncSignal

template<class DataType >
std::condition_variable tinc::DeferredComputation< DataType >::mAsyncSignal

Definition at line 135 of file DeferredComputation.hpp.

◆ mData

template<class DataType >
std::vector<std::shared_ptr<DataType> > tinc::BufferManager< DataType >::mData
protectedinherited

Definition at line 130 of file BufferManager.hpp.

◆ mDataLock

template<class DataType >
std::mutex tinc::BufferManager< DataType >::mDataLock
protectedinherited

Definition at line 132 of file BufferManager.hpp.

◆ mNewData

template<class DataType >
bool tinc::BufferManager< DataType >::mNewData {false}
protectedinherited

Definition at line 133 of file BufferManager.hpp.

◆ mReadBuffer

template<class DataType >
uint16_t tinc::BufferManager< DataType >::mReadBuffer {0}
protectedinherited

Definition at line 134 of file BufferManager.hpp.

◆ mSize

template<class DataType >
const int tinc::BufferManager< DataType >::mSize
inherited

Definition at line 50 of file BufferManager.hpp.

◆ mWriteBuffer

template<class DataType >
uint16_t tinc::BufferManager< DataType >::mWriteBuffer {1}
protectedinherited

Definition at line 135 of file BufferManager.hpp.


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