VCF::EventHandlerInstance< SOURCE, EVENT > Class Template Reference
The EventHandlerInstance class is used to provide a typesafe wrapper around a specific class's member function pointer. More...
#include <vcf/FoundationKit/EventHandler.h>
Inheritance diagram for VCF::EventHandlerInstance< SOURCE, EVENT >:

Public Types | |
| typedef void(SOURCE::* | OnEventHandlerMethod )(EVENT *e) |
Public Member Functions | |
| EventHandlerInstance (SOURCE *source, OnEventHandlerMethod handlerMethod, const String &handlerName="") | |
| virtual | ~EventHandlerInstance () |
| virtual void | invoke (Event *e) |
| Called during the events dispatch cycle. | |
| virtual Object * | getSource () |
| Returns the source that the event handler is attached to. | |
Protected Attributes | |
| SOURCE * | source_ |
| OnEventHandlerMethod | handlerMethod_ |
Detailed Description
template<class SOURCE, class EVENT>
class VCF::EventHandlerInstance< SOURCE, EVENT >
The EventHandlerInstance class is used to provide a typesafe wrapper around a specific class's member function pointer.
In addition, when the instance is created, if the source passed in is derived from VCF::ObjectWithEvents, then the handler will be maintained in a list by the source, and destroyed when the source is destroyed, freeing the creator of the handler from worrying about memory leaks.
The SOURCE template parameter specified the source class that the event handler method is a member of. The EVENT template parameter is the event class type. The event class type must derive (directly or indirectly) from VCF::Event, and it must be the same event type that is specified in the event handler signature. The basic event handler signature is:
void someMethod( EVENT* event );
class Foo : public Object { public: void onSomeEvent( Event* e ); }; int main() { Foo f; EventHandler* ev = new EventHandlerInstance<Foo,Event>(&f,&Foo::onSomeEvent); return 0; }
In the case above we simply created a new event handler instance that wrap's the Foo::onSomeEvent() method. If we wanted to specify a different type:
class Foo : public Object { public: void onSomeEvent( MouseEvent* e ); }; int main() { Foo f; EventHandler* ev = new EventHandlerInstance<Foo,MouseEvent>(&f,&Foo::onSomeEvent); return 0; }
class Foo : public ObjectWithEvents { public: void onSomeEvent( MouseEvent* e ); }; int main() { Foo f; EventHandler* ev = new EventHandlerInstance<Foo,MouseEvent>(&f,&Foo::onSomeEvent, "Foo::onSomeEvent"); return 0; }
EventHandler* ev = f.getEventHandler( "Foo::onSomeEvent" );
- See also:
- Event
Member Typedef Documentation
|
|||||
|
|
Constructor & Destructor Documentation
|
||||||||||||||||||||
|
|
|
|||||||||
|
|
Member Function Documentation
|
|||||||||
|
Returns the source that the event handler is attached to. Some event handler implementations may not return a source for public use, or may not use one at all, so this method may return NULL. An example of not using a source would be the StaticEventHandlerInstance which is used to wrap static functions. The default implementation returns a NULL object source. Reimplemented from VCF::EventHandler. |
|
||||||||||
|
Called during the events dispatch cycle. The implementation will end up calling the appropriate call back method. Implements VCF::EventHandler. |
Member Data Documentation
|
|||||
|
|
|
|||||
|
|
The documentation for this class was generated from the following file:
- vcf/FoundationKit/EventHandler.h
