#include "CubitEventDispatcher.hpp"<--- Skipping configuration 'DBL_MAX' since the value of 'DBL_MAX' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'DBL_MIN' since the value of 'DBL_MIN' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'M_PI' since the value of 'M_PI' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
#include "CubitObserver.hpp"
#include "CubitObservable.hpp"
#include <algorithm>
CubitEventDispatcher::CubitEventDispatcher()
{
}
CubitEventDispatcher::~CubitEventDispatcher()
{
}
void CubitEventDispatcher::send_event(CubitObservable* observable, const CubitEvent& event)
{
if(observable)
{
observable->notify_observers(&event);
}
std::vector<CubitObserver*>::iterator iter;
for(iter = mObservers.begin(); iter != mObservers.end(); ++iter)
{
(*iter)->notify_observer(&event);
}
}
void CubitEventDispatcher::add_observer(CubitObserver* obs)
{
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)
{
mObservers.erase(
std::remove(mObservers.begin(), mObservers.end(), obs),
mObservers.end()
);
}