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

VCF::Delegate Class Reference

The Delegate class is used to maintain a collection of event handlers and fire events to them. More...

#include <vcf/FoundationKit/Delegate.h>

List of all members.

Public Member Functions

 Delegate ()
 ~Delegate ()
 Delegate (const Delegate &rhs)
Delegateoperator= (const Delegate &rhs)
void addHandler (EventHandler *handler)
 This adds a new event handler to the Delegate.
void removeHandler (EventHandler *handler)
 This removes an event handler from the Delegate.
Delegateoperator+= (EventHandler *handler)
 a shortcut for adding an event handler
Delegateoperator-= (EventHandler *handler)
 a shortcut for removing an event handler
void fireEvent (Event *event)
 This fires an event to all known event handlers in this delegate.
void removeAllHandlers ()
EventHandlergetFirstEventHandler ()
void setFirstEventHandler (EventHandler *handler)
bool getEventHandlers (EventHandler::Vector &handlers)
 This allows you to retreive a copy of the handlers registered with this delegate.

Protected Member Functions

void checkHandlers ()

Protected Attributes

EventHandler::Vectorhandlers_


Detailed Description

The Delegate class is used to maintain a collection of event handlers and fire events to them.

Delegate's have their += and -= operators overloaded as a convenienc methods for adding or removing event handlers.

A Delegate is not meant to be subclassed or derived from. It maintains a pointer to a vector of event handlers, and be default the pointer is null. A new vector will be created the first time a handler is added.


Constructor & Destructor Documentation

VCF::Delegate::Delegate  )  [inline]
 

VCF::Delegate::~Delegate  )  [inline]
 

VCF::Delegate::Delegate const Delegate rhs  )  [inline]
 


Member Function Documentation

void VCF::Delegate::addHandler EventHandler handler  )  [inline]
 

This adds a new event handler to the Delegate.

If this is the first time that a handler has been added to this Delegate the Delgate's vector of event handlers will be created.

Parameters:
EventHandler the new event handler to add. The event handler will only be added if it is not already in the collection of event handlers.

void VCF::Delegate::checkHandlers  )  [inline, protected]
 

void VCF::Delegate::fireEvent Event event  )  [inline]
 

This fires an event to all known event handlers in this delegate.

If an Event is marked as consumed (i.e. the Event's consume(true) is called) then the iteration of handlers will stop and the method will exit, otherwise each handler will have it's invoke() method called once, with the event passed in.

Parameters:
Event the event to pass to each event handler
copy the handlers_ vector so that if a call is made to the delegates setFirstEventHandler, or removeAllHandlers, a crash does not occur due to the (possibly) changed state of the handlers_ vector.

bool VCF::Delegate::getEventHandlers EventHandler::Vector handlers  )  [inline]
 

This allows you to retreive a copy of the handlers registered with this delegate.

Parameters:
EventHandler::Vector a reference to a std::vector<EventHandler*> that will be filled with the event handlers registered with this delegate.
Returns:
bool returns true if the handlers were successfully copied over. Otherwise returns false. A delegate with no handlers will also return false.

EventHandler* VCF::Delegate::getFirstEventHandler  )  [inline]
 

Delegate& VCF::Delegate::operator+= EventHandler handler  )  [inline]
 

a shortcut for adding an event handler

Delegate& VCF::Delegate::operator-= EventHandler handler  )  [inline]
 

a shortcut for removing an event handler

Delegate& VCF::Delegate::operator= const Delegate rhs  )  [inline]
 

void VCF::Delegate::removeAllHandlers  )  [inline]
 

void VCF::Delegate::removeHandler EventHandler handler  )  [inline]
 

This removes an event handler from the Delegate.

Parameters:
EventHandler the event handler to remove

void VCF::Delegate::setFirstEventHandler EventHandler handler  )  [inline]
 


Member Data Documentation

EventHandler::Vector* VCF::Delegate::handlers_ [protected]
 


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