Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8516


Ignore:
Timestamp:
May 20, 2011, 3:58:29 AM (14 years ago)
Author:
rgrieder
Message:

Separate method in OutputHandler for updating the global debug level and using std::vector instead of std::list for the listeners.

Location:
code/branches/unity_build/src/libraries/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/unity_build/src/libraries/util/OutputHandler.cc

    r8515 r8516  
    231231    void OutputHandler::registerOutputListener(OutputListener* listener)
    232232    {
    233         for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
     233        for (std::vector<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
    234234        {
    235235            if ((*it)->name_ == listener->name_)
     
    240240        }
    241241        this->listeners_.push_back(listener);
    242         // Update global soft debug level
    243         this->setSoftDebugLevel(listener->getOutputListenerName(), listener->getSoftDebugLevel());
     242        this->updateGlobalDebugLevel();
    244243    }
    245244
    246245    void OutputHandler::unregisterOutputListener(OutputListener* listener)
    247246    {
    248         this->listeners_.remove(listener);
     247        for (std::vector<OutputListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
     248        {
     249            if ((*it)->name_ == listener->name_)
     250            {
     251                this->listeners_.erase(it);
     252                break;
     253            }
     254        }
     255        this->updateGlobalDebugLevel();
    249256    }
    250257
     
    278285    int OutputHandler::getSoftDebugLevel(const std::string& name) const
    279286    {
    280         for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
     287        for (std::vector<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
    281288        {
    282289            if ((*it)->name_ == name)
     
    288295    void OutputHandler::setSoftDebugLevel(const std::string& name, int level)
    289296    {
    290         int globalSoftDebugLevel = -1;
    291         for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
     297        for (std::vector<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
    292298        {
    293299            if ((*it)->name_ == name)
    294300                (*it)->softDebugLevel_ = level;
    295             if ((*it)->softDebugLevel_ > globalSoftDebugLevel)
    296                 globalSoftDebugLevel = (*it)->softDebugLevel_;
    297         }
    298         // Update global soft debug level
     301        }
     302        this->updateGlobalDebugLevel();
     303    }
     304
     305    void OutputHandler::updateGlobalDebugLevel()
     306    {
     307        int globalSoftDebugLevel = -1;
     308        std::vector<OutputListener*>::const_iterator it = this->listeners_.begin();
     309        for (; it != this->listeners_.end(); ++it)
     310            globalSoftDebugLevel = std::max(globalSoftDebugLevel, (*it)->softDebugLevel_);
     311
    299312        OutputHandler::softDebugLevel_s = globalSoftDebugLevel;
    300313    }
  • code/branches/unity_build/src/libraries/util/OutputHandler.h

    r8515 r8516  
    3939#include "UtilPrereqs.h"
    4040
    41 #include <list>
    4241#include <ostream>
    4342#include <string>
     
    221220            OutputHandler(const OutputHandler& rhs);      //!< Copy-constructor: Unused and undefined
    222221
    223             std::list<OutputListener*> listeners_;        //!< Array with all registered output listeners
    224             int                        outputLevel_;      //!< The level of the incoming output
    225             LogFileWriter*             logFile_;          //!< Listener that writes to the log file
    226             ConsoleWriter*             consoleWriter_;    //!< Listener for std::cout (just program beginning)
    227             MemoryLogWriter*           memoryBuffer_;     //!< Writes to memory as a buffer (can/must be stopped at some time)
    228             static int                 softDebugLevel_s;  //!< Maximum of all soft debug levels. @note This is only static for faster access
     222            /// Evaluates the maximum global log level
     223            void updateGlobalDebugLevel();
     224
     225            std::vector<OutputListener*> listeners_;        //!< Array with all registered output listeners
     226            int                          outputLevel_;      //!< The level of the incoming output
     227            LogFileWriter*               logFile_;          //!< Writes output to the log file
     228            ConsoleWriter*               consoleWriter_;    //!< Writes to std::cout (can be disabled)
     229            MemoryLogWriter*             memoryBuffer_;     //!< Writes to memory as a buffer (can/must be stopped at some time)
     230            static int                   softDebugLevel_s;  //!< Maximum of all soft debug levels. @note This is only static for faster access
    229231    };
    230232
     
    271273    inline OutputHandler& OutputHandler::output(const T& output)
    272274    {
    273         for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
     275        for (std::vector<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
    274276        {
    275277            if (this->outputLevel_ <= (*it)->softDebugLevel_ && (*it)->outputStream_ != NULL)
Note: See TracChangeset for help on using the changeset viewer.