[Orxonox-commit 183] r2858 - branches/questsystem5/src/orxonox/overlays/notifications

dafrick at orxonox.net dafrick at orxonox.net
Thu Mar 26 21:45:23 CET 2009


Author: dafrick
Date: 2009-03-26 20:45:23 +0000 (Thu, 26 Mar 2009)
New Revision: 2858

Modified:
   branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc
   branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.h
   branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc
   branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.h
   branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc
   branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h
Log:
Done some documenting, and resolved some (possible) issues. So the Notifications are about finished...

Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc	2009-03-26 18:28:09 UTC (rev 2857)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc	2009-03-26 20:45:23 UTC (rev 2858)
@@ -173,40 +173,35 @@
         Fetches the Notifications for a specific NotificationQueue in a specified timeframe.
     @param queue
         The NotificationQueue the Notifications are fetched for.
+    @param map
+        A multimap, in which the notifications are stored.
     @param timeFrameStart
         The start time of the timeframe.
     @param timeFrameEnd
         The end time of the timeframe.
     @return
-        Returns a time-ordered list of Notifications.
-    @todo
-        Make sure the map is deleted.
+        Returns true if successful.
     */
-    std::multimap<std::time_t,Notification*>* NotificationManager::getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
+    bool NotificationManager::getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
     {
-        std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->queueList_[queue]];
+        if(queue == NULL || map == NULL)
+            return false;
+
+        std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->queueList_[queue]]; //!< The Notifications for the input NotificationQueue.
         
-        if(notifications == NULL)
-            return NULL;
+        if(notifications == NULL) //!< Returns NULL, if there are no Notifications.
+            return true;
     
         std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest;
         itLowest = notifications->lower_bound(timeFrameStart);
         itHighest = notifications->upper_bound(timeFrameStart);
         
-        std::multimap<std::time_t,Notification*>* map = new std::multimap<std::time_t,Notification*>();
-        
-        for(it = itLowest; it != itHighest; it++)
+        for(it = itLowest; it != itHighest; it++) //!< Iterate through the Notifications from the start of the time Frame to the end of it.
         {
-            map->insert(std::pair<std::time_t,Notification*>(it->first,it->second));
+            map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); //!< Add the found Notifications to the map.
         }
         
-        if(map->size() == 0)
-        {
-            delete map;
-            return NULL;
-        }
-        
-        return map;
+        return true;
     }
 
 }

Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.h
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.h	2009-03-26 18:28:09 UTC (rev 2857)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.h	2009-03-26 20:45:23 UTC (rev 2858)
@@ -65,28 +65,29 @@
          
             static NotificationManager & getInstance(); //! Returns a reference to the single instance of the NotificationManager.
 
-            //TDO: Visibility?
             bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
             bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue within the NotificationManager.
             
-            std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueue in a specified timeframe.
+            bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueue in a specified timeframe.
             
             /**
             @brief Fetches the Notifications for a specific NotificationQueue starting at a specified time.
             @param queue The NotificationQueue the Notifications are fetched for.
+            @param map A multimap, in which the notifications are stored.
             @param timeFrameStart The start time the Notifications are fetched from.
-            @return Returns a time-ordered list of Notifications.
+            @return Returns true if successful.
             */
-            std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart)
-                { return this->getNotifications(queue, timeFrameStart, std::time(0)); }
+            bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart)
+                { return this->getNotifications(queue, map, timeFrameStart, std::time(0)); }
             /**
             @brief Fetches the Notifications for a specific NotificationQueue starting at a specified timespan before now.
             @param queue The NotificationQueue the Notifications are fetched for.
+            @param map A multimap, in which the notifications are stored.
             @param timeDelay The timespan.
-            @return Returns a time-ordered list of Notifications.
+            @return Returns true if successful.
             */
-            std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, int timeDelay)
-                { return this->getNotifications(queue, std::time(0)-timeDelay, std::time(0)); }
+            bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, int timeDelay)
+                { return this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); }
      
         private:
             static NotificationManager* singletonRef_s;

Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc	2009-03-26 18:28:09 UTC (rev 2857)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc	2009-03-26 20:45:23 UTC (rev 2858)
@@ -26,6 +26,11 @@
  *
  */
 
+/**
+    @file NotificationOverlay.cc
+    @brief Implementation of the NotificationOverlay class.
+*/
+
 #include "OrxonoxStableHeaders.h"
 #include "NotificationOverlay.h"
 
