/* * EntityObserver_impl.hpp * * Created on: Dec 29, 2015 * Author: heber */ #ifndef ENTITYOBSERVER_IMPL_HPP_ #define ENTITYOBSERVER_IMPL_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include "CodePatterns/Observer/Channels.hpp" /** Private constructor of class EntityObserver. * */ template EntityObserver::EntityObserver( const Observable::channels_t &_Channels, const std::string &_name) : Relay(_name), EntityChannels(_Channels) { Channels *OurChannel = new Channels(); Observable::insertNotificationChannel( std::make_pair(static_cast(this), OurChannel) ); std::for_each(EntityChannels.begin(), EntityChannels.end(), boost::bind(&Channels::addChannel, OurChannel, _1)); } /** Function to call when a new atom has been created. * * @param res */ template void EntityObserver::Inserted(Observable *res) { ASSERT( dynamic_cast(res) != NULL, "EntityObserver::Inserted - type is not derived from Observable."); std::for_each(EntityChannels.begin(), EntityChannels.end(), boost::bind(&Observable::signOn, res, this, _1, GlobalObservableInfo::PriorityDefault)); } /** Function to call when an atom is about to get deleted. * * @param res */ template void EntityObserver::Removed(Observable *res) { std::for_each(EntityChannels.begin(), EntityChannels.end(), boost::bind(&Observable::signOff, res, this, _1)); } #endif /* ENTITYOBSERVER_IMPL_HPP_ */