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 "SubcontextOutputListener.h" |
---|
30 | |
---|
31 | namespace orxonox |
---|
32 | { |
---|
33 | SubcontextOutputListener::SubcontextOutputListener(bool bRegister) : OutputListener(bRegister) |
---|
34 | { |
---|
35 | this->subcontextsCheckMask_ = context::none; |
---|
36 | this->subcontextsNoCheckMask_ = context::none; |
---|
37 | } |
---|
38 | |
---|
39 | SubcontextOutputListener::~SubcontextOutputListener() |
---|
40 | { |
---|
41 | } |
---|
42 | |
---|
43 | void SubcontextOutputListener::setAdditionalContextsMask(OutputContextMask mask) |
---|
44 | { |
---|
45 | this->subcontextsNoCheckMask_ = mask; |
---|
46 | |
---|
47 | OutputListener::setAdditionalContextsMask(this->subcontextsCheckMask_ | this->subcontextsNoCheckMask_); |
---|
48 | } |
---|
49 | |
---|
50 | void SubcontextOutputListener::setAdditionalSubcontexts(const std::set<const OutputContextContainer*>& subcontexts) |
---|
51 | { |
---|
52 | this->subcontextsCheckMask_ = context::none; |
---|
53 | this->subcontexts_.clear(); |
---|
54 | |
---|
55 | for (std::set<const OutputContextContainer*>::const_iterator it = subcontexts.begin(); it != subcontexts.end(); ++it) |
---|
56 | { |
---|
57 | this->subcontextsCheckMask_ |= (*it)->mask; |
---|
58 | this->subcontexts_.insert((*it)->sub_id); |
---|
59 | } |
---|
60 | |
---|
61 | OutputListener::setAdditionalContextsMask(this->subcontextsCheckMask_ | this->subcontextsNoCheckMask_); |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | @brief Returns true if this listener accepts output of the given level and context, based on the levels, contexts masks, and sub-contexts. |
---|
66 | */ |
---|
67 | bool SubcontextOutputListener::acceptsOutput(OutputLevel level, const OutputContextContainer& context) const |
---|
68 | { |
---|
69 | // check if the output level is accepted by the level mask (independent of the context) |
---|
70 | if (this->getLevelMask() & level) |
---|
71 | return true; |
---|
72 | |
---|
73 | // check if the output level is accepted by the additional contexts level mask |
---|
74 | if (this->getAdditionalContextsLevelMask() & level) |
---|
75 | { |
---|
76 | // check if the output context is accepted by the "no check" mask |
---|
77 | if (this->subcontextsNoCheckMask_ & context.mask) |
---|
78 | return true; |
---|
79 | |
---|
80 | // check if the output context is accepted by the "check" mask |
---|
81 | if (this->subcontextsCheckMask_ & context.mask) |
---|
82 | { |
---|
83 | // check if the output's subcontext is in the set of accepted sub-context |
---|
84 | if (this->subcontexts_.find(context.sub_id) != this->subcontexts_.end()) |
---|
85 | return true; |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | // otherwise we don't accept the output |
---|
90 | return false; |
---|
91 | } |
---|
92 | } |
---|