@@ -42,16 +47,30 @@
 namespace orxonox
 {
 
+    /**
+    @brief
+        Constructor. Intializes the class.
+    */
     NotificationOverlay::NotificationOverlay(BaseObject* creator) : OverlayText(creator)
     {
         this->initialize();
     }
 
+    /**
+    @brief
+        Constructor. Initilaizes the class creates a graphical representation of the input Notification for the input Queue.
+    @param queue
+        A pointer to the queue the NotificatonOverlay belongs to.
+    @param notification
+        A pointer to the Notification represented by this overlay.
+    @throws Argument
+        Throws an Argument-Exception if either no Notification or no NotificationQueue were input.
+    */
     NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OverlayText(this)
     {
         this->initialize();
         
-        if(notification == NULL || queue == NULL)
+        if(notification == NULL || queue == NULL) //!> If either notification or queue are not given an Exception is thrown.
         {
             ThrowException(Argument, "There were NULL-Pointer arguments in NotificationOverlay creation.");
         }
@@ -62,6 +81,10 @@
         this->processNotification(notification);
     }
     
+    /**
+    @brief
+        Initializes and Registers the object.
+    */
     void NotificationOverlay::initialize(void)
     {
         RegisterObject(NotificationOverlay);
@@ -69,6 +92,10 @@
         this->queue_ = NULL;
     }
     
+    /**
+    @brief
+        Set some Overlay-specific values.
+    */
     void NotificationOverlay::defineOverlay(void)
     {
         this->setFont(this->queue_->getFont());
@@ -77,20 +104,38 @@
         this->setPosition(this->queue_->getPosition());
     }
 
+    /**
+    @brief
+        Destructor.
+    */
     NotificationOverlay::~NotificationOverlay()
     {
     }
 
+    /**
+    @brief
+        Processes the input notification, resp. sees to it. that the NotificationOverlay displays the Notification message.
+    @param notification
+        A pointer to the notification that should be processed.
+    @return
+        Returns true if successful.
+    */
     bool NotificationOverlay::processNotification(Notification* notification)
     {
+        if(notification == NULL)
+            return false;
         this->setCaption(clipMessage(notification->getMessage()));
         this->notification_ = notification;
         return true;
     }
 
+    /**
+    @brief
+        Clips the input message so that it meets the requirements for the maximal length of Notifications given by the NotificationQueue.
+    */
     const std::string NotificationOverlay::clipMessage(const std::string & message)
     {
-        if(message.length() <= (unsigned int)this->queue_->getNotificationLength())
+        if(message.length() <= (unsigned int)this->queue_->getNotificationLength()) //!< If the message is not too long.
             return message;
         return message.substr(0, this->queue_->getNotificationLength());
     }

Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.h
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.h	2009-03-26 18:28:09 UTC (rev 2857)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.h	2009-03-26 20:45:23 UTC (rev 2858)
@@ -26,6 +26,12 @@
  *
  */
 
+/**
+    @file NotificationOverlay.h
+    @brief Definition of the NotificationOverlay class.
+*/
+
+
 #ifndef _NotificationOverlay_H__
 #define _NotificationOverlay_H__
 
@@ -43,7 +49,7 @@
 
     /**
     @brief
-        
+        The NotificationOverlay is used to display single Notifications, then bundled in a NotificationQUeue.
     @author
         Damian 'Mozork' Frick
     */
@@ -55,20 +61,24 @@
             NotificationOverlay(NotificationQueue* queue, Notification* notification);
             virtual ~NotificationOverlay();
             
-            bool processNotification(Notification* notification);
+            bool processNotification(Notification* notification); //!< Processes the input Notification.
 
-            void setFontSize(float size)
+            /**
+            @brief Sets the font size of this overlay's text.
+            @param size The font size.
+            */
+            inline void setFontSize(float size)
                 { this->setTextSize(size); }
         
         protected:
-            const std::string clipMessage(const std::string & message);
+            const std::string clipMessage(const std::string & message); //!< Clips the input message if too long.
 
         private:
-            NotificationQueue* queue_;
-            Notification* notification_;
+            NotificationQueue* queue_; //!< The NotificationQeue this overlay belongs to.
+            Notification* notification_; //!< The Notification this overlay displays.
 
-            void initialize(void);
-            void defineOverlay(void);
+            void initialize(void); //!< Initializes the object.
+            void defineOverlay(void); //!< Sets some overlay-specific values.
 
     };
 

Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc	2009-03-26 18:28:09 UTC (rev 2857)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc	2009-03-26 20:45:23 UTC (rev 2858)
@@ -26,12 +26,19 @@
  *
  */
 
