CFugue
|
#include <EventHandler.h>
Public Member Functions | |
template<typename TEventReceiver > | |
void | Subscribe (TEventReceiver *pReceiver, void(TEventReceiver::*lpfnHandler)(TEventSource *, TEventHandlerArgs *)) |
void | Subscribe (void(*lpfnHandler)(TEventSource *, TEventHandlerArgs *)) |
void | UnSubscribe (void(*lpfnHandler)(TEventSource *, TEventHandlerArgs *)) |
template<typename TReceiverClass > | |
void | UnSubscribe (TReceiverClass *pReceiver) |
void | UnSubscribeAll () |
size_t | SubscriberCount () const |
Friends | |
class | CEventSource |
A Receiver can Subscribe for an Event only once. If a Receiver requests a second subscription for the same Event, its previous subscription would be replaced with the new subscription.
A Receiver can subscribe for as many different events as it wants. But for each, only once.
And an Event can have as many Receivers as it likes.
CEventT take template arguments that indicate the prototype of the handler proc that should used to subscribe to that event. By default, CEvent uses the handlers of the form
You can use different prototypes by simply defining the sender and handler args in the template definition for CEventT.
For example, CEventT<Sender, HandlerArgs> expects its subscriber functions to be of the form
Following Snippet demonstrates sample usage.
Summary> Default form of CEventT that uses
as the Event handler procedure /Summary>
Definition at line 133 of file EventHandler.h.
void OIL::CEventT< TEventSource, TEventHandlerArgs >::Subscribe | ( | TEventReceiver * | pReceiver, |
void(TEventReceiver::*)(TEventSource *, TEventHandlerArgs *) | lpfnHandler | ||
) |
Creates an IEventFunctor object for the given function and subcribes it to be called upon the given object whenever the event is raised. Duplicates or Multiple Subscriptions are not allowed. If the Receiver object already has a subscription for this event, the old subscription is removed before adding the new subcription.
Definition at line 224 of file EventHandler.h.
void OIL::CEventT< TEventSource, TEventHandlerArgs >::Subscribe | ( | void(*)(TEventSource *, TEventHandlerArgs *) | lpfnHandler | ) |
Subscribes the given Function to be called whenever the event is raised. Duplicates are not Allowed. If the given Function is already a subscriber, it would not be added again.
Definition at line 236 of file EventHandler.h.
size_t OIL::CEventT< TEventSource, TEventHandlerArgs >::SubscriberCount | ( | ) | const |
Gives the number of active Subcriptions for this event. It includes the Class-based Subscriptions as well the Function-based ones.
Definition at line 281 of file EventHandler.h.
void OIL::CEventT< TEventSource, TEventHandlerArgs >::UnSubscribe | ( | void(*)(TEventSource *, TEventHandlerArgs *) | lpfnHandler | ) |
UnSubscribes the given Function from being called. Nothing Happens if the given Function is not a Subscriber.
Definition at line 248 of file EventHandler.h.
void OIL::CEventT< TEventSource, TEventHandlerArgs >::UnSubscribe | ( | TReceiverClass * | pReceiver | ) |
UnSubscribes the pReceiver from the Subscription. Nothing Happens if the supplied pReceiver object is not a Subscriber.
Definition at line 261 of file EventHandler.h.
void OIL::CEventT< TEventSource, TEventHandlerArgs >::UnSubscribeAll | ( | ) |
UnSubscribes all receivers. SubscriberCount() would become Zero.
Definition at line 269 of file EventHandler.h.
CFugue, the C++ Music Programming Library | © Copyright 2009 Cenacle Research India Private Limited | Gopalakrishna Palem |