Boost logo

Boost :

From: Edward Diener (eddielee_at_[hidden])
Date: 2004-08-20 21:29:12


Reece Dunn wrote:
> Edward Diener wrote:
>> Why not use boost::signals for your event interface. It is much
>> better than hand-coded actions and listeners, since any type of
>> function can handle an event. The technology is already in Boost so
>> why re-invent the wheel.
>
> The signals library looks very good, but it solves half the problem.
> You
> need to work out what types of signals are raised:
> MouseUp
> MouseDown
> MouseDoubleClick
> MouseMove
> and have a signal for each. This would mean that you could have
> hundreds of signals!

You need to have a signal for each event which could occur anyway, so that
others can handle them. But you shouldn't need to create a new signal in a
derived class for an event which occurs in a base class.

>
> It might be easier to group events by type, use signals to dispatch
> them and an event handler like I suggested to deal with them, e.g.
> MouseEvent( unsigned int event, const MouseEvent & info );
> KeyEvent( unsigned int event, const KeyEvent & info );

Why do you have to create event handlers for people to use. Just create
boost::signal<> which encapsulates the parameters you want to pass when the
event occurs. Give it a name which relates to the event that is happening,
and let anyone simply add their slot to the signal. When your code
determines that the event has occurred, just trigger the signal and allow
anyone, including your own internal code if necessary, to handle the event.
Why do I like this ? Because systems that determine that one must be
this-or-that to handle an event are always unnecessarily limiting in one way
or another.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk