Changeset 40f2e6
- Timestamp:
- Dec 13, 2011, 9:46:12 AM (14 years ago)
- Children:
- 2c11c1
- Parents:
- 75d156
- git-author:
- Frederik Heber <heber@…> (12/02/11 10:05:36)
- git-committer:
- Frederik Heber <heber@…> (12/13/11 09:46:12)
- Location:
- src/Patterns/Observer
- Files:
-
- 4 edited
-
Observable.cpp (modified) (1 diff)
-
Observable.hpp (modified) (2 diffs)
-
unittests/ObserverUnitTest.cpp (modified) (3 diffs)
-
unittests/stubs/ObserverStub.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Observer/Observable.cpp
r75d156 r40f2e6 273 273 } 274 274 275 void Observable::signOn(Observer *target, Notification_ptr notification) const 276 { 275 void Observable::signOn(Observer *target, size_t channelno) const 276 { 277 Notification_ptr notification = getChannel(channelno); 277 278 notification->addObserver(target); 278 279 } 279 280 280 void Observable::signOff(Observer *target, Notification_ptr notification) const 281 { 281 void Observable::signOff(Observer *target, size_t channelno) const 282 { 283 Notification_ptr notification = getChannel(channelno); 282 284 notification->removeObserver(target); 283 285 } -
src/Patterns/Observer/Observable.hpp
r75d156 r40f2e6 74 74 * Sign on for specialized notifications 75 75 */ 76 virtual void signOn(Observer *target, Notification_ptr notification) const;76 virtual void signOn(Observer *target, size_t channelno) const; 77 77 78 78 /** 79 79 * Stop receiving a specialized notification 80 80 */ 81 virtual void signOff(Observer *target, Notification_ptr notification) const;81 virtual void signOff(Observer *target, size_t channelno) const; 82 82 83 83 /** … … 146 146 #define PASTE_HELPER(a,b) a ## b 147 147 #define OBSERVE Observable::_Observable_protector PASTE(_scope_obs_protector_,__LINE__)(this) 148 #define NOTIFY(channelno) do{ const ChannelMap::const_iterator iter=NotificationChannels.find(this);ASSERT(iter!=NotificationChannels.end(),"NOTIFY() - channel not found.");Observable::enque_notification_internal(this,iter->second->getChannel(channelno));}while(0)148 #define NOTIFY(channelno) do{Observable::enque_notification_internal(this,NotificationChannels[this]->getChannel(channelno));}while(0) 149 149 #define LOCK_OBSERVABLE(observable) Observable::_Observable_protector PASTE(_scope_obs_protector_,__LINE__)(&(observable)) 150 150 -
src/Patterns/Observer/unittests/ObserverUnitTest.cpp
r75d156 r40f2e6 160 160 161 161 void ObserverTest::doesNotifyTest(){ 162 CPPUNIT_ASSERT_EQUAL( 163 (size_t)NotificationObservable::Operation1Notify, 164 notificationObservable->getChannel(NotificationObservable::Operation1Notify)->getChannelNo()); 165 CPPUNIT_ASSERT_EQUAL( 166 (size_t)NotificationObservable::Operation2Notify, 167 notificationObservable->getChannel(NotificationObservable::Operation2Notify)->getChannelNo()); 168 notificationObservable->signOn(notificationObserver1, 169 notificationObservable->getChannel(NotificationObservable::Operation1Notify)); 170 notificationObservable->signOn(notificationObserver2, 171 notificationObservable->getChannel(NotificationObservable::Operation2Notify)); 162 notificationObservable->signOn(notificationObserver1, NotificationObservable::Operation1Notify); 163 notificationObservable->signOn(notificationObserver2, NotificationObservable::Operation2Notify); 172 164 173 165 notificationObservable->operation1(); … … 180 172 CPPUNIT_ASSERT(!notificationObserver1->wasNotified); 181 173 CPPUNIT_ASSERT(notificationObserver2->wasNotified); 182 183 174 } 184 175 … … 237 228 CPPUNIT_ASSERT_EQUAL( 1, observer2->updates); 238 229 239 240 230 obsset->signOff(observer1); 241 231 obsmap->signOff(observer2); -
src/Patterns/Observer/unittests/stubs/ObserverStub.cpp
r75d156 r40f2e6 170 170 void NotificationObserver::subjectKilled(Observable*){} 171 171 void NotificationObserver::recieveNotification(Observable *publisher, Notification_ptr notification){ 172 ASSERT(requestedNotification==notification,"Notification received that was not requested");172 CPPUNIT_ASSERT(requestedNotification==notification); 173 173 wasNotified = true; 174 174 }
Note:
See TracChangeset
for help on using the changeset viewer.
