Changeset 6944 for code/branches/presentation3/src/modules/questsystem/notifications/NotificationManager.cc
- Timestamp:
- May 20, 2010, 9:43:45 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/src/modules/questsystem/notifications/NotificationManager.cc
r6417 r6944 66 66 NotificationManager::~NotificationManager() 67 67 { 68 68 69 } 69 70 … … 101 102 this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationListener. 102 103 it->first->update(notification, time); //!< Update the listener. 104 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(notification); 105 if(counterIt == this->listenerCounter_.end()) 106 this->listenerCounter_[notification] = 1; 107 else 108 this->listenerCounter_[notification] = counterIt->second + 1; 103 109 } 104 110 } 105 111 106 COUT( 3) << "Notification registered with the NotificationManager." << std::endl;112 COUT(4) << "Notification registered with the NotificationManager." << std::endl; 107 113 108 114 return true; 115 } 116 117 /** 118 @brief 119 Unregisters a Notification within the NotificationManager. 120 */ 121 void NotificationManager::unregisterNotification(Notification* notification, NotificationListener* listener) 122 { 123 assert(notification); 124 assert(listener); 125 126 if(this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second))) 127 this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1; 128 if(this->listenerCounter_[notification] == (unsigned int) 0) 129 { 130 this->removeNotification(notification, this->allNotificationsList_); 131 notification->destroy(); 132 } 133 134 COUT(4) << "Notification unregistered with the NotificationManager." << std::endl; 135 } 136 137 /** 138 @brief 139 Helper method that removes an input notification form an input map. 140 */ 141 bool NotificationManager::removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map) 142 { 143 for(std::multimap<std::time_t, Notification*>::iterator it = map.begin(); it != map.end(); it++) 144 { 145 if(it->second == notification) 146 { 147 map.erase(it); 148 return true; 149 } 150 } 151 return false; 109 152 } 110 153 … … 130 173 { 131 174 this->notificationLists_[index] = &this->allNotificationsList_; 132 COUT( 3) << "NotificationListener registered with the NotificationManager." << std::endl;175 COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl; 133 176 return true; 134 177 } … … 142 185 if(set.find(it->second->getSender()) != set.end()) //!< Checks whether the overlay has the sender of the current notification as target. 143 186 { 144 map.insert(std::pair<std::time_t,Notification*>(it->first, it->second)); 187 map.insert(std::pair<std::time_t, Notification*>(it->first, it->second)); 188 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(it->second); 189 if(counterIt == this->listenerCounter_.end()) 190 this->listenerCounter_[it->second] = 1; 191 else 192 this->listenerCounter_[it->second] = counterIt->second + 1; 145 193 } 146 194 } … … 148 196 listener->update(); //!< Update the listener. 149 197 150 COUT( 3) << "NotificationListener registered with the NotificationManager." << std::endl;198 COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl; 151 199 152 200 return true; 201 } 202 203 /** 204 @brief 205 Unregisters a NotificationListener withing the NotificationManager. 206 */ 207 void NotificationManager::unregisterListener(NotificationListener* listener) 208 { 209 assert(listener); 210 211 int identifier = this->listenerList_.find(listener)->second; 212 std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second; 213 214 // Make sure all Notifications are removed. 215 std::multimap<std::time_t, Notification*>::iterator it = map->begin(); 216 while(it != map->end()) 217 { 218 this->unregisterNotification(it->second, listener); 219 it = map->begin(); 220 } 221 222 this->listenerList_.erase(listener); 223 this->notificationLists_.erase(identifier); 224 delete map; 225 226 COUT(4) << "NotificationListener unregistered with the NotificationManager." << std::endl; 153 227 } 154 228
Note: See TracChangeset
for help on using the changeset viewer.