- Timestamp:
- Aug 11, 2010, 8:55:13 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/questsystem/notifications/NotificationManager.cc
r6417 r7163 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 @param notification 121 A pointer to the Notification to be unregistered. 122 @param listener 123 A pointer to the NotificationListener the Notification is unregistered for. 124 */ 125 void NotificationManager::unregisterNotification(Notification* notification, NotificationListener* listener) 126 { 127 assert(notification); 128 assert(listener); 129 130 // If the Notification was removed from the list of Notifications of the input NotificationListener, the counter for the Notification of the number of NotificationListeners it is present in is decremented. 131 if(this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second))) 132 this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1; 133 134 // If the Notification is no longer present in any of the NotificationListeners it can be removed from the map of all Notifications and be destroyed. 135 if(this->listenerCounter_[notification] == (unsigned int) 0) 136 { 137 this->removeNotification(notification, this->allNotificationsList_); 138 this->listenerCounter_.erase(notification); 139 notification->destroy(); 140 } 141 142 COUT(4) << "Notification unregistered with the NotificationManager." << std::endl; 143 } 144 145 /** 146 @brief 147 Helper method that removes an input notification form an input map. 148 @param notification 149 A pointer to the notification to be removed. 150 @param map 151 The map the notification should be removed from. 152 @return 153 Returns true if successful. 154 */ 155 bool NotificationManager::removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map) 156 { 157 // Iterates through all items in the map until the Notification is found. 158 //TODO: Do more efficiently? 159 for(std::multimap<std::time_t, Notification*>::iterator it = map.begin(); it != map.end(); it++) 160 { 161 if(it->second == notification) 162 { 163 map.erase(it); 164 return true; 165 } 166 } 167 return false; 109 168 } 110 169 … … 130 189 { 131 190 this->notificationLists_[index] = &this->allNotificationsList_; 132 COUT( 3) << "NotificationListener registered with the NotificationManager." << std::endl;191 COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl; 133 192 return true; 134 193 } … … 142 201 if(set.find(it->second->getSender()) != set.end()) //!< Checks whether the overlay has the sender of the current notification as target. 143 202 { 144 map.insert(std::pair<std::time_t,Notification*>(it->first, it->second)); 203 map.insert(std::pair<std::time_t, Notification*>(it->first, it->second)); 204 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(it->second); 205 if(counterIt == this->listenerCounter_.end()) 206 this->listenerCounter_[it->second] = 1; 207 else 208 this->listenerCounter_[it->second] = counterIt->second + 1; 145 209 } 146 210 } … … 148 212 listener->update(); //!< Update the listener. 149 213 150 COUT( 3) << "NotificationListener registered with the NotificationManager." << std::endl;214 COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl; 151 215 152 216 return true; 217 } 218 219 /** 220 @brief 221 Unregisters a NotificationListener withing the NotificationManager. 222 */ 223 void NotificationManager::unregisterListener(NotificationListener* listener) 224 { 225 assert(listener); 226 227 int identifier = this->listenerList_.find(listener)->second; 228 std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second; 229 230 // Make sure all Notifications are removed. 231 std::multimap<std::time_t, Notification*>::iterator it = map->begin(); 232 while(it != map->end()) 233 { 234 this->unregisterNotification(it->second, listener); 235 it = map->begin(); 236 } 237 238 this->listenerList_.erase(listener); 239 this->notificationLists_.erase(identifier); 240 241 // If the map is not the map of all notifications, delete it. 242 if(map != &this->allNotificationsList_) 243 delete map; 244 245 COUT(4) << "NotificationListener unregistered with the NotificationManager." << std::endl; 153 246 } 154 247
Note: See TracChangeset
for help on using the changeset viewer.