iCub-main
Public Member Functions | Static Public Member Functions | List of all members
iCub::learningmachine::EventDispatcher Class Reference

The EventDispatcher manages the relation between the various instances of IEventListeners and IEvents. More...

#include <EventDispatcher.h>

Public Member Functions

virtual void addListener (IEventListener *listener)
 Adds an IEventListener to the list. More...
 
virtual void removeListener (int idx)
 Removes an IEventListener from the list. More...
 
virtual void removeListener (IEventListener *listener)
 Removes an IEventListener from the list. More...
 
virtual IEventListenergetAt (int idx)
 Returns the IEventListener at a specified index. More...
 
virtual IEventListenergetAt (int idx) const
 Returns the IEventListener at a specified index. More...
 
virtual void clear ()
 Clears all the IEventListeners from the EventDispatcher. More...
 
virtual void raise (IEvent &event)
 Raises an IEvent, causing it to be dispatched to each registered IEventListener. More...
 
virtual int countListeners () const
 Counts the number of registered listeners. More...
 
virtual bool hasListeners ()
 Tells whether there are listeners for events. More...
 

Static Public Member Functions

static EventDispatcherinstance ()
 An instance retrieval method that follows the Singleton pattern. More...
 

Detailed Description

The EventDispatcher manages the relation between the various instances of IEventListeners and IEvents.

It allows IEvents to get raised and dispatches these to the registered IEventListeners. Internally, the EventDispatcher uses a double dispatching mechanism that allows extension of both IEventListeners and IEvents.

See also
iCub::learningmachine::IEventListener
iCub::learningmachine::IEvent
Author
Arjan Gijsberts

Definition at line 44 of file EventDispatcher.h.

Member Function Documentation

◆ addListener()

virtual void iCub::learningmachine::EventDispatcher::addListener ( IEventListener listener)
inlinevirtual

Adds an IEventListener to the list.

Note that the EventDispatcher takes over responsibility of the pointer and its deconstruction.

Parameters
listenerThe IEventListener that is to be add.

Definition at line 93 of file EventDispatcher.h.

◆ clear()

void iCub::learningmachine::EventDispatcher::clear ( )
virtual

Clears all the IEventListeners from the EventDispatcher.

Definition at line 76 of file EventDispatcher.cpp.

◆ countListeners()

virtual int iCub::learningmachine::EventDispatcher::countListeners ( ) const
inlinevirtual

Counts the number of registered listeners.

Returns
the number of registered listeners

Definition at line 144 of file EventDispatcher.h.

◆ getAt() [1/2]

IEventListener & iCub::learningmachine::EventDispatcher::getAt ( int  idx)
virtual

Returns the IEventListener at a specified index.

Returns
the IEventListener
Parameters
idxThe index of the IEventListener.

Definition at line 64 of file EventDispatcher.cpp.

◆ getAt() [2/2]

IEventListener & iCub::learningmachine::EventDispatcher::getAt ( int  idx) const
virtual

Returns the IEventListener at a specified index.

Returns
the IEventListener
Parameters
idxThe index of the IEventListener.

Definition at line 70 of file EventDispatcher.cpp.

◆ hasListeners()

virtual bool iCub::learningmachine::EventDispatcher::hasListeners ( )
inlinevirtual

Tells whether there are listeners for events.

Returns
true if there are one of more registered IEventListeners.

Definition at line 153 of file EventDispatcher.h.

◆ instance()

static EventDispatcher& iCub::learningmachine::EventDispatcher::instance ( )
inlinestatic

An instance retrieval method that follows the Singleton pattern.

Note that this implementation should not be considered thread safe and that problems may arise. However, due to the nature of the expected use this will not be likely to result in problems.

See http://www.oaklib.org/docs/oak/singleton.html for more information.

Returns
the singleton factory instance

Definition at line 83 of file EventDispatcher.h.

◆ raise()

void iCub::learningmachine::EventDispatcher::raise ( IEvent event)
virtual

Raises an IEvent, causing it to be dispatched to each registered IEventListener.

Note that a double dispatching mechanism is used to determine the proper runtime types of both the IEvent and the IEventListener using dynamic binding.

Parameters
eventThe IEvent instance that is to be raised.

Definition at line 83 of file EventDispatcher.cpp.

◆ removeListener() [1/2]

void iCub::learningmachine::EventDispatcher::removeListener ( IEventListener listener)
virtual

Removes an IEventListener from the list.

This does not delete the object itself. As the caller has access to the pointer, it can take responsibility for the proper destruction of the object.

Parameters
listenerThe IEventListener instance that is to be removed.

Definition at line 59 of file EventDispatcher.cpp.

◆ removeListener() [2/2]

void iCub::learningmachine::EventDispatcher::removeListener ( int  idx)
virtual

Removes an IEventListener from the list.

Parameters
idxThe index of the IEventListener that is to be removed.

Definition at line 51 of file EventDispatcher.cpp.


The documentation for this class was generated from the following files: