Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 30, 2011, 7:51:08 PM (13 years ago)
Author:
landauf
Message:

Code related to config values for output is now implemented in BaseWriter.
There's a config value for the normal output level, a vector with additional contexts, and a config value for the level of these additional contexts.
ioconsole and standard console use the same values.

Location:
code/branches/output/src/libraries/util/output
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/output/src/libraries/util/output/BaseWriter.cc

    r8795 r8799  
    3333namespace orxonox
    3434{
    35     BaseWriter::BaseWriter()
     35    BaseWriter::BaseWriter(const std::string& name)
    3636    {
     37        this->name_ = name;
     38
     39        this->configurableMaxLevel_ = level::none;
     40        this->configurableContextsMaxLevel_ = level::verbose;
    3741    }
    3842
     
    4347    void BaseWriter::output(OutputLevel level, OutputContext context, const std::vector<std::string>& lines)
    4448    {
    45         const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context);
    46         std::string blanks(prefix.length(), ' ');
     49        if (level <= this->configurableMaxLevel_ || (level <= this->configurableContextsMaxLevel_ && this->isAdditionalContext(context)))
     50        {
     51            const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context);
     52            std::string blanks(prefix.length(), ' ');
    4753
    48         for (size_t i = 0; i < lines.size(); ++i)
    49             this->printLine((i == 0 ? prefix : blanks) + lines[i], level);
     54            for (size_t i = 0; i < lines.size(); ++i)
     55                this->printLine((i == 0 ? prefix : blanks) + lines[i], level);
     56        }
     57    }
     58
     59    void BaseWriter::setLevelMax(OutputLevel max)
     60    {
     61        this->configurableMaxLevel_ = max;
     62        this->changedConfigurableLevels();
     63    }
     64
     65    void BaseWriter::changedConfigurableLevels()
     66    {
     67        OutputLevel max_level = std::max(this->configurableMaxLevel_, this->configurableContextsMaxLevel_);
     68        OutputListener::setLevelMax(max_level);
     69    }
     70
     71    void BaseWriter::changedConfigurableContexts()
     72    {
     73        this->configurableContextsSet_.clear();
     74        for (size_t i = 0; i < this->configurableContexts_.size(); ++i)
     75            this->configurableContextsSet_.insert(this->configurableContexts_[i]);
     76    }
     77
     78    bool BaseWriter::isAdditionalContext(OutputContext context) const
     79    {
     80        const std::string& name = OutputManager::getInstance().getContextName(context);
     81        std::set<std::string>::const_iterator it = this->configurableContextsSet_.find(name);
     82        return (it != this->configurableContextsSet_.end());
    5083    }
    5184}
  • code/branches/output/src/libraries/util/output/BaseWriter.h

    r8795 r8799  
    3131
    3232#include "util/UtilPrereqs.h"
     33
     34#include <set>
     35#include <vector>
     36
    3337#include "OutputListener.h"
    3438
     
    3842    {
    3943        public:
    40             BaseWriter();
     44            BaseWriter(const std::string& name);
    4145            virtual ~BaseWriter();
     46
     47            const std::string& getName() const
     48                { return this->name_; }
     49
     50            void setLevelMax(OutputLevel max);
     51
     52            OutputLevel configurableMaxLevel_;
     53            inline std::string getConfigurableMaxLevelName() const
     54                { return "outputLevel" + this->name_; }
     55
     56            OutputLevel configurableContextsMaxLevel_;
     57            inline std::string getConfigurableContextsMaxLevelName() const
     58                { return "outputContextsLevel" + this->name_; }
     59
     60            std::vector<std::string> configurableContexts_;
     61            inline std::string getConfigurableContextsName() const
     62                { return "outputContexts" + this->name_; }
     63
     64            void changedConfigurableLevels();
     65            void changedConfigurableContexts();
     66
     67            static inline std::string getConfigurableSectionName()
     68                { return "Output"; }
    4269
    4370        protected:
     
    4673        private:
    4774            virtual void printLine(const std::string& line, OutputLevel level) = 0;
     75
     76            void setLevelRange(OutputLevel min, OutputLevel max);
     77            void setLevelMask(OutputLevel mask);
     78
     79            bool isAdditionalContext(OutputContext context) const;
     80
     81            std::string name_;
     82            std::set<std::string> configurableContextsSet_;
    4883    };
    4984}
  • code/branches/output/src/libraries/util/output/ConsoleWriter.cc

    r8795 r8799  
    3535namespace orxonox
    3636{
    37     ConsoleWriter::ConsoleWriter()
     37    ConsoleWriter::ConsoleWriter() : BaseWriter("Console")
    3838    {
    3939#ifdef ORXONOX_RELEASE
  • code/branches/output/src/libraries/util/output/LogWriter.cc

    r8795 r8799  
    3636namespace orxonox
    3737{
    38     LogWriter::LogWriter()
     38    LogWriter::LogWriter() : BaseWriter("Log")
    3939    {
    4040        this->setLevelMax(level::internal_info);
    4141
    42         this->filename_ = "orxonox2.log";
     42        this->filename_ = "orxonox.log";
    4343
    4444        // Get path for a temporary file
  • code/branches/output/src/libraries/util/output/OutputDefinitions.h

    r8798 r8799  
    4444        static const OutputLevel all              = 0xFFFF;
    4545        static const OutputLevel none             = 0x0000;
     46
    4647        static const OutputLevel debug_output     = 0x0001;
    4748        static const OutputLevel user_error       = 0x0002;
  • code/branches/output/src/libraries/util/output/OutputManager.cc

    r8787 r8799  
    166166    }
    167167
     168    OutputContext OutputManager::getContextValue(const std::string& name) const
     169    {
     170        boost::bimap<OutputContext, std::string>::right_map::const_iterator it = this->contexts_.right.find(name);
     171        if (it != this->contexts_.right.end())
     172            return it->second;
     173        else
     174            return context::none;
     175    }
     176
    168177    std::string OutputManager::getComposedContextName(OutputContext context) const
    169178    {
  • code/branches/output/src/libraries/util/output/OutputManager.h

    r8787 r8799  
    6666            const std::string& getLevelName(OutputLevel level) const;
    6767            const std::string& getContextName(OutputContext context) const;
     68            OutputContext getContextValue(const std::string& name) const;
     69
    6870            std::string getComposedContextName(OutputContext context) const;
    6971            std::string getDefaultPrefix(OutputLevel level, OutputContext context) const;
Note: See TracChangeset for help on using the changeset viewer.