#include <Notifier.h>
Collaboration diagram for TSE3::Listener< interface_type >:
Public Types | |
typedef Notifier< interface_type > | notifier_type |
Public Member Functions | |
void | attachTo (notifier_type *notifier) |
void | detachFrom (notifier_type *notifier) |
Protected Types | |
typedef interface_type::notifier_type | c_notifier_type |
Protected Member Functions | |
Listener () | |
virtual void | Notifier_Deleted (c_notifier_type *) |
virtual | ~Listener () |
Friends | |
class | notifier_type |
The Listener class receives events sent from a Notifier class.
Listener inherits from the specified interface_type
so you don't need to mupltiply inherit from both Listener the interface_type
in your derived class.
To instatiate the Listener class inherit from Listener<NotifierType>. Following the example in the Notifier documentation, this would be:
class Voyeur : public Listener<ExhibtionistListener> { public: virtual void eventOne(Exhibitionist *src) { ... } virtual void eventTwo(Exhibitionist *src, int a) { ... } virtual void Notifier_Deleted(Exhibitionist *src) { // The 'src' is being deleted - you do not need to // detach from it, the link is automatically broken.
// This method is not defined in the // ExhibitionistListener base class, but is defined by // the Listener<ExhibitionistListener> class. You // don't have to implement it if you don't need it. } };Upon deletion, the Listener class ensures that it is detached from every Notifier it has been attached to. This prevents a Notifier later trying to callback to an invalid object.
|
The type of Notifier class this listener works with. |
|
The concrete Notifier type (i.e. the class that derives from Notifier<interface_type>. |
|
Creates a new Listener which is not attached to any Notifier. Use attachTo to attach to . You can only subclass this type, not instanitate it directly. |
|
The destructor ensures that the Listener is detached from every Notifier it has been attached to. This means that you don't have to specifically detach from all Notifier sources yourself, although it is still considered good practice to do so. |
|
Attaches this Listener to You can only attach to a object once - any subsequent attempt to attach to it results in nothing happening; it is not an error, but the Listener will still only ever receive one copy of any event.
|
|
Detaches this Listener from If the listener is not already attached to this Notifier no error is raised.
|
|
This may be implemented by Listener classes if they care about a Notifier object being deleted.
It is called by the destructor - so the You do not need to detachFrom the the Notifier since the link is automatically broken for you.
|
|
|