Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/Observer.hpp

    r033a05 rcd5047  
    1111#include <map>
    1212#include <set>
     13#include <string>
     14#include <sstream>
    1315
    1416/**
     
    2830 */
    2931
     32// Deactivate any logging when we are not in debug mode
     33#ifdef NDEBUG
     34#undef LOG_OBSERVER
     35#endif
     36
    3037class Observable;
    3138class Notification;
     
    3542// identification process
    3643typedef Notification *const Notification_ptr;
     44
     45template<class _Set>
     46class ObservedIterator;
    3747
    3848/**
     
    5363  friend class Observable;
    5464  friend class Notification;
    55 public:
    56   Observer();
     65  template<class> friend class ObservedIterator;
     66
     67  // indicates the constructor called from Observables
     68  struct BaseConstructor{};
     69
     70public:
     71  Observer(BaseConstructor);
     72  Observer(std::string);
    5773  virtual ~Observer();
    5874
     
    86102class Observable : public Observer {
    87103public:
    88   Observable();
     104  Observable(std::string _name);
    89105  virtual ~Observable();
    90106
     
    152168  static std::set<Observable*> busyObservables;
    153169
    154 
    155170  //! @cond
    156171  // Structure for RAII-Style notification
     
    164179  public:
    165180    _Observable_protector(Observable *);
     181    _Observable_protector(const _Observable_protector&);
    166182    ~_Observable_protector();
    167183  private:
     
    187203};
    188204
     205#ifdef LOG_OBSERVER
     206
     207/**
     208 * This class is used to log the working of the observer mechanism
     209 *
     210 * TODO: make this conditional dependent on compiler Flag.
     211 */
     212class ObserverLog{
     213  friend class Observable;
     214  friend class Observer;
     215  template <typename> friend class Cacheable;
     216public:
     217  ObserverLog();
     218  ~ObserverLog();
     219  std::string getLog();                        // get everything that has been logged
     220  std::string getName(void*);                  // get the name of an actor
     221  bool isObservable(void*);
     222private:
     223  int count;                                   // number to reference each actor in this framework
     224  std::map<void*,std::string> names;           // List of names assigned to actors
     225  std::set<void*> observables;                 // List of pointers to Observables. Needed to distinguish Observers and Observables
     226  void addName(void*, std::string);            // Assign a name to an Actor
     227  void addObservable(void*);
     228  void deleteName(void*);                      // delete the name of an Actor
     229  void deleteObservable(void*);
     230  std::stringstream &addMessage(int depth=0);  // Add a Message to the logging
     231  std::stringstream log;                       // The internal log object
     232};
     233
     234ObserverLog &observerLog();
     235
     236#endif
     237
    189238// extra macro is necessary to work with __LINE__
    190239#define PASTE(a,b) PASTE_HELPER(a,b)
Note: See TracChangeset for help on using the changeset viewer.