/* * EntityObserver.hpp * * Created on: Dec 29, 2015 * Author: heber */ #ifndef ENTITYOBSERVER_HPP_ #define ENTITYOBSERVER_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/Observer/Relay.hpp" /** The EntityObserver is a central instance to all changes occuring within a set entities such as * all atoms or all molecules. * * The intent is that if a class wants to know about changes in just _any_ single entity, * he may register singly to this class and not to each and every one. This also * keeps him updated in case of removed or added entities. * * \warning EntityObserver must get purged \b after World as we do not keep an * an internal list of all entities. Hence, each one must get destroyed while * the EntityObserver instance is still intact or segfault will occur. * * \section howto How to use EntityObserver * * All your template class, here T, needs to do is call Inserted() and Removed() functions * in its cstor and dstor, respectively. * * Make this a singleton and add some static variables (for channels) in a derived class * (derive both the singleton pattern and this template class). * */ template class EntityObserver : public Relay { //!> grant template class access to inserted and removed functions friend T; /** Inform all Observers of this EntityObserver that a new entity has been inserted. * * \param res the inserted entity */ void Inserted(Observable *res); /** Inform all Observers of this EntityObserver that a new entity has been removed. * * \param res the removed entity */ void Removed(Observable *res); protected: /** Constructor for EntityObserver. * * \param _Channels a set of channels for the entity to observe (e.g. all of them) * \param _name name for this for the ObserverLog */ EntityObserver(const Observable::channels_t &_Channels, const std::string &_name); //!> ref to list of channels we observe const Observable::channels_t &EntityChannels; }; #include "EntityObserver_impl.hpp" #endif /* ENTITYOBSERVER_HPP_ */