Changeset c0332d for molecuilder/src/Patterns/Observer.hpp
- Timestamp:
- Apr 24, 2010, 3:27:00 PM (16 years ago)
- Children:
- 65b413
- Parents:
- 298621
- File:
-
- 1 edited
-
molecuilder/src/Patterns/Observer.hpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/Patterns/Observer.hpp
r298621 rc0332d 29 29 30 30 class Observable; 31 class Notification; 32 33 // Pointers to notifications are used for unique identification 34 // using this typedef makes it hard for others to mess up this 35 // identification process 36 typedef Notification *const Notification_ptr; 31 37 32 38 /** … … 46 52 { 47 53 friend class Observable; 54 friend class Notification; 48 55 public: 49 56 Observer(); … … 55 62 */ 56 63 virtual void update(Observable *publisher)=0; 64 65 /** 66 * This method is called when a special named change 67 * of the Observable occured 68 */ 69 virtual void recieveNotification(Observable *publisher, Notification_ptr notification); 57 70 58 71 /** … … 96 109 97 110 /** 111 * Sign on for specialized notifications 112 */ 113 virtual void signOn(Observer *target, Notification_ptr notification); 114 115 /** 116 * Stop receiving a specialized notification 117 */ 118 virtual void signOff(Observer *target, Notification_ptr notification); 119 120 /** 98 121 * Ask an Observer if it is currently in a blocked state, i.e. if 99 122 * Changes are in Progress, that are not yet published. … … 119 142 static void finish_observer_internal(Observable *publisher); 120 143 144 static void enque_notification_internal(Observable *publisher, Notification_ptr notification); 145 121 146 private: 122 147 typedef std::multimap<int,Observer*> callees_t; 148 typedef std::set<Notification*> notificationSet; 123 149 static std::map<Observable*, int> depth; 124 150 static std::map<Observable*,callees_t*> callTable; 151 static std::map<Observable*,notificationSet> notifications; 125 152 static std::set<Observable*> busyObservables; 153 126 154 127 155 //! @cond … … 143 171 }; 144 172 173 class Notification { 174 friend class Observable; 175 public: 176 Notification(Observable *_owner); 177 virtual ~Notification(); 178 protected: 179 180 void addObserver(Observer *target); 181 void removeObserver(Observer *target); 182 183 void notifyAll(); 184 private: 185 Observable * const owner; 186 std::set<Observer*> targets; 187 }; 188 145 189 // extra macro is necessary to work with __LINE__ 146 190 #define PASTE(a,b) PASTE_HELPER(a,b) 147 191 #define PASTE_HELPER(a,b) a ## b 148 192 #define OBSERVE Observable::_Observable_protector PASTE(_scope_obs_protector_,__LINE__)(this) 149 // deprecated macros from before RAII was used 150 //#define START_OBSERVER Observable::start_observer_internal(this);do{do{}while(0) 151 //#define FINISH_OBSERVER }while(0);Observable::finish_observer_internal(this) 152 //#define RETURN_OBSERVER( retval ) do{Observable::finish_observer_internal(this); return (retval);}while(0) 193 #define NOTIFY(notification) do{Observable::enque_notification_internal(this,notification);}while(0) 194 153 195 #endif /* OBSERVER_HPP_ */
Note:
See TracChangeset
for help on using the changeset viewer.
