cgma
CubitEventDispatcher Class Reference

#include <CubitEventDispatcher.hpp>

List of all members.

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

Detailed Description

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.


Constructor & Destructor Documentation

Definition at line 11 of file CubitEventDispatcher.cpp.

{
}

Member Function Documentation

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);
  }
}

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);
  }
}

Member Data Documentation

Definition at line 33 of file CubitEventDispatcher.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines