Changeset 74e0f7 for src/Patterns/Observer.hpp
- Timestamp:
- Sep 1, 2011, 11:07:47 AM (14 years ago)
- Children:
- 9e776f
- Parents:
- 451f17
- git-author:
- Frederik Heber <heber@…> (09/01/11 11:02:49)
- git-committer:
- Frederik Heber <heber@…> (09/01/11 11:07:47)
- File:
-
- 1 edited
-
src/Patterns/Observer.hpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Observer.hpp
r451f17 r74e0f7 40 40 #endif 41 41 42 class Channels; 43 class Notification; 42 44 class Observable; 43 class Notification;44 45 45 46 // Pointers to notifications are used for unique identification … … 145 146 virtual bool isBlocked(); 146 147 148 Notification_ptr getChannel(size_t no) const; 149 147 150 protected: 148 151 virtual void update(Observable *publisher); … … 164 167 165 168 static void enque_notification_internal(Observable *publisher, Notification_ptr notification); 169 170 Channels *NotificationChannels; 166 171 167 172 private: … … 192 197 }; 193 198 199 /** Notifications are sort of new channels of an Observable. 200 * Via the NOTIFY() macro updates can be transmitted in a specific channel. 201 * Observers can subscribe to Notification in much the same way as they can to 202 * the Observable itself. Usually, Notifications 203 */ 194 204 class Notification { 195 205 friend class Observable; 206 friend class Channels; 196 207 public: 197 208 Notification(Observable *_owner); 209 Notification(Observable *_owner, size_t _channelno); 198 210 virtual ~Notification(); 211 212 size_t getChannelNo() const { return channelno; } 199 213 protected: 200 214 … … 206 220 Observable * const owner; 207 221 std::set<Observer*> targets; 222 size_t channelno; 223 }; 224 225 /** Channels aggregate all possible Notifications of an Observable. 226 * 227 * Usually, one implements an enumeration of the channel number which is 228 * visible to the outside only. 229 * 230 */ 231 class Channels { 232 public: 233 Channels(Observable *_owner); 234 virtual ~Channels(); 235 236 void addChannel(size_t no); 237 238 Notification_ptr getChannel(size_t no) const; 239 size_t getType(Notification_ptr channel) const; 240 241 protected: 242 void removeChannel(size_t no); 243 244 private: 245 Observable * const owner; 246 247 typedef std::map< size_t, Notification_ptr> NotificationTypetoRefMap; 248 249 NotificationTypetoRefMap ChannelMap; 208 250 }; 209 251 … … 245 287 #define PASTE_HELPER(a,b) a ## b 246 288 #define OBSERVE Observable::_Observable_protector PASTE(_scope_obs_protector_,__LINE__)(this) 247 #define NOTIFY( notification) do{Observable::enque_notification_internal(this,notification);}while(0)289 #define NOTIFY(channelno) do{Observable::enque_notification_internal(this,NotificationChannels->getChannel(channelno));}while(0) 248 290 #define LOCK_OBSERVABLE(observable) Observable::_Observable_protector PASTE(_scope_obs_protector_,__LINE__)(&(observable)) 249 291
Note:
See TracChangeset
for help on using the changeset viewer.
