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

ONE::util::Event< Disp > Class Template Reference

Inheritance diagram for ONE::util::Event< Disp >:

Inheritance graph
[legend]
List of all members.

Detailed Description

template<class Disp>
class ONE::util::Event< Disp >

Base class for all system events.

The event framework relies on three classes: the event that is passed out, a dispatcher that sends the events and listeners that receive them. The former two are based on the Event and EventDispatcher base classes. In order to create a new event type, developers should write subclasses of these two classes and provide an appropriate listener interface. A typical implementation is listed below.

 class FooDispatcher;

 class FooEvent : public Event<FooDispatcher> {
 private:
        //event data
 public:
        FooEvent(FooDispatcher* src) : Event<FooDispatcher>(src) {}
        //data accessors
 };
 
 class FooListener {
 public:
        virtual ~FooListener() {}
        virtual void processFooEvent(FooEvent&) = 0;
 };

 class FooDispatcher : public EventDispatcher<FooEvent,FooListener,struct FooRelay> {
 public:
        inline void addFooListener(const LPtr& l) { add(l); }
        inline void removeFooListener(const LPtr& l) { remove(l); }
 };
 
 struct FooRelay {
        inline static void forward(FooEvent& e, const FooDispatcher::LPtr& l) { 
                l->processFooEvent(e); 
        }
 };
See the EventDispatcher documentation for details on the forward function.
To avoid overhead, great care should be taken when designing event types. As one inheritance from the EventDispatcher template is necessary for each type of event, very similar actions should be combined in one event class. However, too general events will lead to excessive listener notification. For example, pressing and releasing a mouse button is combined in one event class, while a keystroke would be considered a different event.

Parameters:
Disp the dispatcher class for this event
Author:
Daniel Seibert


Public Member Functions

 Event (Disp *src)
 creates a new event.
Disp * getSource () const
 provides access to the source of the event.
virtual ~Event ()


Constructor & Destructor Documentation

template<class Disp>
ONE::util::Event< Disp >::Event< Disp > Disp *  src  ) 
 

creates a new event.

Parameters:
src the source of the event

template<class Disp>
ONE::util::Event< Disp >::~Event< Disp >  )  [virtual]
 


Member Function Documentation

template<class Disp>
Disp * ONE::util::Event< Disp >::getSource  )  const [inline]
 

provides access to the source of the event.

The source of an event is the EventDispatcher that created and dispatched it.

Returns:
this event's source


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