Changeset b760ac5 for src/Patterns/Observer/Relay.cpp
- Timestamp:
- Dec 13, 2011, 12:02:21 PM (14 years ago)
- Children:
- 3324cf
- Parents:
- d85532
- git-author:
- Frederik Heber <heber@…> (12/02/11 13:13:44)
- git-committer:
- Frederik Heber <heber@…> (12/13/11 12:02:21)
- File:
-
- 1 edited
-
src/Patterns/Observer/Relay.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Observer/Relay.cpp
rd85532 rb760ac5 24 24 #include "Assert.hpp" 25 25 #include "Channels.hpp" 26 #include "defs.hpp"27 26 #include "Notification.hpp" 28 27 … … 48 47 observerLog().addMessage() << "-- Destroying Relay " << observerLog().getName(this); 49 48 #endif 50 } 51 49 // killing subjects is done by Observables' dstor 50 } 51 52 53 54 /** Sign on an Observer to this Observable. 55 * Puts \a *target into Observable::callTable list. 56 * \param *target Observer 57 * \param priority number in [-20,20] 58 */ 59 void Relay::signOn(Observer *target, PriorityLevel priority) const 60 { 61 #ifdef LOG_OBSERVER 62 observerLog().addMessage() << "@@ Signing on " << observerLog().getName(target) 63 << " to " 64 << observerLog().getName(const_cast<Observable *>(static_cast<const Observable * const>(this))); 65 #endif 66 bool res = false; 67 callees_t &callees = callTable[const_cast<Observable *>(static_cast<const Observable * const>(this))]; 68 69 callees_t::iterator iter; 70 for(iter=callees.begin();iter!=callees.end();++iter){ 71 res |= ((*iter).second == target); 72 } 73 if(!res) 74 callees.insert(std::pair<int,Observer*>(priority.level,target)); 75 } 76 77 /** Sign off an Observer from this Observable. 78 * Removes \a *target from Observable::callTable list. 79 * \param *target Observer 80 */ 81 void Relay::signOff(Observer *target) const 82 { 83 ASSERT(callTable.count(const_cast<Observable *>(static_cast<const Observable * const>(this))), 84 "Relay::signOff() - called for an Observable without Observers."); 85 #ifdef LOG_OBSERVER 86 observerLog().addMessage() << "** Signing off " << observerLog().getName(target) 87 << " from " 88 << observerLog().getName(const_cast<Observable *>(static_cast<const Observable * const>(this))); 89 #endif 90 callees_t &callees = callTable[const_cast<Observable *>(static_cast<const Observable * const>(this))]; 91 92 callees_t::iterator iter; 93 callees_t::iterator deliter; 94 for(iter=callees.begin();iter!=callees.end();) { 95 if((*iter).second == target) { 96 callees.erase(iter++); 97 } 98 else { 99 ++iter; 100 } 101 } 102 if(callees.empty()){ 103 callTable.erase(const_cast<Observable *>(static_cast<const Observable * const>(this))); 104 } 105 } 106 107 void Relay::signOn(Observer *target, size_t channelno) const 108 { 109 Notification_ptr notification = getChannel(channelno); 110 notification->addObserver(target); 111 } 112 113 void Relay::signOff(Observer *target, size_t channelno) const 114 { 115 Notification_ptr notification = getChannel(channelno); 116 notification->removeObserver(target); 117 } 52 118 53 119 /** Notify all Observers of changes. … … 125 191 Updater = publisher; 126 192 notifyAll(); 193 Updater = NULL; 127 194 } 128 195 else{ … … 135 202 } 136 203 137 //Notification_ptr Relay::getChannel(size_t no) const 138 //{ 139 // ASSERT(NotificationChannels != NULL, 140 // "Relay::getChannel() - observable has no channels."); 141 // return NotificationChannels->getChannel(no); 142 //} 204 /** Method for receiving specialized notifications. 205 * 206 * \param *publisher The \a *this we observe. 207 * \param notification type of notification 208 */ 209 void Relay::recieveNotification(Observable *publisher, Notification_ptr notification) 210 { 211 Updater = publisher; 212 const Channels *myChannels = NotificationChannels[const_cast<Observable *>(static_cast<const Observable * const>(this))]; 213 ASSERT(myChannels != NULL, 214 "Relay::recieveNotification() - this relay does not have any channels."); 215 const size_t channelno = notification->getChannelNo(); 216 Notification_ptr mynotification = myChannels->getChannel(channelno); 217 ASSERT(mynotification != NULL, 218 "Relay::recieveNotification() - this relay does not have a notification no "+toString(channelno)+"."); 219 mynotification->notifyAll(Updater); 220 Updater = NULL; 221 } 143 222 144 223 /** Handles sub-observables that just got killed
Note:
See TracChangeset
for help on using the changeset viewer.
