[Orxonox-commit 2708] r7413 - in code/trunk: data/gui/scripts src/libraries/util src/modules/notifications src/orxonox/interfaces

dafrick at orxonox.net dafrick at orxonox.net
Sat Sep 11 17:05:48 CEST 2010


Author: dafrick
Date: 2010-09-11 17:05:47 +0200 (Sat, 11 Sep 2010)
New Revision: 7413

Modified:
   code/trunk/data/gui/scripts/NotificationLayer.lua
   code/trunk/src/libraries/util/StringUtils.h
   code/trunk/src/modules/notifications/Notification.cc
   code/trunk/src/modules/notifications/NotificationManager.cc
   code/trunk/src/modules/notifications/NotificationQueue.cc
   code/trunk/src/modules/notifications/NotificationQueue.h
   code/trunk/src/orxonox/interfaces/NotificationListener.h
Log:
Removing some TODO comments.
Better handling of duplicate name in Notificationlayer.lua.
Moving StringCompare object from NotificationListener to StringUtils.


Modified: code/trunk/data/gui/scripts/NotificationLayer.lua
===================================================================
--- code/trunk/data/gui/scripts/NotificationLayer.lua	2010-09-11 14:16:10 UTC (rev 7412)
+++ code/trunk/data/gui/scripts/NotificationLayer.lua	2010-09-11 15:05:47 UTC (rev 7413)
@@ -425,10 +425,18 @@
 function P.createNewQueue_clicked(e)
     local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName")
     local name = window:getText()
+
+    local queue = P.queueList[name]
+    -- Test if a queue with that name already exists.
+    if queue ~= nil then
+        window:setText("Queue with that name already exists.")
+        return
+    end
+
     -- Creates the new queue.
     orxonox.NotificationManager:getInstance():createQueue(name)
 
-    local queue = P.queueList[name]
+    queue = P.queueList[name]
     if queue == nil then
         return
     end

