OpenGUI::EventDelegate Class Reference

#include <OpenGUI_EventHandler.h>

Inheritance diagram for OpenGUI::EventDelegate:

OpenGUI::EventHandler List of all members.

Detailed Description

Self destroying multi-purpose event delegate.

This delegate class is capable of binding to either C-style function pointers or object specific member function pointers. It performs the smoke and magic through an abstract interface class system, and the use of a very light template in the specific case of member function callbacks.


Public Member Functions

 EventDelegate (EventCallbackFunc *C_funcPtr)
 Create the delegate from a C function pointer.
template<class CLASS, class ARGS_TYPE>
 EventDelegate (CLASS *classObjPtr, void(CLASS::*memberFunc)(Object *, ARGS_TYPE &))
 Create the delegate from an object bound member function pointer.
virtual void onEvent (Object *sender, EventArgs &args)
 Calls the function/member given at EventDelegate creation on event trigger.
virtual void onEventDestruction ()
 Automatically deletes self on event destruction.


Constructor & Destructor Documentation

OpenGUI::EventDelegate::EventDelegate ( EventCallbackFunc *  C_funcPtr  )  [inline]

Create the delegate from a C function pointer.

Example usage:
Assume obj is a pointer to a valid Object, and desiredEvent is a valid event for that Object.
                obj->getEvents()["desiredEvent"].add( new EventDelegate(&myCallback) );

template<class CLASS, class ARGS_TYPE>
OpenGUI::EventDelegate::EventDelegate ( CLASS *  classObjPtr,
void(CLASS::*)(Object *, ARGS_TYPE &)  memberFunc 
) [inline]

Create the delegate from an object bound member function pointer.

Example usage:
First we'll define an example class with a member function capable of receiving the event.
                class MyClass{
                public:
                        void myMethod( Object* sender, EventArgs& args ){
                                //do something important
                        }
                };
And now an example of binding an object of the example class and its method to an event. Assume obj is a pointer to a valid Object, desiredEvent is a valid event for that Object, and myClassObj is a valid pointer to an instance of MyClass.
                obj->getEvents()["desiredEvent"].add( new EventDelegate(myClassObj, &MyClass::myMethod) );
Note:
In the first code area, the sender is a pointer to the Object that is experiencing the event, and args is a reference to the appropriate EventArgs derived class. You can use either EventArgs specifically, and cast it yourself later, or you can use the specific EventArgs derived class for the particular event you plan on receiving. If you try to send an event to a handler that tries to cast args to the wrong type, it will compile fine but will suffer a run time exception because of a bad reference cast when the event is invoked. The sender is sent because you may be binding the same event across several different instances of Widgets, and in that case a pointer back to the Widget that is experiencing the event is most useful.


Member Function Documentation

virtual void OpenGUI::EventDelegate::onEvent ( Object sender,
EventArgs args 
) [inline, virtual]

Calls the function/member given at EventDelegate creation on event trigger.

Implements OpenGUI::EventHandler.

virtual void OpenGUI::EventDelegate::onEventDestruction (  )  [inline, virtual]

Automatically deletes self on event destruction.

This is so that you do not need to retain a pointer to it. In fact, you probably shouldn't.

Reimplemented from OpenGUI::EventHandler.


The documentation for this class was generated from the following file:
Copyright © 2006 OpenGUI | OpenGUI.SF.net
Generated: Fri Jan 5 23:05:25 2007