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

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:

VCF::Object VCF::AbstractPropertyEditor VCF::AbstractScrollable::ControlResizeHandler VCF::Component VCF::MenuManager VCF::OSXControl VCF::TableItemEditor VCF::UIToolkit VCF::UndoRedoStack VCF::Win32Object VCF::XMLParser List of all members.

Public Member Functions

 ObjectWithCallbacks ()
virtual ~ObjectWithCallbacks ()
void addCallback (CallBack *cb)
void addCallback (CallBack *cb, const String &cbName)
void removeCallback (CallBack *cb)
CallBackgetCallback (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

VCF::ObjectWithCallbacks::ObjectWithCallbacks  )  [inline]
 

virtual VCF::ObjectWithCallbacks::~ObjectWithCallbacks  )  [virtual]
 


Member Function Documentation

void VCF::ObjectWithCallbacks::addCallback CallBack cb,
const String cbName
 

void VCF::ObjectWithCallbacks::addCallback CallBack cb  ) 
 

CallBack* VCF::ObjectWithCallbacks::getCallback const String name  )  const
 

void VCF::ObjectWithCallbacks::removeCallback CallBack cb  ) 
 


Member Data Documentation

std::map<String,CallBack*>* VCF::ObjectWithCallbacks::callbacks_ [protected]
 


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