Sourceforge.net - The VCF's Project Host
   The VCF Website Home   |   Online Discussion Forums   |   Sourceforge.net Project Page   

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:

VCF::Object VCF::AbstractApplication VCF::AbstractPropertyEditor VCF::AbstractScrollable::ControlResizeHandler VCF::Component VCF::MenuManager VCF::OSXControl VCF::TableItemEditor VCF::UIToolkit VCF::UndoRedoStack VCF::Win32Object VCF::XMLParser VCFRemote::AbstractDistributedApplication::DistributedAppListener VCFRemote::ClassServerInstance List of all members.

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.
EventHandlergetEventHandler (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

VCF::ObjectWithEvents::ObjectWithEvents  ) 
 

virtual VCF::ObjectWithEvents::~ObjectWithEvents  )  [virtual]
 


Member Function Documentation

void VCF::ObjectWithEvents::addEventHandler const String handlerName,
EventHandler handler
 

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.

EventHandler* VCF::ObjectWithEvents::getEventHandler const String handlerName  ) 
 

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

String VCF::ObjectWithEvents::getEventHandlerName EventHandler handler  ) 
 


Member Data Documentation

std::map<String,EventHandler*> VCF::ObjectWithEvents::eventHandlers_ [protected]
 

This map holds a list of EventHandlers that have been added to the object.

Reimplemented in VCF::Win32HTMLBrowser.

VCF::Delegate VCF::ObjectWithEvents::Notified
 

Event Delegate:
Notifier events are used as a generic signal mechanism and can signify anything that takes place to the ObjectWithEvents instance.
event class: NotifyEvent


The documentation for this class was generated from the following file:
   Comments or Suggestions?    License Information