Modified: code/trunk/src/libraries/util/StringUtils.h
===================================================================
--- code/trunk/src/libraries/util/StringUtils.h	2010-09-11 14:16:10 UTC (rev 7412)
+++ code/trunk/src/libraries/util/StringUtils.h	2010-09-11 15:05:47 UTC (rev 7413)
@@ -46,6 +46,14 @@
 namespace orxonox
 {
     extern _UtilExport std::string BLANKSTRING;
+
+    //!< Struct that can be used as a comparison object for strings in stl containers.
+    _UtilExport struct StringCompare
+    {
+        bool operator() (const std::string& lhs, const std::string& rhs) const
+            { return lhs.compare(rhs) < 0; }
+    };
+
     _UtilExport std::string getUniqueNumberString();
 
     _UtilExport void         strip(std::string* str);

Modified: code/trunk/src/modules/notifications/Notification.cc
===================================================================
--- code/trunk/src/modules/notifications/Notification.cc	2010-09-11 14:16:10 UTC (rev 7412)
+++ code/trunk/src/modules/notifications/Notification.cc	2010-09-11 15:05:47 UTC (rev 7413)
@@ -103,7 +103,7 @@
     /**
     @brief
         Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues.
-    @param clientID
+    @param clientId
         The id of the client that this Notification is sent to.
     @param sender
         The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues.

Modified: code/trunk/src/modules/notifications/NotificationManager.cc
===================================================================
--- code/trunk/src/modules/notifications/NotificationManager.cc	2010-09-11 14:16:10 UTC (rev 7412)
+++ code/trunk/src/modules/notifications/NotificationManager.cc	2010-09-11 15:05:47 UTC (rev 7413)
@@ -128,7 +128,7 @@
         // Insert the Notification in all NotificationListeners that have its sender as target.
         for(std::map<NotificationListener*, unsigned int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all NotificationListeners.
         {
-            std::set<std::string, NotificationListenerStringCompare> set = it->first->getTargetsSet();
+            std::set<std::string, StringCompare> set = it->first->getTargetsSet();
             bool bAll = set.find(NotificationManager::ALL) != set.end();
             // If either the Notification has as sender 'all', the NotificationListener displays all Notifications or the NotificationListener has the sender of the Notification as target.
             if(all || bAll || set.find(notification->getSender()) != set.end())
@@ -209,7 +209,7 @@
 
         this->listenerList_[listener] = index; // Add the NotificationListener to the list of NotificationListeners.
 
-        std::set<std::string, NotificationListenerStringCompare> set = listener->getTargetsSet();
+        std::set<std::string, StringCompare> set = listener->getTargetsSet();
 
         // If all senders are the target of the NotificationListener, then the list of Notifications for that specific NotificationListener is the same as the list of all Notifications.
         bool bAll = set.find(NotificationManager::ALL) != set.end();
@@ -247,7 +247,6 @@
     {
         assert(listener);
 
-        //TODO: Make unsigned int.
         unsigned int identifier = this->listenerList_.find(listener)->second;
         std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second;
 

Modified: code/trunk/src/modules/notifications/NotificationQueue.cc
===================================================================
--- code/trunk/src/modules/notifications/NotificationQueue.cc	2010-09-11 14:16:10 UTC (rev 7412)
+++ code/trunk/src/modules/notifications/NotificationQueue.cc	2010-09-11 15:05:47 UTC (rev 7413)
@@ -68,7 +68,7 @@
 
         // Initialize.
         this->size_ = 0;
-        this->tickTime_ = 0.0;
+        this->tickTime_ = 0.0f;
 
         // Sets the input values.
         this->setTargets(senders);
@@ -76,15 +76,13 @@
         this->maxSize_ = size;
         this->setDisplayTime(displayTime);
 
-        //TODO: Destroy if registration fails?
-
         // Register the NotificationQueue with the NotificationManager.
         bool queueRegistered = NotificationManager::getInstance().registerQueue(this);
         this->registered_ = true;
         if(!queueRegistered) // If the registration has failed.
         {
             this->registered_ = false;
-            COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl;
+            COUT(1) << "Error: NotificationQueue '" << this->getName() << "' could not be registered." << std::endl;
             return;
         }
 
@@ -98,7 +96,7 @@
             // Remove the NotificationQueue in lua.
             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() +  "\")");
             NotificationManager::getInstance().unregisterQueue(this);
-            COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl;
+            COUT(1) << "Error: NotificationQueue '" << this->getName() << "' could not be registered." << std::endl;
             return;
         }
 
@@ -357,7 +355,7 @@
         std::stringstream stream;
         bool first = true;
         // Iterate through the set of targets.
-        for(std::set<std::string, NotificationListenerStringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++)
+        for(std::set<std::string, StringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++)
         {
             if(!first)
                 stream << ", ";

Modified: code/trunk/src/modules/notifications/NotificationQueue.h
===================================================================
--- code/trunk/src/modules/notifications/NotificationQueue.h	2010-09-11 14:16:10 UTC (rev 7412)
+++ code/trunk/src/modules/notifications/NotificationQueue.h	2010-09-11 15:05:47 UTC (rev 7413)
@@ -123,7 +123,7 @@
             @brief Returns the targets of this NotificationQueue, reps. the senders which Notifications are displayed in this NotificationQueue.
             @return Returns a set of strings holding the different targets.
             */
-            inline const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet()
+            inline const std::set<std::string, StringCompare> & getTargetsSet()
                 { return this->targets_; }
 
             // tolua_begin
@@ -143,7 +143,7 @@
 
             bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
 
-            std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the NotificationQueue displays Notifications of.
+            std::set<std::string, StringCompare> targets_; //!< The targets the NotificationQueue displays Notifications of.
 
             std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered.
             std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue.

Modified: code/trunk/src/orxonox/interfaces/NotificationListener.h
===================================================================
--- code/trunk/src/orxonox/interfaces/NotificationListener.h	2010-09-11 14:16:10 UTC (rev 7412)
+++ code/trunk/src/orxonox/interfaces/NotificationListener.h	2010-09-11 15:05:47 UTC (rev 7413)
@@ -40,6 +40,8 @@
 #include <set>
 #include <string>
 
+#include "util/StringUtils.h"
+
 #include "core/OrxonoxClass.h"
 
 namespace orxonox
@@ -48,17 +50,6 @@
 
     /**
     @brief
-        Struct that overloads the compare operation between two PickupIdentifier pointers.
-    */
-    //TODO: 
-    struct NotificationListenerStringCompare
-    {
-        bool operator() (const std::string& lhs, const std::string& rhs) const
-            { return lhs.compare(rhs) < 0; }
-    };
-
-    /**
-    @brief
         NotificationListener interface.
     @author
         Fabian 'x3n' Landau
@@ -69,7 +60,7 @@
             NotificationListener();
             virtual ~NotificationListener() {}
 
-            virtual const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet() = 0;
+            virtual const std::set<std::string, StringCompare> & getTargetsSet() = 0;
             virtual void update(void) = 0;
             virtual void update(Notification* notification, const std::time_t & time) = 0;
     };




More information about the Orxonox-commit mailing list