Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

chain

The chain class chains together multiple copies of the same component.

Table 1.18. function class use example

fused

unfused

signals::chain<void(float), FusedDoublerClass> doubling_chain(4, NULL);
signals::storage<void (float), signals::fused> floater(1.0f);
signals::storage<void (float), signals::fused> collector(0.0f);

floater >>= doubling_chain >>= collector;
floater.send();

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

signals::chain<void(float), UnfusedDoublerClass> doubling_chain(4, NULL);
signals::storage<void (float)> floater(1.0f);
signals::storage<void (float)> collector(0.0f);

floater >>= doubling_chain >>= collector;
floater.send();

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

The example above uses the following classes:

class UnfusedDoublerClass : public signals::filter<void (float), signals::unfused>
{
public:
    typedef void result_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;
        boost::fusion::at_c<0>(y) = 2 * boost::fusion::at_c<0>(x);
        fused_out(y);
    }
};

Copyright © 2007 Stjepan Rajko

PrevUpHomeNext