Changeset bc2698
- Timestamp:
- Dec 13, 2011, 9:43:39 AM (14 years ago)
- Children:
- e2e035e
- Parents:
- e7352a5
- git-author:
- Frederik Heber <heber@…> (12/01/11 09:09:18)
- git-committer:
- Frederik Heber <heber@…> (12/13/11 09:43:39)
- Location:
- src/Patterns
- Files:
-
- 3 edited
-
Observer.cpp (modified) (2 diffs)
-
Observer.hpp (modified) (3 diffs)
-
unittests/stubs/ObserverStub.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Observer.cpp
re7352a5 rbc2698 43 43 std::map<Observable*,std::set<Notification*> > Observable::notifications; 44 44 set<Observable*> Observable::busyObservables; //!< Set of Observables that are currently busy notifying their sign-on'ed Observers 45 Observable::ChannelMap Observable::NotificationChannels; //!< Map of Observables to their Channels. 45 46 46 47 /** Attaching Sub-observables to Observables. … … 278 279 Notification_ptr Observable::getChannel(size_t no) const 279 280 { 280 ASSERT(NotificationChannels != NULL, 281 ChannelMap::iterator iter = NotificationChannels.find(const_cast<Observable *>(this)); 282 ASSERT(iter != NotificationChannels.end(), 283 "Observable::getChannel() - we do not have a channel in NotificationChannels."); 284 const Channels *OurChannel = iter->second; 285 ASSERT(OurChannel != NULL, 281 286 "Observable::getChannel() - observable has no channels."); 282 return NotificationChannels->getChannel(no);287 return OurChannel->getChannel(no); 283 288 } 284 289 -
src/Patterns/Observer.hpp
re7352a5 rbc2698 168 168 static void enque_notification_internal(Observable *publisher, Notification_ptr notification); 169 169 170 Channels *NotificationChannels; 170 typedef std::map<Observable*, Channels *> ChannelMap; 171 static ChannelMap NotificationChannels; 171 172 172 173 private: … … 197 198 }; 198 199 199 /** Notifications are sort of new channels of an Observable.200 /** Notifications are sort of news channels of an Observable. 200 201 * Via the NOTIFY() macro updates can be transmitted in a specific channel. 201 202 * Observers can subscribe to Notification in much the same way as they can to 202 * the Observable itself. Usually, Notifications 203 * the Observable itself. Usually, Notifications are used along 204 * with the usual OBSERVE() macro to generate both the specific and 205 * the global message of change. 203 206 */ 204 207 class Notification { … … 287 290 #define PASTE_HELPER(a,b) a ## b 288 291 #define OBSERVE Observable::_Observable_protector PASTE(_scope_obs_protector_,__LINE__)(this) 289 #define NOTIFY(channelno) do{ Observable::enque_notification_internal(this,NotificationChannels->getChannel(channelno));}while(0)292 #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) 290 293 #define LOCK_OBSERVABLE(observable) Observable::_Observable_protector PASTE(_scope_obs_protector_,__LINE__)(&(observable)) 291 294 -
src/Patterns/unittests/stubs/ObserverStub.cpp
re7352a5 rbc2698 132 132 Observable("NotificationObservable") 133 133 { 134 NotificationChannels = new Channels(this); 135 NotificationChannels->addChannel(Operation1Notify); 136 NotificationChannels->addChannel(Operation2Notify); 134 Channels *OurChannel = new Channels(this); 135 NotificationChannels.insert( std::make_pair(this, OurChannel) ); 136 OurChannel->addChannel(Operation1Notify); 137 OurChannel->addChannel(Operation2Notify); 137 138 } 138 139 139 140 NotificationObservable::~NotificationObservable() 140 141 { 141 delete NotificationChannels;142 NotificationChannels.erase(this); 142 143 } 143 144
Note:
See TracChangeset
for help on using the changeset viewer.
