Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 11, 2010, 8:55:13 AM (14 years ago)
Author:
dafrick
Message:

Merged presentation3 branch into trunk.

Location:
code/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/questsystem/notifications/Notification.cc

    r6417 r7163  
    4040{
    4141
     42    CreateUnloadableFactory(Notification);
     43
    4244    /**
    4345    @brief
     
    5658        The message of the Notification.
    5759    */
    58     Notification::Notification(const std::string & message) : BaseObject(NULL)
     60    Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator)
    5961    {
    6062        this->message_ = message;
     
    6769    Notification::~Notification()
    6870    {
     71
    6972    }
    7073
  • code/trunk/src/modules/questsystem/notifications/Notification.h

    r5781 r7163  
    5353        public:
    5454            Notification(BaseObject* creator);
    55             Notification(const std::string & message);
     55            Notification(BaseObject* creator, const std::string & message);
    5656            virtual ~Notification();
    5757
  • code/trunk/src/modules/questsystem/notifications/NotificationManager.cc

    r6417 r7163  
    6666    NotificationManager::~NotificationManager()
    6767    {
     68
    6869    }
    6970
     
    101102                this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationListener.
    102103                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;
    103109            }
    104110        }
    105111
    106         COUT(3) << "Notification registered with the NotificationManager." << std::endl;
     112        COUT(4) << "Notification registered with the NotificationManager." << std::endl;
    107113
    108114        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;
    109168    }
    110169
     
    130189        {
    131190            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;
    133192            return true;
    134193        }
     
    142201            if(set.find(it->second->getSender()) != set.end()) //!< Checks whether the overlay has the sender of the current notification as target.
    143202            {
    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;
    145209            }
    146210        }
     
    148212        listener->update(); //!< Update the listener.
    149213
    150         COUT(3) << "NotificationListener registered with the NotificationManager." << std::endl;
     214        COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
    151215
    152216        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;
    153246    }
    154247
  • code/trunk/src/modules/questsystem/notifications/NotificationManager.h

    r5929 r7163  
    6060            virtual ~NotificationManager();
    6161
    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.
    6464
    6565            bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
     66            void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager.
    6667            bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager.
     68            void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager.
    6769
    6870            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.
     
    9092            static NotificationManager* singletonPtr_s;
    9193
    92             int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that  no key appears twice.
     94            int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
    9395
    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.
    9597            std::map<NotificationListener*,int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
    9698            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.
    97100
     101            bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input notification form an input map.
    98102
    99103    };
  • 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  
    3434#include "NotificationQueue.h"
    3535
    36 #include <sstream>
    37 
     36#include "util/Convert.h"
    3837#include "core/CoreIncludes.h"
    3938#include "core/XMLPort.h"
     
    5655    NotificationQueue::NotificationQueue(BaseObject* creator) : OverlayGroup(creator)
    5756    {
     57        this->registered_ = false;
     58
    5859        RegisterObject(NotificationQueue);
    5960        this->initialize();
     
    6869        this->targets_.clear();
    6970        this->clear();
     71
     72        if(this->registered_)
     73            NotificationManager::getInstance().unregisterListener(this);
    7074    }
    7175
     
    8185
    8286        NotificationManager::getInstance().registerListener(this);
     87        this->registered_ = true;
    8388    }
    8489
     
    118123        XMLPortParam(NotificationQueue, "position", setPosition, getPosition, xmlElement, mode);
    119124
    120         COUT(3) << "NotificationQueue created." << std::endl;
     125        COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl;
    121126    }
    122127
     
    173178        delete notifications;
    174179
    175         COUT(3) << "NotificationQueue updated." << std::endl;
     180        COUT(4) << "NotificationQueue '" << this->getName() << "' updated." << std::endl;
    176181    }
    177182
     
    196201        }
    197202
    198         COUT(3) << "NotificationQueue updated. A new Notifications has been added." << std::endl;
     203        COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notifications has been added." << std::endl;
    199204    }
    200205
     
    397402        std::string timeString = std::ctime(&time);
    398403        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));
    402405        container->name = "NotificationOverlay(" + timeString + ")&" + addressString;
    403406
     
    422425        if(this->size_ == 0) //!< You cannot remove anything if the queue is empty.
    423426            return false;
     427
     428        // Unregister the NotificationQueue with the NotificationManager.
     429        NotificationManager::getInstance().unregisterNotification(container->notification, this);
    424430
    425431        this->removeElement(container->overlay);
     
    443449        {
    444450            this->removeContainer(*it);
    445             it = this->containers_.begin(); //TODO: Needed?
     451            it = this->containers_.begin();
    446452        }
    447453    }
  • code/trunk/src/modules/questsystem/notifications/NotificationQueue.h

    r5781 r7163  
    7171
    7272        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.
    7374        <NotificationQueue
    7475            name = "SuperQueue" //Name of your OverlayQueue.
     
    185186            NotificationOverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
    186187
     188            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
     189
    187190            void initialize(void); //!< Initializes the object.
    188191            void setDefaults(void); //!< Helper method to set the default values.
Note: See TracChangeset for help on using the changeset viewer.