Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

filter

See also: filter class reference.

The filter class is provided as a base class for in / out components. It provides support for Signal Network connection operators, and provides a default output signal. Here is an example of a simple class which inherits filter:

class DoublerClass : public signals::filter<void (float), signals::unfused>
{
public:
    typedef signals::filter<void (float), signals::unfused>::signal_type signal_type;
    template<typename FArgs>
    struct result
    {
        typedef void type;
    };
    
    void operator()(float x) {out(2*x);}
};

class FusedDoublerClass : public signals::filter<void (float), signals::fused>
{
public:
    typedef void result_type;
    void operator()(const fusion::vector<float> &x)
    {
        // this could be more general but I'm having problems with the general approach...
        fusion::vector<float> y;
        fusion::at_c<0>(y) = 2 * fusion::at_c<0>(x);
        fused_out(y);
    }
};

The type of the output signal (in the above example, unfused_out_signal) is specified as the second template parameter. There are three options:

A component developed on top of the filter class can then be used in the appropriate network. Here is an example which uses the class defined above:

Table 1.12. filter-based class use example

fused

unfused

FusedDoublerClass doubler1, doubler2;
signals::storage<void (float), signals::fused> floater(1.0f);
signals::storage<void (float), signals::fused> collector(0.0f);

floater >>= doubler1 >>= doubler2 >>= collector;
floater.send();

BOOST_CHECK_EQUAL(collector.at<0>(), 4.0f);

DoublerClass doubler1, doubler2;
signals::storage<void (float)> floater(1.0f);
signals::storage<void (float)> collector(0.0f);

floater >>= doubler1 >>= doubler2 >>= collector;
floater.send();

BOOST_CHECK_EQUAL(collector.at<0>(), 4.0f);

Copyright © 2007 Stjepan Rajko

PrevUpHomeNext