Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7412


Ignore:
Timestamp:
Sep 11, 2010, 4:16:10 PM (14 years ago)
Author:
dafrick
Message:

Fixed one (hopefully) final bug in Notifications.

Location:
code/trunk/src/modules/notifications
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/notifications/NotificationQueue.cc

    r7410 r7412  
    153153            while(it != this->ordering_.upper_bound(&this->timeLimit_))
    154154            {
    155                 NotificationContainer* temp = *it;
     155                std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator temp = it;
    156156                it++;
    157157                this->remove(temp); // Remove the Notifications that have expired.
     
    238238    {
    239239        NotificationContainer* container = this->notifications_.back();
    240         this->ordering_.erase(container);
     240        // Get all the NotificationContainers that were sent the same time the NotificationContainer we want to pop was sent.
     241        std::pair<std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator, std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator> iterators = this->ordering_.equal_range(container);
     242        // Iterate thourgh all suspects and remove the container as soon as we find it.
     243        for(std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = iterators.first; it != iterators.second; it++)
     244        {
     245            if(container == *it)
     246            {
     247                this->ordering_.erase(it);
     248                break;
     249            }
     250        }
    241251        this->notifications_.pop_back();
    242252
     
    252262    @brief
    253263        Removes the Notification that is stored in the input NotificationContainer.
    254     @param container
    255         The NotificationContainer with the Notification to be removed.
    256     */
    257     void NotificationQueue::remove(NotificationContainer* container)
    258     {
    259         std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), container);
     264    @param containerIterator
     265        An iterator to the NotificationContainer to be removed.
     266    */
     267    void NotificationQueue::remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator)
     268    {
     269        std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), *containerIterator);
    260270        // Get the index at which the Notification is.
    261271        std::vector<NotificationContainer*>::difference_type index = it - this->notifications_.begin ();
    262         this->ordering_.erase(container);
     272        this->ordering_.erase(containerIterator);
    263273        this->notifications_.erase(it);
    264274
    265275        this->size_--;
    266276
    267         delete container;
     277        delete *containerIterator;
    268278
    269279        // Removes the Notification from the GUI.
  • code/trunk/src/modules/notifications/NotificationQueue.h

    r7410 r7412  
    158158            void push(Notification* notification, const std::time_t & time); //!< Adds (pushes) a Notification to the NotificationQueue.
    159159            void pop(void); //!< Removes (pops) the least recently added Notification form the NotificationQueue.
    160             void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input NotificationContainer.
     160            void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); //!< Removes the Notification that is stored in the input NotificationContainer.
    161161
    162162            void clear(void); //!< Clears the NotificationQueue by removing all NotificationContainers.
Note: See TracChangeset for help on using the changeset viewer.