Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ONE::util::EventDispatcher< Evt, Lst, Rly > Class Template Reference

Inheritance diagram for ONE::util::EventDispatcher< Evt, Lst, Rly >:

Inheritance graph
[legend]
List of all members.

Detailed Description

template<class Evt, class Lst, class Rly>
class ONE::util::EventDispatcher< Evt, Lst, Rly >

The Event Dispatcher base class.

event dispatchers keep a list of registered event listeners that are notified of occuring events. This class provides basic infrastructure common to all such dispatchers for easy dispatcher creation. See the Event documentation for further details.
Since the event listener's callback function must be named differently for each listener class (virtual functions must not be overloaded), the dispatcher needs a way to call a function with an unknown name in a generic way. This is handled through Rly, the relay policy. This can be one of the three event related classes or a separate policy class that implements a static forward function. This function forwards the notification to the correct listener function. An example policy may look as follows:

 struct FooRelay {
        inline static void forward(FooEvent& e, const FooDispatcher::LPtr& l) { 
                l->processFooEvent(e); 
        }
 };

Parameters:
Evt the type of Event the dispatcher passes out
Lst the listener class to be registered
Rly the relay policy
Author:
Daniel Seibert


Public Types

typedef Lst * LPtr

Public Member Functions

 EventDispatcher ()
void fireEvent (Evt &e) const
 notifies all registered listeners
bool isMuted () const
 reflects this dispatcher's muted state.
void setMuted (bool mute)
 mutes or un-mutes the dispatcher
virtual ~EventDispatcher ()

Protected Member Functions

void add (const LPtr &l)
 registers a listener
void remove (const LPtr &l)
 de-registers a listener.


Member Typedef Documentation

template<class Evt, class Lst, class Rly>
typedef Lst* ONE::util::EventDispatcher< Evt, Lst, Rly >::LPtr
 


Constructor & Destructor Documentation

template<class Evt, class Lst, class Rly>
ONE::util::EventDispatcher< Evt, Lst, Rly >::EventDispatcher  ) 
 

template<class Evt, class Lst, class Rly>
ONE::util::EventDispatcher< Evt, Lst, Rly >::~EventDispatcher  )  [virtual]
 


Member Function Documentation

template<class Evt, class Lst, class Rly>
void ONE::util::EventDispatcher< Evt, Lst, Rly >::add const LPtr l  )  [inline, protected]
 

registers a listener

Parameters:
l a listener

template<class Evt, class Lst, class Rly>
void ONE::util::EventDispatcher< Evt, Lst, Rly >::fireEvent Evt &  e  )  const
 

notifies all registered listeners

The listeners are called in the order in which they were added.
This function is provided primarily for use by subclasses. However, it may also be called from the outside in order to inject events into the system. Note that great care should be taken when doing so. For example, listeners generally rely on the event's source being identical to the instance that passes them around, i.e. this event dispatcher.

Parameters:
e the event to forward to each listener

template<class Evt, class Lst, class Rly>
bool ONE::util::EventDispatcher< Evt, Lst, Rly >::isMuted  )  const [inline]
 

reflects this dispatcher's muted state.

Returns:
true if the dispatcher is muted, false otherwise

template<class Evt, class Lst, class Rly>
void ONE::util::EventDispatcher< Evt, Lst, Rly >::remove const LPtr l  )  [protected]
 

de-registers a listener.

This listener will no longer notify l of events, unless l is registered more than once. If so, a call to this function will only remove the first occurence of l.

Parameters:
l a listener

template<class Evt, class Lst, class Rly>
void ONE::util::EventDispatcher< Evt, Lst, Rly >::setMuted bool  mute  )  [inline]
 

mutes or un-mutes the dispatcher

Muted dispatchers no longer notify their listeners.


Generated on Wed Sep 7 19:03:31 2005 for ONEngine by  doxygen 1.4.3