Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

Listener< EvType > Class Template Reference

Inheritance diagram for Listener< EvType >:

Inheritance graph
[legend]
List of all members.

Public Methods

 Listener ()
 By default, listener not registered.

virtual ~Listener ()
 Automatically deregister ourselves.

void ignoreEvents ()
void listenForEvents ()
void ignoreThisEvent ()
void processEventPublic (const EvType &)
bool isRegistered () const

Protected Methods

virtual void processEvent (const EvType &event)=0

Detailed Description

template<typename EvType>
class Listener< EvType >

Derive your class from a Listener<EvType>, to give it the ability to hear (i.e. receive, listen to) events of type EvType. EvType is a fundamental type (bool, int, float, etc), a struct or a class of your choice. You must define Listener<EvType>::processEvent() in your Listener<EvType> subclass. You call listenForEvents() on your listener instance (at least once) for it to be able to hear (i.e. receive) any EvType event, and you call ignoreEvents() on the instance so it will no longer receive events of type EvType.

Note:

Definition at line 24 of file Listener.hh.


Member Function Documentation

template<typename EvType>
void Listener< EvType >::ignoreEvents  
 

Tell EventSender<EvType> that this listener is not interested in hearing EvType events. This does nothing if already ignoring them.

Definition at line 59 of file Listener.cc.

template<typename EvType>
void Listener< EvType >::ignoreThisEvent  
 

Tell EventSender<EvType> that this listener is ignoring the event received. This will increment a counter in EventSender<EvType>, such that a call to EventSender<EvType>::getNumIgnored() will return how many listeners ignored the event. Note however that the listener is not required to notify EventSender<EvType> that it is ignoring the event, hence this number is only a minimum. This method can be called more than once without screwing up the count. If called from outside a call to Listener<EvType>::processEvent(), nothing is done.

Definition at line 39 of file Listener.cc.

References EventSender< EvType >::isSending().

template<typename EvType>
bool Listener< EvType >::isRegistered   const [inline]
 

Is this instance of listener registered? If not, it will not receive events of type EvType, processEvent() will not be called. To register it, call listenForEvents().

Returns:
true if *this is registered

Definition at line 45 of file Listener.hh.

template<typename EvType>
void Listener< EvType >::listenForEvents  
 

Tell EventSender<EvType> that this listener wants to hear EvType events. This does nothing if already listening to them.

Definition at line 75 of file Listener.cc.

template<typename EvType>
virtual void Listener< EvType >::processEvent const EvType &    event [protected, pure virtual]
 

Classes that inherit from Listener must override this method. This is where you react to the event heard.

Parameters:
event  the event heard.

Referenced by Listener< EvType >::processEventPublic().

template<typename EvType>
void Listener< EvType >::processEventPublic const EvType &    event [inline]
 

Process this event. This public method can be called directly with an event to simulate an event having been generated and heard by this listener. It is also called by EventSender<EvType>::send(). This public method is a "template pattern" method, in that it calls several private methods but most importantly calls the protected, virtual processEvent(). Since the latter is virtual it is the definition in the most derived class of this Listener<EvType> that will get called. The event is passed as const, so listeners can't change the data carried by the event.

Parameters:
event  event to process

Definition at line 101 of file Listener.hh.

References Listener< EvType >::processEvent().


The documentation for this class was generated from the following files:
Generated on Sun Feb 16 16:56:24 2003 for C++ Event Handling Template Library by doxygen1.2.18