Changeset bc1fbf for molecuilder/src/Patterns
- Timestamp:
- Feb 3, 2010, 4:31:45 PM (16 years ago)
- Children:
- 8501eb
- Parents:
- 2e8296
- Location:
- molecuilder/src/Patterns
- Files:
-
- 2 edited
-
Observer.cpp (modified) (1 diff)
-
Observer.hpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/Patterns/Observer.cpp
r2e8296 rbc1fbf 51 51 depth.erase(publisher); 52 52 } 53 } 54 55 Observable::_Observable_protector::_Observable_protector(Observable *_protege) : 56 protege(_protege) 57 { 58 start_observer_internal(protege); 59 } 60 61 Observable::_Observable_protector::~_Observable_protector() 62 { 63 finish_observer_internal(protege); 53 64 } 54 65 -
molecuilder/src/Patterns/Observer.hpp
r2e8296 rbc1fbf 16 16 * 17 17 * Observers register themselves with the observables to be notified when something changes. 18 * In the Observable code that changes attributes should be wrapped in 19 * START_OBSERVER ... END_OBSERVER blocks. If other methods are called that also contain 20 * Observation blocks from there, these functions wont trigger notifications. Only the end 21 * of the final observation block triggers the update of Observers. 22 * 23 * Returning from observed code should be done using the RETURN_OBSERVER() macro. This way the Observer mechanism 24 * is notified that the method is left. 18 * In the Observable code that changes attributes should be started with OBSERVE;. This macro 19 * locks the observer mechanism while changes are done. At the end of the scope in which the 20 * macro was placed the lock is released. When the last lock is released all changes are 21 * propagated to the observers. 25 22 * 26 23 * Each observerable can have sub-observables. When one of these sub-observables changes and … … 62 59 /** 63 60 * Internal method. 64 * Do not call directly. Use START_OBSERVERmacro instead61 * Do not call directly. Use OBSERVE macro instead 65 62 */ 66 63 static void start_observer_internal(Observable *publisher); 67 64 /** 68 65 * Internal method. 69 * Do not call directly. Use FINISH_OBSERVERmacro instead66 * Do not call directly. Use OBSERVE macro instead 70 67 */ 71 68 static void finish_observer_internal(Observable *publisher); … … 76 73 static std::map<Observable*,callees_t*> callTable; 77 74 static std::set<Observable*> busyObservables; 75 76 // Structure for RAII-Style notification 77 protected: 78 class _Observable_protector { 79 public: 80 _Observable_protector(Observable *); 81 ~_Observable_protector(); 82 private: 83 Observable *protege; 84 }; 78 85 }; 79 86 80 87 81 88 #define OBSERVE Observable::_Observable_protector _scope_obs_protector(this) 82 89 #define START_OBSERVER Observable::start_observer_internal(this);do{do{}while(0) 83 90 #define FINISH_OBSERVER }while(0);Observable::finish_observer_internal(this)
Note:
See TracChangeset
for help on using the changeset viewer.
