Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

moved filtering of sub-contexts from BaseWriter to a new interface SubcontextOutputListener

  • Property svn:eol-style set to native
File size: 3.7 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, bool bRegister) : SubcontextOutputListener(bRegister)
36    {
37        this->name_ = name;
38
39        this->configurableMaxLevel_ = level::none;
40        this->configurableAdditionalContextsMaxLevel_ = level::verbose;
41        this->configurableAdditionalContexts_.push_back("example");
42
43        this->changedConfigurableLevel();
44        this->changedConfigurableAdditionalContextsLevel();
45        this->changedConfigurableAdditionalContexts();
46    }
47
48    BaseWriter::~BaseWriter()
49    {
50    }
51
52    void BaseWriter::output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines)
53    {
54        const std::string& prefix = OutputManager::getInstance().getDefaultPrefix(level, context);
55        std::string blanks(prefix.length(), ' ');
56
57        for (size_t i = 0; i < lines.size(); ++i)
58            this->printLine((i == 0 ? prefix : blanks) + lines[i], level);
59    }
60
61    void BaseWriter::setLevelMax(OutputLevel max)
62    {
63        this->configurableMaxLevel_ = max;
64        this->changedConfigurableLevel();
65    }
66
67    void BaseWriter::setAdditionalContextsLevelMax(OutputLevel max)
68    {
69        this->configurableAdditionalContextsMaxLevel_ = max;
70        this->changedConfigurableAdditionalContextsLevel();
71    }
72
73    void BaseWriter::changedConfigurableLevel()
74    {
75        OutputListener::setLevelMax(static_cast<OutputLevel>(this->configurableMaxLevel_));
76    }
77
78    void BaseWriter::changedConfigurableAdditionalContextsLevel()
79    {
80        OutputListener::setAdditionalContextsLevelMax(static_cast<OutputLevel>(this->configurableAdditionalContextsMaxLevel_));
81    }
82
83    void BaseWriter::changedConfigurableAdditionalContexts()
84    {
85        OutputContextMask main_contexts = context::none;
86        std::set<const OutputContextContainer*> sub_contexts;
87
88        for (size_t i = 0; i < this->configurableAdditionalContexts_.size(); ++i)
89        {
90            const std::string& full_name = this->configurableAdditionalContexts_[i];
91
92            std::string name = full_name;
93            std::string subname;
94
95            size_t pos = full_name.find("::");
96            if (pos != std::string::npos)
97            {
98                name = full_name.substr(0, pos);
99                subname = full_name.substr(pos + 2);
100            }
101
102            const OutputContextContainer& context = OutputManager::getInstance().registerContext(name, subname);
103
104            if (context.sub_id == context::no_subcontext)
105                main_contexts |= context.mask;
106            else
107                sub_contexts.insert(&context);
108        }
109
110        this->setAdditionalContextsMask(main_contexts);
111        this->setAdditionalSubcontexts(sub_contexts);
112    }
113}
Note: See TracBrowser for help on using the repository browser.