Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 24, 2013, 4:26:33 PM (12 years ago)
Author:
landauf
Message:

small refactoring in output system

Location:
code/branches/testing/src/libraries/util
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/testing/src/libraries/util/UtilPrereqs.h

    r8858 r9530  
    8484namespace orxonox
    8585{
     86    class AdditionalContextListener;
    8687    class Clock;
    8788    class Exception;
  • code/branches/testing/src/libraries/util/output/OutputListener.cc

    r8858 r9530  
    6262
    6363    /**
     64        @brief Adds a listener to the list.
     65    */
     66    void OutputListener::registerListener(AdditionalContextListener* listener)
     67    {
     68        this->listeners_.push_back(listener);
     69    }
     70
     71    /**
     72        @brief Removes a listener from the list.
     73    */
     74    void OutputListener::unregisterListener(AdditionalContextListener* listener)
     75    {
     76        for (std::vector<AdditionalContextListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
     77        {
     78            if (*it == listener)
     79            {
     80                this->listeners_.erase(it);
     81                break;
     82            }
     83        }
     84    }
     85
     86    /**
    6487        @brief Defines the level mask in a way which accepts all output up to the level \c max.
    6588    */
     
    88111        this->levelMask_ = mask;
    89112
    90         OutputManager::getInstance().updateCombinedLevelMask();
     113        for (size_t i = 0; i < this->listeners_.size(); ++i)
     114            this->listeners_[i]->updatedLevelMask(this);
    91115    }
    92116
     
    118142        this->additionalContextsLevelMask_ = mask;
    119143
    120         OutputManager::getInstance().updateCombinedAdditionalContextsLevelMask();
     144        for (size_t i = 0; i < this->listeners_.size(); ++i)
     145            this->listeners_[i]->updatedAdditionalContextsLevelMask(this);
    121146    }
    122147
     
    128153        this->additionalContextsMask_ = mask;
    129154
    130         OutputManager::getInstance().updateCombinedAdditionalContextsMask();
     155        for (size_t i = 0; i < this->listeners_.size(); ++i)
     156            this->listeners_[i]->updatedAdditionalContextsMask(this);
    131157    }
    132158
  • code/branches/testing/src/libraries/util/output/OutputListener.h

    r8858 r9530  
    5555            virtual ~OutputListener();
    5656
     57            void registerListener(AdditionalContextListener* listener);
     58            void unregisterListener(AdditionalContextListener* listener);
     59
    5760            void setLevelMax(OutputLevel max);
    5861            void setLevelRange(OutputLevel min, OutputLevel max);
     
    8588            virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) = 0;
    8689
     90            inline const std::vector<AdditionalContextListener*>& getListeners() const
     91                { return this->listeners_; }
     92
    8793        private:
    88             OutputLevel       levelMask_;                   ///< Mask of accepted output levels, independent of contexts
    89             OutputContextMask additionalContextsMask_;      ///< Mask of accepted additional contexts
    90             OutputLevel       additionalContextsLevelMask_; ///< Mask of accepted output levels of the additional contexts
     94            std::vector<AdditionalContextListener*> listeners_; ///< List of all registered additional context listeners
     95
     96            OutputLevel       levelMask_;                       ///< Mask of accepted output levels, independent of contexts
     97            OutputContextMask additionalContextsMask_;          ///< Mask of accepted additional contexts
     98            OutputLevel       additionalContextsLevelMask_;     ///< Mask of accepted output levels of the additional contexts
    9199    };
    92100
  • code/branches/testing/src/libraries/util/output/OutputManager.cc

    r8858 r9530  
    113113    void OutputManager::registerListener(OutputListener* listener)
    114114    {
     115        listener->registerListener(this);
    115116        this->listeners_.push_back(listener);
    116117        this->updateMasks();
     
    122123    void OutputManager::unregisterListener(OutputListener* listener)
    123124    {
     125        listener->unregisterListener(this);
    124126        for (std::vector<OutputListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
    125127        {
  • code/branches/testing/src/libraries/util/output/OutputManager.h

    r8858 r9530  
    4343
    4444#include "OutputDefinitions.h"
     45#include "AdditionalContextListener.h"
    4546
    4647namespace orxonox
     
    6162        Additionally OutputManager is used to register output contexts.
    6263    */
    63     class _UtilExport OutputManager
     64    class _UtilExport OutputManager : public AdditionalContextListener
    6465    {
    6566        public:
     
    7273            void unregisterListener(OutputListener* listener);
    7374
    74             void updateMasks();
    75             void updateCombinedLevelMask();
    76             void updateCombinedAdditionalContextsLevelMask();
    77             void updateCombinedAdditionalContextsMask();
     75            virtual void updatedLevelMask(const OutputListener* listener)
     76                { this->updateCombinedLevelMask(); }
     77            virtual void updatedAdditionalContextsLevelMask(const OutputListener* listener)
     78                { this->updateCombinedAdditionalContextsLevelMask(); }
     79            virtual void updatedAdditionalContextsMask(const OutputListener* listener)
     80                { this->updateCombinedAdditionalContextsMask(); }
    7881
    7982            /**
     
    9598            std::string getDefaultPrefix(OutputLevel level, const OutputContextContainer& context) const;
    9699
     100        protected:
     101            inline const std::vector<OutputListener*>& getListeners() const
     102                { return this->listeners_; }
     103
    97104        private:
    98105            OutputManager();
    99106            OutputManager(const OutputManager&);
    100107            ~OutputManager();
     108
     109            void updateMasks();
     110            void updateCombinedLevelMask();
     111            void updateCombinedAdditionalContextsLevelMask();
     112            void updateCombinedAdditionalContextsMask();
    101113
    102114            std::vector<OutputListener*> listeners_;                            ///< List of all registered output listeners
Note: See TracChangeset for help on using the changeset viewer.