csp::common::FunctionProcess< DATA_TYPE_IN, DATA_TYPE_OUT, FUNCTION > Class Template Reference

Inheritance diagram for csp::common::FunctionProcess< DATA_TYPE_IN, DATA_TYPE_OUT, FUNCTION >:

csp::CSProcess csp::ThreadCSProcess boost::noncopyable List of all members.

Detailed Description

template<typename DATA_TYPE_IN, typename DATA_TYPE_OUT, typename FUNCTION = DATA_TYPE_OUT (*)(const DATA_TYPE_IN&)>
class csp::common::FunctionProcess< DATA_TYPE_IN, DATA_TYPE_OUT, FUNCTION >

This process acts like an Id process, but applies a transformation to the data before sending it on.

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>

DATA_TYPE Requirements

DATA_TYPE_IN must have a default constructor, and must meet the requirements of the channels it is being used with.

DATA_TYPE_OUT Requirements

DATA_TYPE_OUT must meet the requirements of the channels it is being used with.

DATA_TYPE Requirements

FUNCTION must have a copy constructor, and must either be:


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.


Constructor & Destructor Documentation

template<typename DATA_TYPE_IN, typename DATA_TYPE_OUT, typename FUNCTION = DATA_TYPE_OUT (*)(const DATA_TYPE_IN&)>
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.

Parameters:
_in The input channel
_out The output channel
_func The function to call


Member Function Documentation

template<typename DATA_TYPE_IN, typename DATA_TYPE_OUT, typename FUNCTION = DATA_TYPE_OUT (*)(const DATA_TYPE_IN&)>
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.


Generated on Mon Aug 20 12:24:29 2007 for C++CSP2 by  doxygen 1.4.7