Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Multiple inputs of the same signature

In some cases, a class may want to receive multiple signals of the same signature.

For example, the following class could receive void() signals both through operator() and through AltInput:

class Signal2VoidCounter : public signals::counter<void (), signals::unfused>
{
public:
	signals::counter<void (), signals::unfused> other;
}; // end class Signal2VoidCounter

class Signal2VoidInputs
{
	int result;
public:
    typedef void result_type;
    
	Signal2VoidInputs() : result(0) {};
	void operator()()
	{
		result++;
	}
	void AltInput()
	{
		result+=10;
	}
	int GetResult()
	{
		return result;
	}
}; // end class Signal2VoidInputs

The following example shows how to connect signals to all of the above slots. For the class Signal2VoidInputs, this is accomplished using the slot_selector function:

Table 1.10. multiple slots example

fused

unfused

signals::storage<void (), signals::unfused> banger;
Signal2VoidCounter counter;

banger
    | counter
    | counter.other;

banger();
BOOST_CHECK_EQUAL(counter.count(), 1);
BOOST_CHECK_EQUAL(counter.other.count(), 1);

Signal2VoidInputs inputs;

banger
    | inputs
    | signals::make_slot_selector<void ()> (&Signal2VoidInputs::AltInput, inputs);

banger();
BOOST_CHECK_EQUAL(inputs.GetResult(), 11);

Copyright © 2007 Stjepan Rajko

PrevUpHomeNext