cgma
|
#include <CubitEventDispatcher.hpp>
Public Member Functions | |
CubitEventDispatcher () | |
virtual | ~CubitEventDispatcher () |
void | send_event (CubitObservable *observable, const CubitEvent &event) |
void | add_observer (CubitObserver *obs) |
Add an observer. | |
void | remove_observer (CubitObserver *obs) |
Remove an observer. | |
Protected Attributes | |
std::vector< CubitObserver * > | mObservers |
An event dispatcher class to handle sending events to observers. A CubitObserver may register with this class to receive events.
Definition at line 13 of file CubitEventDispatcher.hpp.
Definition at line 7 of file CubitEventDispatcher.cpp.
{ }
CubitEventDispatcher::~CubitEventDispatcher | ( | ) | [virtual] |
Definition at line 11 of file CubitEventDispatcher.cpp.
{ }
void CubitEventDispatcher::add_observer | ( | CubitObserver * | obs | ) |
Add an observer.
Definition at line 29 of file CubitEventDispatcher.cpp.
{ std::vector<CubitObserver*>::iterator iter; iter = std::find(mObservers.begin(), mObservers.end(), obs); if(iter == mObservers.end()) { mObservers.push_back(obs); } }
void CubitEventDispatcher::remove_observer | ( | CubitObserver * | obs | ) |
Remove an observer.
Definition at line 39 of file CubitEventDispatcher.cpp.
{ mObservers.erase( std::remove(mObservers.begin(), mObservers.end(), obs), mObservers.end() ); }
void CubitEventDispatcher::send_event | ( | CubitObservable * | observable, |
const CubitEvent & | event | ||
) |
Send an event to observers. The event is sent two ways: 1. If an observable is given, the event is sent to the observers directly observing that entity. 2. The event is sent to all observers added to this dispatcher. Ownership of the event is taken by this object.
Definition at line 15 of file CubitEventDispatcher.cpp.
{ if(observable) { observable->notify_observers(&event); } std::vector<CubitObserver*>::iterator iter; for(iter = mObservers.begin(); iter != mObservers.end(); ++iter) { (*iter)->notify_observer(&event); } }
std::vector<CubitObserver*> CubitEventDispatcher::mObservers [protected] |
Definition at line 33 of file CubitEventDispatcher.hpp.