Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

TSE3::Notifier< interface_type > Class Template Reference

Base class for objects that multicast events to listeners. More...

#include <Notifier.h>

Collaboration diagram for TSE3::Notifier< interface_type >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef Listener< interface_type > listener_type

Protected Types

typedef interface_type::notifier_type c_notifier_type

Protected Member Functions

 Notifier ()
template<typename func_type> void notify (func_type func)
template<typename func_type, typename p1_type> void notify (func_type func, const p1_type &p1)
template<typename func_type, typename p1_type, typename p2_type> void notify (func_type func, const p1_type &p1, const p2_type &p2)
template<typename func_type, typename p1_type, typename p2_type, typename p3_type> void notify (func_type func, const p1_type &p1, const p2_type &p2, const p3_type &p3)
virtual ~Notifier ()
unsigned int numListeners () const

Friends

class listener_type

Detailed Description

template<class interface_type>
class TSE3::Notifier< interface_type >

Base class for objects that multicast events to listeners.

The Notifier template base class is an implementation of the observer design pattern (GoF book).

Objects that need to send out specific callback events derive from this base class. Each Notifier class may have any number of callback events, and each of these events may take any number (and type) of parameters. The callback system is type safe and easy to use.

Events sent from the Notifier class are received by objects of the Listener class.

Usage
A separate interface class detailing each callback event and the type of Notifier source class must be written, for example:
class Exhibitionist;

class ExhibitionistListener { public: typedef Exhibitionist notifier_type;

virtual void eventOne(Exhibitionist *) = 0; virtual void eventTwo(Exhibitionist *, int a) = 0; };
The first parameter of callback events must always be a pointer to the source object.

You may choose to provide a default implementation for the callback methods. This will save you having to reimplement every callback, only the ones for the events you are interested in.

You can now declare a Notifier class thus:

class Exhibitionist : public Notifier<ExhibtionistListener> { // Other contents.... };
and implement your functionality.

The Exhibitionist class can send callbacks to any attached listener by calling the notify member function. For example:

notify(&ExhibitionistListener::eventTwo, 1);
The source object pointer parameter is automatically provided and does not need to be specified.

To receive events from a Notifier class, you must write a class that derives from Listener. The documentation for Listener describes how to do this.

Author:
Pete Goodliffe
Version:
3.00
See also:
Listener


Member Typedef Documentation

template<class interface_type>
typedef Listener<interface_type> TSE3::Notifier< interface_type >::listener_type
 

The type of Listener that this Notifier class works with.

template<class interface_type>
typedef interface_type::notifier_type TSE3::Notifier< interface_type >::c_notifier_type [protected]
 

The concrete Notifier type (i.e. the class that will be subclassing Notifier<interface_type>.


Constructor & Destructor Documentation

template<class interface_type>
TSE3::Notifier< interface_type >::Notifier  )  [inline, protected]
 

Creates a Notifier with no listeners.

Use Listener::attachTo to add listeners.

You can only subclass this type, not instanitate it directly.

template<class interface_type>
virtual TSE3::Notifier< interface_type >::~Notifier  )  [inline, protected, virtual]
 

The dtor tells every attached Listener that this object is being deleted.


Member Function Documentation

template<class interface_type>
template<typename func_type>
void TSE3::Notifier< interface_type >::notify func_type  func  )  [inline, protected]
 

There is a family of notify functions. The allow a Notifier to multicast an event to every attached Listener object.

They are overloaded on the different number of parameters each listener event function takes.

You call a notify method specifying first the member function of the interface_type to call, and then the parameters to call it with.

Every listener function has a first parameter which is a pointer to this (source) object. This is automatically provided by the notify function, so you need not supply it. If a funciton takes any extra parameters then you must specify them.

The first notify function is for events with no extra parameters.

template<class interface_type>
template<typename func_type, typename p1_type>
void TSE3::Notifier< interface_type >::notify func_type  func,
const p1_type &  p1
[inline, protected]
 

Notify function for events with one extra parameter.

template<class interface_type>
template<typename func_type, typename p1_type, typename p2_type>
void TSE3::Notifier< interface_type >::notify func_type  func,
const p1_type &  p1,
const p2_type &  p2
[inline, protected]
 

Notify function for events with two extra parameters.

template<class interface_type>
template<typename func_type, typename p1_type, typename p2_type, typename p3_type>
void TSE3::Notifier< interface_type >::notify func_type  func,
const p1_type &  p1,
const p2_type &  p2,
const p3_type &  p3
[inline, protected]
 

Notify function for events with three extra parameters.

template<class interface_type>
unsigned int TSE3::Notifier< interface_type >::numListeners  )  const [inline, protected]
 


Friends And Related Function Documentation

template<class interface_type>
friend class listener_type [friend]
 


The documentation for this class was generated from the following file:
Generated on Wed May 25 14:46:41 2005 for TSE3 by doxygen 1.3.2