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) |
---|
36 | { |
---|
37 | this->name_ = name; |
---|
38 | |
---|
39 | this->configurableMaxLevel_ = level::none; |
---|
40 | this->configurableContextsMaxLevel_ = level::verbose; |
---|
41 | } |
---|
42 | |
---|
43 | BaseWriter::~BaseWriter() |
---|
44 | { |
---|
45 | } |
---|
46 | |
---|
47 | void BaseWriter::output(OutputLevel level, OutputContext context, const std::vector<std::string>& lines) |
---|
48 | { |
---|
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(), ' '); |
---|
53 | |
---|
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()); |
---|
83 | } |
---|
84 | } |
---|