Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/output/src/libraries/util/output/BaseWriter.cc @ 8831

Last change on this file since 8831 was 8831, checked in by landauf, 13 years ago

fixed wrong config value callback in Shell
fixed bug in ConfigFileManager: if a vector contained only one element at index 0, size 0 instead of 1 was returned
removed output context "output"
the configurable vector of output contexts now contains "example" as default to make the config vector visible in the config file

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "BaseWriter.h"
30
31#include "OutputManager.h"
32
33namespace orxonox
34{
35    BaseWriter::BaseWriter(const std::string& name)
36    {
37        this->name_ = name;
38
39        this->configurableMaxLevel_ = level::none;
40        this->configurableContextsMaxLevel_ = level::verbose;
41        this->configurableContexts_.push_back("example");
42        this->changedConfigurableLevels();
43    }
44
45    BaseWriter::~BaseWriter()
46    {
47    }
48
49    void BaseWriter::output(OutputLevel level, OutputContext context, const std::vector<std::string>& lines)
50    {
51        if (level <= this->configurableMaxLevel_ || (level <= this->configurableContextsMaxLevel_ && this->isAdditionalContext(context)))
52        {
53            const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context);
54            std::string blanks(prefix.length(), ' ');
55
56            for (size_t i = 0; i < lines.size(); ++i)
57                this->printLine((i == 0 ? prefix : blanks) + lines[i], level);
58        }
59    }
60
61    void BaseWriter::setLevelMax(OutputLevel max)
62    {
63        this->configurableMaxLevel_ = max;
64        this->changedConfigurableLevels();
65    }
66
67    void BaseWriter::changedConfigurableLevels()
68    {
69        int max_level = std::max(this->configurableMaxLevel_, this->configurableContextsMaxLevel_);
70        OutputListener::setLevelMax(static_cast<OutputLevel>(max_level));
71    }
72
73    void BaseWriter::changedConfigurableContexts()
74    {
75        this->configurableContextsSet_.clear();
76        for (size_t i = 0; i < this->configurableContexts_.size(); ++i)
77            this->configurableContextsSet_.insert(this->configurableContexts_[i]);
78    }
79
80    bool BaseWriter::isAdditionalContext(OutputContext context) const
81    {
82        const std::string& name = OutputManager::getInstance().getContextName(context);
83        std::set<std::string>::const_iterator it = this->configurableContextsSet_.find(name);
84        return (it != this->configurableContextsSet_.end());
85    }
86}
Note: See TracBrowser for help on using the repository browser.