Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/SuperOrxoBros_HS18/src/libraries/util/output/SubcontextOutputListener.cc @ 12175

Last change on this file since 12175 was 12175, checked in by siramesh, 5 years ago

Super Orxo Bros (Sidharth Ramesh, Nisa Balta, Jeff Ren)

File size: 4.1 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/**
30    @file
31    @brief Implementation of the SubcontextOutputListener interface.
32*/
33
34#include "SubcontextOutputListener.h"
35
36namespace orxonox
37{
38    /**
39        @brief Constructor, initializes the context masks.
40    */
41    SubcontextOutputListener::SubcontextOutputListener(bool bRegister) : OutputListener(bRegister)
42    {
43        this->subcontextsCheckMask_ = context::none;
44        this->subcontextsNoCheckMask_ = context::none;
45    }
46
47    /**
48        @brief Destructor.
49    */
50    SubcontextOutputListener::~SubcontextOutputListener()
51    {
52    }
53
54    /**
55        @brief Overwritten implementation of the function defined by OutputListener.
56
57        Contexts defined with this function are accepted independent of the
58        sub-context. The "final" mask of additional contexts is defined by the
59        combination of this mask and the masks of all accepted sub-contexts.
60    */
61    void SubcontextOutputListener::setAdditionalContextsMask(OutputContextMask mask)
62    {
63        this->subcontextsNoCheckMask_ = mask;
64
65        OutputListener::setAdditionalContextsMask(this->subcontextsCheckMask_ | this->subcontextsNoCheckMask_);
66    }
67
68    /**
69        @brief Defines the set of accepted sub-contexts.
70
71        The masks of sub-contexts in this set are added to the mask of
72        additional contexts, but output is only accepted if the exact
73        sub-context exists in this set.
74    */
75    void SubcontextOutputListener::setAdditionalSubcontexts(const std::set<const OutputContextContainer*>& subcontexts)
76    {
77        this->subcontextsCheckMask_ = context::none;
78        this->subcontexts_.clear();
79
80        // compose the mask of subcontexts and build the set of sub-context-IDs
81        for (const OutputContextContainer* subcontext : subcontexts)
82        {
83            this->subcontextsCheckMask_ |= subcontext->mask;
84            this->subcontexts_.insert(subcontext->sub_id);
85        }
86
87        OutputListener::setAdditionalContextsMask(this->subcontextsCheckMask_ | this->subcontextsNoCheckMask_);
88    }
89
90    /**
91        @brief Returns true if this listener accepts output of the given level and context, based on the levels and contexts masks, as well as the set of accepted sub-contexts.
92    */
93    bool SubcontextOutputListener::acceptsOutput(OutputLevel level, const OutputContextContainer& context) const
94    {
95        // check if the output level is accepted by the level mask (independent of the context)
96        if (this->getLevelMask() & level)
97            return true;
98
99        // check if the output level is accepted by the additional contexts level mask
100        if (this->getAdditionalContextsLevelMask() & level)
101        {
102            // check if the output context is accepted by the "no check" mask
103            if (this->subcontextsNoCheckMask_ & context.mask)
104                return true;
105
106            // check if the output context is accepted by the "check" mask
107            if (this->subcontextsCheckMask_ & context.mask)
108            {
109                // check if the output's subcontext is in the set of accepted sub-context
110                if (this->subcontexts_.find(context.sub_id) != this->subcontexts_.end())
111                    return true;
112            }
113        }
114
115        // otherwise we don't accept the output
116        return false;
117    }
118}
Note: See TracBrowser for help on using the repository browser.