Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

A context is now defined by a struct instead of only a mask.

Introduced sub-contexts. Sub-contexts of the same main-context share the same mask, but have a different ID.
Main-contexts are filtered using a bitmask which happens for every line of output and is very fast.
Sub-contexts are filtered using a set which is slow but happens only if a specific sub-context is enabled in the config file which is usually not the case.

The concept of filtering normal output + additional contexts was moved from BaseWriter directly to OutputListener and OutputManager which makes the whole system faster.
BaseWriter now calls registerContext() for each configured output context, which basically allows the usage of more than 64 contexts as long as these contexts are not used before loading the config file. Though by design it's not recommended.

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