Changeset 9e776f
- Timestamp:
- Sep 1, 2011, 1:51:25 PM (14 years ago)
- Children:
- d45509
- Parents:
- 74e0f7
- Location:
- src/Patterns
- Files:
-
- 2 edited
-
Observer.cpp (modified) (5 diffs)
-
Observer.hpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Observer.cpp
r74e0f7 r9e776f 211 211 * \param priority number in [-20,20] 212 212 */ 213 void Observable::signOn(Observer *target,int priority) { 213 void Observable::signOn(Observer *target,int priority) const 214 { 214 215 ASSERT(priority>=-20 && priority<=+20, "Priority out of range [-20:+20] when signing on Observer"); 215 216 #ifdef LOG_OBSERVER 216 observerLog().addMessage() << "@@ Signing on " << observerLog().getName(target) << " to " << observerLog().getName( this) << endl;217 observerLog().addMessage() << "@@ Signing on " << observerLog().getName(target) << " to " << observerLog().getName(const_cast<Observable *>(this)) << endl; 217 218 #endif 218 219 bool res = false; 219 callees_t &callees = callTable[ this];220 callees_t &callees = callTable[const_cast<Observable *>(this)]; 220 221 221 222 callees_t::iterator iter; … … 231 232 * \param *target Observer 232 233 */ 233 void Observable::signOff(Observer *target) { 234 ASSERT(callTable.count(this),"SignOff called for an Observable without Observers."); 235 #ifdef LOG_OBSERVER 236 observerLog().addMessage() << "** Signing off " << observerLog().getName(target) << " from " << observerLog().getName(this) << endl; 237 #endif 238 callees_t &callees = callTable[this]; 234 void Observable::signOff(Observer *target) const 235 { 236 ASSERT(callTable.count(const_cast<Observable *>(this)),"SignOff called for an Observable without Observers."); 237 #ifdef LOG_OBSERVER 238 observerLog().addMessage() << "** Signing off " << observerLog().getName(target) << " from " << observerLog().getName(const_cast<Observable *>(this)) << endl; 239 #endif 240 callees_t &callees = callTable[const_cast<Observable *>(this)]; 239 241 240 242 callees_t::iterator iter; … … 249 251 } 250 252 if(callees.empty()){ 251 callTable.erase(this); 252 } 253 } 254 255 void Observable::signOn(Observer *target, Notification_ptr notification){ 253 callTable.erase(const_cast<Observable *>(this)); 254 } 255 } 256 257 void Observable::signOn(Observer *target, Notification_ptr notification) const 258 { 256 259 ASSERT(notification->owner==this, 257 260 "Trying to sign on for a notification that is not provided by this object"); … … 260 263 } 261 264 262 void Observable::signOff(Observer *target, Notification_ptr notification){ 265 void Observable::signOff(Observer *target, Notification_ptr notification) const 266 { 263 267 ASSERT(notification->owner==this, 264 268 "Trying to sign off from a notification that is not provided by this object"); … … 267 271 } 268 272 269 bool Observable::isBlocked(){ 270 return depth.count(this) > 0; 273 bool Observable::isBlocked() const 274 { 275 return depth.count(const_cast<Observable *>(this)) > 0; 271 276 } 272 277 -
src/Patterns/Observer.hpp
r74e0f7 r9e776f 122 122 * ussually no need to order the update sequence. 123 123 */ 124 virtual void signOn(Observer *target, int priority=0) ;124 virtual void signOn(Observer *target, int priority=0) const; 125 125 126 126 /** … … 128 128 * updates will be recieved from that observer. 129 129 */ 130 virtual void signOff(Observer *target) ;130 virtual void signOff(Observer *target) const; 131 131 132 132 /** 133 133 * Sign on for specialized notifications 134 134 */ 135 virtual void signOn(Observer *target, Notification_ptr notification) ;135 virtual void signOn(Observer *target, Notification_ptr notification) const; 136 136 137 137 /** 138 138 * Stop receiving a specialized notification 139 139 */ 140 virtual void signOff(Observer *target, Notification_ptr notification) ;140 virtual void signOff(Observer *target, Notification_ptr notification) const; 141 141 142 142 /** … … 144 144 * Changes are in Progress, that are not yet published. 145 145 */ 146 virtual bool isBlocked() ;146 virtual bool isBlocked() const; 147 147 148 148 Notification_ptr getChannel(size_t no) const;
Note:
See TracChangeset
for help on using the changeset viewer.
