Changeset 7163 for code/trunk/src/modules/questsystem/notifications
- Timestamp:
- Aug 11, 2010, 8:55:13 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/questsystem/notifications/Notification.cc
r6417 r7163 40 40 { 41 41 42 CreateUnloadableFactory(Notification); 43 42 44 /** 43 45 @brief … … 56 58 The message of the Notification. 57 59 */ 58 Notification::Notification( const std::string & message) : BaseObject(NULL)60 Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator) 59 61 { 60 62 this->message_ = message; … … 67 69 Notification::~Notification() 68 70 { 71 69 72 } 70 73 -
code/trunk/src/modules/questsystem/notifications/Notification.h
r5781 r7163 53 53 public: 54 54 Notification(BaseObject* creator); 55 Notification( const std::string & message);55 Notification(BaseObject* creator, const std::string & message); 56 56 virtual ~Notification(); 57 57 -
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 -
code/trunk/src/modules/questsystem/notifications/NotificationManager.h
r5929 r7163 60 60 virtual ~NotificationManager(); 61 61 62 static const std::string ALL; 63 static const std::string NONE; 62 static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationListeners. 63 static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener. 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. 97 100 101 bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input notification form an input map. 98 102 99 103 }; -
code/trunk/src/modules/questsystem/notifications/NotificationOverlay.cc
- Property svn:executable deleted
-
code/trunk/src/modules/questsystem/notifications/NotificationOverlay.h
- Property svn:executable deleted
-
code/trunk/src/modules/questsystem/notifications/NotificationQueue.cc
r6502 r7163 34 34 #include "NotificationQueue.h" 35 35 36 #include <sstream> 37 36 #include "util/Convert.h" 38 37 #include "core/CoreIncludes.h" 39 38 #include "core/XMLPort.h" … … 56 55 NotificationQueue::NotificationQueue(BaseObject* creator) : OverlayGroup(creator) 57 56 { 57 this->registered_ = false; 58 58 59 RegisterObject(NotificationQueue); 59 60 this->initialize(); … … 68 69 this->targets_.clear(); 69 70 this->clear(); 71 72 if(this->registered_) 73 NotificationManager::getInstance().unregisterListener(this); 70 74 } 71 75 … … 81 85 82 86 NotificationManager::getInstance().registerListener(this); 87 this->registered_ = true; 83 88 } 84 89 … … 118 123 XMLPortParam(NotificationQueue, "position", setPosition, getPosition, xmlElement, mode); 119 124 120 COUT(3) << "NotificationQueue created." << std::endl;125 COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl; 121 126 } 122 127 … … 173 178 delete notifications; 174 179 175 COUT( 3) << "NotificationQueueupdated." << std::endl;180 COUT(4) << "NotificationQueue '" << this->getName() << "' updated." << std::endl; 176 181 } 177 182 … … 196 201 } 197 202 198 COUT( 3) << "NotificationQueueupdated. A new Notifications has been added." << std::endl;203 COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notifications has been added." << std::endl; 199 204 } 200 205 … … 397 402 std::string timeString = std::ctime(&time); 398 403 timeString.erase(timeString.length()-1); 399 std::ostringstream stream; 400 stream << reinterpret_cast<unsigned long>(notification); 401 const std::string& addressString = stream.str(); 404 const std::string& addressString = multi_cast<std::string>(reinterpret_cast<unsigned long>(notification)); 402 405 container->name = "NotificationOverlay(" + timeString + ")&" + addressString; 403 406 … … 422 425 if(this->size_ == 0) //!< You cannot remove anything if the queue is empty. 423 426 return false; 427 428 // Unregister the NotificationQueue with the NotificationManager. 429 NotificationManager::getInstance().unregisterNotification(container->notification, this); 424 430 425 431 this->removeElement(container->overlay); … … 443 449 { 444 450 this->removeContainer(*it); 445 it = this->containers_.begin(); //TODO: Needed?451 it = this->containers_.begin(); 446 452 } 447 453 } -
code/trunk/src/modules/questsystem/notifications/NotificationQueue.h
r5781 r7163 71 71 72 72 Creating a NotificationQueue through XML goes as follows: 73 Be aware that the NotificationQueue must be inside the <Level></Level> tags or bad things will happen. 73 74 <NotificationQueue 74 75 name = "SuperQueue" //Name of your OverlayQueue. … … 185 186 NotificationOverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired. 186 187 188 bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already. 189 187 190 void initialize(void); //!< Initializes the object. 188 191 void setDefaults(void); //!< Helper method to set the default values.
Note: See TracChangeset
for help on using the changeset viewer.