VCF::ObjectWithEvents Class Reference
ObjectWithEvents is an object that may have 0 or more EventHandlers associated with it, and will automatically clean up these EventHandlers when it is destroyed. More...
#include <vcf/FoundationKit/ObjectWithEvents.h>
Inheritance diagram for VCF::ObjectWithEvents:

Public Member Functions | |
| ObjectWithEvents () | |
| virtual | ~ObjectWithEvents () |
| void | addEventHandler (const String &handlerName, EventHandler *handler) |
| This is a utility method for adding event handlers to an object. | |
| EventHandler * | getEventHandler (const String &handlerName) |
| Finds a EventHandler handler for a given name. | |
| String | getEventHandlerName (EventHandler *handler) |
Public Attributes | |
| VCF::Delegate | Notified |
Protected Attributes | |
| std::map< String, EventHandler * > | eventHandlers_ |
| This map holds a list of EventHandlers that have been added to the object. | |
Detailed Description
ObjectWithEvents is an object that may have 0 or more EventHandlers associated with it, and will automatically clean up these EventHandlers when it is destroyed.This simplifies handling who has to clean up EventHandlers that have been allocated on the heap (which they always will be).
Because the collection is a map, an event handler may be retreived for future use - that is it may be reused by another delegate. For example:
class Stuff : public ObjectWithEvents { public: void onEvent( Event* e ) { } }; int main() { FoundationKit::init(); Stuff stuff; EventHandler* ev = new GenericEventHandler<Stuff>(&stuff,&Stuff::onEvent,"Stuff::onEvent"); FoundationKit::terminate(); return 0; }
This adds the new event handler (ev) to the stuff instance. This event handler can then be retreived at any time:
void someFunction( Stuff* stuff ) { EventHandler* stuffHandler = stuff->getEventHandler( "Stuff::onEvent" ); //use the stuffHandler somehow... }
Note that the ObjectWithEvents should not be created directly. Instead derive a new custom class using this as a base class.
- Event Delegates for this class:
Constructor & Destructor Documentation
|
|
|
|
|
|
Member Function Documentation
|
||||||||||||
|
This is a utility method for adding event handlers to an object. Adding a handler provides a convenient way to store the various events an object may wish to listen to. Handlers still need to have their method callbacks set, otherwise nothing will happen. When the object is destroyed all the event handlers in this list are also destroyed. |
|
|
Finds a EventHandler handler for a given name. If the object has that handler then a pointer to the is returned otherwise null is returned |
|
|
|
Member Data Documentation
|
|
This map holds a list of EventHandlers that have been added to the object.
Reimplemented in VCF::Win32HTMLBrowser. |
|
|
|
The documentation for this class was generated from the following file:
- vcf/FoundationKit/ObjectWithEvents.h
