[Orxonox-commit 3840] r8516 - code/branches/unity_build/src/libraries/util

rgrieder at orxonox.net rgrieder at orxonox.net
Fri May 20 03:58:30 CEST 2011


Author: rgrieder
Date: 2011-05-20 03:58:29 +0200 (Fri, 20 May 2011)
New Revision: 8516

Modified:
   code/branches/unity_build/src/libraries/util/OutputHandler.cc
   code/branches/unity_build/src/libraries/util/OutputHandler.h
Log:
Separate method in OutputHandler for updating the global debug level and using std::vector instead of std::list for the listeners.

Modified: code/branches/unity_build/src/libraries/util/OutputHandler.cc
===================================================================
--- code/branches/unity_build/src/libraries/util/OutputHandler.cc	2011-05-20 01:53:21 UTC (rev 8515)
+++ code/branches/unity_build/src/libraries/util/OutputHandler.cc	2011-05-20 01:58:29 UTC (rev 8516)
@@ -230,7 +230,7 @@
 
     void OutputHandler::registerOutputListener(OutputListener* listener)
     {
-        for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
+        for (std::vector<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
         {
             if ((*it)->name_ == listener->name_)
             {
@@ -239,13 +239,20 @@
             }
         }
         this->listeners_.push_back(listener);
-        // Update global soft debug level
-        this->setSoftDebugLevel(listener->getOutputListenerName(), listener->getSoftDebugLevel());
+        this->updateGlobalDebugLevel();
     }
 
     void OutputHandler::unregisterOutputListener(OutputListener* listener)
     {
-        this->listeners_.remove(listener);
+        for (std::vector<OutputListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
+        {
+            if ((*it)->name_ == listener->name_)
+            {
+                this->listeners_.erase(it);
+                break;
+            }
+        }
+        this->updateGlobalDebugLevel();
     }
 
     void OutputHandler::setLogPath(const std::string& path)
@@ -277,7 +284,7 @@
 
     int OutputHandler::getSoftDebugLevel(const std::string& name) const
     {
-        for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
+        for (std::vector<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
         {
             if ((*it)->name_ == name)
                 return (*it)->softDebugLevel_;
@@ -287,15 +294,21 @@
 
     void OutputHandler::setSoftDebugLevel(const std::string& name, int level)
     {
-        int globalSoftDebugLevel = -1;
-        for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
+        for (std::vector<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
         {
             if ((*it)->name_ == name)
                 (*it)->softDebugLevel_ = level;
-            if ((*it)->softDebugLevel_ > globalSoftDebugLevel)
-                globalSoftDebugLevel = (*it)->softDebugLevel_;
         }
-        // Update global soft debug level
+        this->updateGlobalDebugLevel();
+    }
+
+    void OutputHandler::updateGlobalDebugLevel()
+    {
+        int globalSoftDebugLevel = -1;
+        std::vector<OutputListener*>::const_iterator it = this->listeners_.begin();
+        for (; it != this->listeners_.end(); ++it)
+            globalSoftDebugLevel = std::max(globalSoftDebugLevel, (*it)->softDebugLevel_);
+
         OutputHandler::softDebugLevel_s = globalSoftDebugLevel;
     }
 }

Modified: code/branches/unity_build/src/libraries/util/OutputHandler.h
===================================================================
--- code/branches/unity_build/src/libraries/util/OutputHandler.h	2011-05-20 01:53:21 UTC (rev 8515)
+++ code/branches/unity_build/src/libraries/util/OutputHandler.h	2011-05-20 01:58:29 UTC (rev 8516)
@@ -38,7 +38,6 @@
 
 #include "UtilPrereqs.h"
 
-#include <list>
 #include <ostream>
 #include <string>
 #include <vector>
@@ -220,12 +219,15 @@
             ~OutputHandler();
             OutputHandler(const OutputHandler& rhs);      //!< Copy-constructor: Unused and undefined
 
-            std::list<OutputListener*> listeners_;        //!< Array with all registered output listeners
-            int                        outputLevel_;      //!< The level of the incoming output
-            LogFileWriter*             logFile_;          //!< Listener that writes to the log file
-            ConsoleWriter*             consoleWriter_;    //!< Listener for std::cout (just program beginning)
-            MemoryLogWriter*           memoryBuffer_;     //!< Writes to memory as a buffer (can/must be stopped at some time)
-            static int                 softDebugLevel_s;  //!< Maximum of all soft debug levels. @note This is only static for faster access
+            /// Evaluates the maximum global log level
+            void updateGlobalDebugLevel();
+
+            std::vector<OutputListener*> listeners_;        //!< Array with all registered output listeners
+            int                          outputLevel_;      //!< The level of the incoming output
+            LogFileWriter*               logFile_;          //!< Writes output to the log file
+            ConsoleWriter*               consoleWriter_;    //!< Writes to std::cout (can be disabled)
+            MemoryLogWriter*             memoryBuffer_;     //!< Writes to memory as a buffer (can/must be stopped at some time)
+            static int                   softDebugLevel_s;  //!< Maximum of all soft debug levels. @note This is only static for faster access
     };
 
     /**
@@ -270,7 +272,7 @@
     template<class T>
     inline OutputHandler& OutputHandler::output(const T& output)
     {
-        for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
+        for (std::vector<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
         {
             if (this->outputLevel_ <= (*it)->softDebugLevel_ && (*it)->outputStream_ != NULL)
             {




More information about the Orxonox-commit mailing list