Boost logo

Boost :

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

Mathew Robertson 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!
> What makes this worse is that you often want to synthesise other
> events eg:
> - MouseClick+LeftAlt
> - MouseMove-Left-Down (think 'mouse gestures')
> - etc

Just create a boost::signal<> for the mouse click and pass along all the
information about the keyboard with it to the handler. Let the handler
decide what should then be done with it. The handler could also be you,
internally, ready to trigger a new event for some special situation. The
point being that if you decide to have X number of events for a particular
class, and you decide that some subset of X can be handled by the user, you
are going to have to trigger those events anyway, so having subset-X
boost::signals to do it by is no less of a cost than any other way. Remember
also that boost::signal<> are just variabales like anything else and can be
inherited like anything else by a specific derived class over a broader base
class. There is no reason, if you have a particular mouse event as a
boost::signal<> for a base class type of "window" to have to create another
mouse event of the exact same type, as a boost::signal<>, for the derived

Boost list run by bdawes at, gregod at, cpdaniel at, john at