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