+/**
+    @file NotificationQueue.cc
+    @brief Implementation of the NotificationQueue class.
+*/
+
 #include "OrxonoxStableHeaders.h"
 #include "NotificationQueue.h"
 
 #include <OgreOverlayManager.h>
 #include <OgreTextAreaOverlayElement.h>
 #include <list>
+#include <iostream>
+#include <sstream>
 
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
@@ -154,16 +161,23 @@
     {
         this->clear();
     
-        std::multimap<std::time_t,Notification*>* notifications = NotificationManager::getInstance().getNotifications(this, this->displayTime_);
+        std::multimap<std::time_t,Notification*>* notifications = new std::multimap<std::time_t,Notification*>;
+        if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) //!< Get the Notifications sent in the interval form now to minus the display time.
+        {
+            COUT(1) << "NotificationQueue update failed due to undetermined cause." << std::endl;
+            return;
+        }
         
-        if(notifications == NULL)
+        if(notifications->empty())
             return;
         
-        for(std::multimap<std::time_t,Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++)
+        for(std::multimap<std::time_t,Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) //!> Add all Notifications.
         {
             this->addNotification(it->second, it->first);
         }
         
+        delete notifications;
+        
         COUT(3) << "NotificationQueue updated." << std::endl;
     }
     
@@ -342,6 +356,12 @@
         return true;
     }
 
+    /**
+    @brief
+        Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector.
+    @param pos
+        The vector the NotificationQueue is scrolled.
+    */
     void NotificationQueue::scroll(const Vector2 pos)
     {
         for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Scroll each overlay.
@@ -350,7 +370,11 @@
         }
     }
 
-    void NotificationQueue::positionChanged()
+    /**
+    @brief
+        Aligns all the Notifications to the position of the NotificationQueue.
+    */
+    void NotificationQueue::positionChanged(void)
     {
         int counter = 0;
         for (std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin(); it != this->containers_.end(); it++) //!< Set the position for each overlay.
@@ -378,9 +402,9 @@
         container->time = time;
         std::string timeString = std::ctime(&time);
         timeString.erase(timeString.length()-1);
-        char buffer[64]; //TDO: Very un-nice.
-        std::sprintf(buffer,"%x",(unsigned long)notification); //TDO: Use other conversion to avoid 64bit problems.
-        std::string addressString = buffer;
+        std::ostringstream stream;
+        stream << (unsigned long)notification;
+        std::string addressString = stream.str() ;
         container->name = "NotificationOverlay(" + timeString + ")&" + addressString;
         
         this->containers_.insert(container);

Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h	2009-03-26 18:28:09 UTC (rev 2857)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h	2009-03-26 20:45:23 UTC (rev 2858)
@@ -70,6 +70,19 @@
     /**
     @brief
         Displays Notifications from specific senders.
+        Beware! The NotificationQueue is an OverlayGruop and thus cannot be be a sub-element of an OverlayGroup (at least no for now.)
+
+        Creating a NotificationQueue through XML goes as follows:
+        <NotificationQueue
+            name = "SuperQueue" //Name of your OverlayQueue.
+            maxSize = "5" //The maximum size of Notifications displayed.
+            notificationLength = "64" //The maximum number of characters of a Notification, that are displayed. (Default is 5)
+            displayTime = "30" //The time a Notification is displayed in seconds. (Default is 30)
+            targets = "target1, target2" //The senders this NotificationQueue displays Notifications from. (all, if all Notifications should be displayed.)
+            font = "VeraMono" //The font (Default is VeraMono)
+            fontSize = '0.4' //The font size. (Default is 0.025)
+            position = "0.0, .0.0" //The position of the NotificationQueue. (Default is 0.0,0.0)
+        />
     @author
         Damian 'Mozork' Frick
     */
@@ -139,10 +152,14 @@
                 { return this->targets_; }
             bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets.
             
-            inline void setPosition(Vector2 pos)
+            /**
+            @brief Sets the position of the NotificationQueue.
+            @param pos The position.
+            */
+            inline void setPosition(Vector2 pos) 
                 { this->position_ = pos; this->positionChanged(); }
 
-            void scroll(const Vector2 pos);
+            void scroll(const Vector2 pos); //!< Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector.
             
         private:
             static const int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
@@ -182,7 +199,7 @@
             bool setFontSize(float size); //!< Set the font size.
             bool setFont(const std::string & font); //!< Set the font.
 
-            void positionChanged();
+            void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue.
             
             void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
             bool removeContainer(NotificationOverlayContainer* container); //!< Remove a container from the queue.




More information about the Orxonox-commit mailing list