Inheritance diagram for csp::common::FunctionProcess< DATA_TYPE_IN, DATA_TYPE_OUT, FUNCTION >:
For example, the following code will make the process continually read in a value, and send out the cosine of that value:
Run(new FunctionProcess<float,float>(in,out,&cosf));
Similarly, this code will continually read in a type MyVariant, and apply MyVisitor to it, returning the result:
//class MyVisitor : static_visitor<std::string> // MyVisitor is assumed to have an operator()(const MyVariant& v) method // that calls apply_visitor(*this,v); Run(new FunctionProcess<MyVariant,std::string,MyVisitor>(in,out, MyVisitor() ));
If you want to send more than one parameter to the function consider using a data structure (either a class/struct, or std::pair or boost::tuple) and potentially wrapping a function (or function class) around your desired function that separates out these parameters and passes them to the real function.
To use this process, you will need to include <cppcsp/common/basic.h>
Public Member Functions | |
FunctionProcess (const Chanin< DATA_TYPE_IN > _in, const Chanout< DATA_TYPE_OUT > &_out, const FUNCTION &_func) | |
Constructs the process. | |
Protected Member Functions | |
void | run () |
You must implement this function to provide the code for your process. |
csp::common::FunctionProcess< DATA_TYPE_IN, DATA_TYPE_OUT, FUNCTION >::FunctionProcess | ( | const Chanin< DATA_TYPE_IN > | _in, | |
const Chanout< DATA_TYPE_OUT > & | _out, | |||
const FUNCTION & | _func | |||
) | [inline] |
Constructs the process.
_in | The input channel | |
_out | The output channel | |
_func | The function to call |
void csp::common::FunctionProcess< DATA_TYPE_IN, DATA_TYPE_OUT, 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.