class Notifier

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

Full nameTSE3::Notifier
Definition#include <Notifier.h>
Template formNotifier<class interface_type>
Inherited byDisplayParams, EventTrack, EventTrack, FlagTrack, FlagTrack, KeySigTrack, KeySigTrack, Metronome, Metronome, MidiCommandFilter, MidiData, MidiData, MidiEcho, MidiFileImport, MidiFileImport, MidiFilter, MidiMapper, MidiParams, MidiParams, MidiScheduler, Mixer, MixerChannel, MixerPort, Panic, Panic, Part, Part, Phrase, Phrase, Phrase, PhraseEdit, PhraseEdit, PhraseEdit, PhraseList, Playable, PresetColours, RepeatTrack, RepeatTrack, Song, Song, TempoTrack, TempoTrack, TimeSigTrack, TimeSigTrack, Track, Track, Transport
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Types

Public Members

Protected Types

Protected Methods


Detailed Description

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
     {
         // 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.

See also: Listener

typedef Listener listener_type

listener_type

The type of Listener that this Notifier class works with.

friend class listener_type

listener_type

 Notifier ()

Notifier

[protected]

Creates a Notifier with no listeners.

Use Listener::attachTo to add listeners.

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

typedef interface_type::notifier_type c_notifier_type

c_notifier_type

[protected]

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

template void  notify (func_type func)

notify

[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 void  notify (func_type func, const p1_type &p1)

notify

[protected]

Notify function for events with one extra parameter.

template void  notify (func_type func, const p1_type &p1, const p2_type &p2)

notify

[protected]

Notify function for events with two extra parameters.

template void  notify (func_type func, const p1_type &p1, const p2_type &p2, const p3_type &p3)

notify

[protected]

Notify function for events with three extra parameters.

 ~Notifier ()

~Notifier

[protected virtual]

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

unsigned int  numListeners ()

numListeners

[protected const]