- Timestamp:
- May 20, 2010, 9:43:45 PM (15 years ago)
- Location:
- code/branches/presentation3/src/modules/questsystem/notifications
- Files:
-
- 4 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 -
code/branches/presentation3/src/modules/questsystem/notifications/NotificationManager.h
r5929 r6944 64 64 65 65 bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager. 66 void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager. 66 67 bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager. 68 void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager. 67 69 68 70 bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationListener in a specified timeframe. … … 90 92 static NotificationManager* singletonPtr_s; 91 93 92 int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that 94 int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice. 93 95 94 std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored (together with their respecive timestamps).96 std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored. 95 97 std::map<NotificationListener*,int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier. 96 98 std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored. 99 std::map<Notification*, unsigned int> listenerCounter_; //!< A container to store the number of NotificationListeners a Notification is registered with. 100 101 bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); 97 102 98 103 -
code/branches/presentation3/src/modules/questsystem/notifications/NotificationQueue.cc
r6502 r6944 56 56 NotificationQueue::NotificationQueue(BaseObject* creator) : OverlayGroup(creator) 57 57 { 58 this->registered_ = false; 59 58 60 RegisterObject(NotificationQueue); 59 61 this->initialize(); … … 68 70 this->targets_.clear(); 69 71 this->clear(); 72 73 if(this->registered_) 74 NotificationManager::getInstance().unregisterListener(this); 70 75 } 71 76 … … 81 86 82 87 NotificationManager::getInstance().registerListener(this); 88 this->registered_ = true; 83 89 } 84 90 … … 423 429 return false; 424 430 431 NotificationManager::getInstance().unregisterNotification(container->notification, this); 432 425 433 this->removeElement(container->overlay); 426 434 this->containers_.erase(container); … … 443 451 { 444 452 this->removeContainer(*it); 445 it = this->containers_.begin(); //TODO: Needed?453 it = this->containers_.begin(); 446 454 } 447 455 } -
code/branches/presentation3/src/modules/questsystem/notifications/NotificationQueue.h
r5781 r6944 185 185 NotificationOverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired. 186 186 187 bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already. 188 187 189 void initialize(void); //!< Initializes the object. 188 190 void setDefaults(void); //!< Helper method to set the default values.
Note: See TracChangeset
for help on using the changeset viewer.