/* * Graveyard.hpp * * Created on: Sep 5, 2013 * Author: heber */ #ifndef GRAVEYARD_HPP_ #define GRAVEYARD_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include "CodePatterns/Observer/Zombie.hpp" class GraveyardUnitTest; class Observable; /** The Graveyard takes of Observables instances that are about to get * destroyed but where it is necessary that all Observers that are still * signOn()'ed signOff() before the instance actually vanishes. * * For this the Graveyard takes Observable and turns/wraps them into a * Zombie class (that is basically just an Attorney pattern so far) * informing the Observable of a present Graveyard. * * \section graveyard-usage Usage * * The Graveyard is really easy to use. Have an instance that lives * long enough and use * \code * Observable *_obs = new Observable("_obs"); * Graveyard::turnZombies(_obs); * \endcode * in place pf * \code * delete _obs; * \endcode * The instance is fully destroyed as soon as all Observers are signOff()'d * */ class Graveyard { //!> grant unit test access to private parts friend class GraveyardUnitTest; public: Graveyard(); ~Graveyard(); /** This turns an Observable into a Zombie and takes over the ptr. * * \param _observable Observable to take control of */ void turnZombie(Observable *&_observable); private: friend class Observable; /** Function to be called by Observables if Observer's have signOff()ed. * * \param _observable calling Observable */ void ObserverLeft(const Observable *_observable); private: //!> typedef for internal list of zombies typedef std::map graveyard_t; //!> the list of currently active zombies graveyard_t graveyard; //!> static function to inform observer Observable::graveyard_informer_t graveyard_informer; }; #endif /* GRAVEYARD_HPP_ */