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

Public Member Functions | |
| ObjectWithCallbacks () | |
| virtual | ~ObjectWithCallbacks () |
| void | addCallback (CallBack *cb) |
| void | addCallback (CallBack *cb, const String &cbName) |
| void | removeCallback (CallBack *cb) |
| CallBack * | getCallback (const String &name) const |
Protected Attributes | |
| std::map< String, CallBack * > * | callbacks_ |
Detailed Description
ObjectWithCallbacks is an object that may have 0 or more CallBacks associated with it, and will automatically clean up these CallBacks when it is destroyed.This simplifies handling who has to clean up a CallBack that may have been allocated on the heap (which they always will be).
Because the collection is a map, a CallBack may be retrieved for future use - that is it may be reused by another delegate. For example:
class Stuff : public ObjectWithCallbacks { public: void onEvent( Event* e ) { } }; int main() { FoundationKit::init(); Stuff stuff; CallBack* ev = new ClassProcedure1<Event*,Stuff>(&stuff,&Stuff::onEvent,"Stuff::onEvent"); FoundationKit::terminate(); return 0; }
This adds the new callback (ev) to the stuff instance. The callback can then be retreived at any time:
void someFunction( Stuff* stuff ) { CallBack* stuffHandler = stuff->getCallback( "Stuff::onEvent" ); //use the stuffHandler somehow... }
Note that the ObjectWithCallbacks should not be created directly. Instead derive a new custom class using this as a base class.
Constructor & Destructor Documentation
|
|
|
|
|
|
Member Function Documentation
|
||||||||||||
|
|
|
|
|
|
|
|
|
|
|
Member Data Documentation
|
|
|
The documentation for this class was generated from the following file:
- vcf/FoundationKit/Delegates.h
