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 "OutputManager.h" |
---|
30 | |
---|
31 | #include "util/Debug.h" |
---|
32 | #include "OutputListener.h" |
---|
33 | |
---|
34 | namespace orxonox |
---|
35 | { |
---|
36 | namespace test |
---|
37 | { |
---|
38 | class ConsoleOutput : public OutputListener |
---|
39 | { |
---|
40 | public: |
---|
41 | ConsoleOutput() |
---|
42 | { |
---|
43 | this->setLevelMax(level::user_info); |
---|
44 | } |
---|
45 | |
---|
46 | protected: |
---|
47 | virtual void output(OutputLevel level, OutputContext context, const std::string& message) |
---|
48 | { |
---|
49 | COUT(0) << (int)level << " / " << context << " : " << message << endl; |
---|
50 | } |
---|
51 | }; |
---|
52 | |
---|
53 | OutputManager::OutputManager() |
---|
54 | { |
---|
55 | this->combinedLevelMask_ = 0; |
---|
56 | this->combinedContextMask_ = 0; |
---|
57 | } |
---|
58 | |
---|
59 | OutputManager::~OutputManager() |
---|
60 | { |
---|
61 | } |
---|
62 | |
---|
63 | /*static*/ OutputManager& OutputManager::getInstance() |
---|
64 | { |
---|
65 | static OutputManager& instance = OutputManager::getInstanceInternal(); |
---|
66 | static ConsoleOutput consoleOutputInstance; |
---|
67 | return instance; |
---|
68 | } |
---|
69 | |
---|
70 | /*static*/ OutputManager& OutputManager::getInstanceInternal() |
---|
71 | { |
---|
72 | static OutputManager instance; |
---|
73 | return instance; |
---|
74 | } |
---|
75 | |
---|
76 | void OutputManager::pushMessage(OutputLevel level, OutputContext context, const std::string& message) |
---|
77 | { |
---|
78 | for (size_t i = 0; i < this->listeners_.size(); ++i) |
---|
79 | if (this->listeners_[i]->acceptsOutput(level, context)) |
---|
80 | this->listeners_[i]->output(level, context, message); |
---|
81 | } |
---|
82 | |
---|
83 | void OutputManager::registerListener(OutputListener* listener) |
---|
84 | { |
---|
85 | this->listeners_.push_back(listener); |
---|
86 | this->updateMasks(); |
---|
87 | } |
---|
88 | |
---|
89 | void OutputManager::unregisterListener(OutputListener* listener) |
---|
90 | { |
---|
91 | for (std::vector<OutputListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) |
---|
92 | { |
---|
93 | if (*it == listener) |
---|
94 | { |
---|
95 | this->listeners_.erase(it); |
---|
96 | break; |
---|
97 | } |
---|
98 | } |
---|
99 | this->updateMasks(); |
---|
100 | } |
---|
101 | |
---|
102 | void OutputManager::updateMasks() |
---|
103 | { |
---|
104 | this->updateCombinedLevelMask(); |
---|
105 | this->updateCombinedContextMask(); |
---|
106 | } |
---|
107 | |
---|
108 | void OutputManager::updateCombinedLevelMask() |
---|
109 | { |
---|
110 | this->combinedLevelMask_ = 0; |
---|
111 | for (size_t i = 0; i < this->listeners_.size(); ++i) |
---|
112 | this->combinedLevelMask_ |= this->listeners_[i]->getLevelMask(); |
---|
113 | } |
---|
114 | |
---|
115 | void OutputManager::updateCombinedContextMask() |
---|
116 | { |
---|
117 | this->combinedContextMask_ = 0; |
---|
118 | for (size_t i = 0; i < this->listeners_.size(); ++i) |
---|
119 | this->combinedContextMask_ |= this->listeners_[i]->getContextMask(); |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|