Inheritance diagram for csp::common::EvaluateFunction< RESULT, FUNCTION >:
This process calls a function/calls operator() on a function class once and sends out the output. It can be viewed as a simple way to distribute some processing into another thread. For example, this will search a list in another process:
template <typename T> class ListSearcher { public: std::list<T>* data; T const * target; typename std::list<T>::iterator operator()() { return std::find(data->begin(),data->end(),*target); } inline ListSearcher(std::list<T>* _data,T const * _target) : data(_data),target(_target) { } }; // In some process: list<int> hugeList; // ... fill hugeList ... One2OneChannel< list<int>::iterator > c0,c1,c2; const int target0 = 36; const int target1 = 49; const int target2 = 64; ScopedForking forking; forking.fork(new EvaluateFunction< list<int>::iterator , ListSearcher<int> >(ListSearcher<int>(&hugeList,&target0),c0.writer())); forking.fork(new EvaluateFunction< list<int>::iterator , ListSearcher<int> >(ListSearcher<int>(&hugeList,&target1),c1.writer())); forking.fork(new EvaluateFunction< list<int>::iterator , ListSearcher<int> >(ListSearcher<int>(&hugeList,&target2),c2.writer())); list<int>::iterator res0,res1,res2; c0.reader() >> res0; c1.reader() >> res1; c2.reader() >> res2; if (res0 == hugeList.end() && res1 == hugeList.end() && res2 == hugeList.end()) { //No values found, do something }
A simpler example is:
One2OneChannel<int> c; ScopedForking forking; forking.fork(new EvaluateFunction<int>(&::rand,c.writer())); int n; //Read a random value into n: c.reader() >> n;
To use this process, you will need to include <cppcsp/common/basic.h>
Public Member Functions | |
EvaluateFunction (const FUNCTION &_func, const Chanout< RESULT > &_out) | |
Constructs the process. | |
Protected Member Functions | |
void | run () |
You must implement this function to provide the code for your process. |
csp::common::EvaluateFunction< RESULT, FUNCTION >::EvaluateFunction | ( | const FUNCTION & | _func, | |
const Chanout< RESULT > & | _out | |||
) | [inline] |
Constructs the process.
_func | The function to call | |
_out | The output channel to send the result out on. |
void csp::common::EvaluateFunction< RESULT, FUNCTION >::run | ( | ) | [inline, protected, virtual] |
You must implement this function to provide the code for your process.
When the run method finishes, the process will terminate.
You should not let an uncaught exception cause the end of this function. If it derives from std::exception, it will be caught (although this behaviour should not be relied upon) but otherwise undefined behaviour will result.
Implements csp::ThreadCSProcess.