[8765] | 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 | |
---|
[8848] | 29 | /** |
---|
| 30 | @file |
---|
| 31 | @brief Implementation of the OutputListener class. |
---|
| 32 | */ |
---|
| 33 | |
---|
[8765] | 34 | #include "OutputListener.h" |
---|
| 35 | |
---|
| 36 | #include "OutputManager.h" |
---|
| 37 | |
---|
| 38 | namespace orxonox |
---|
| 39 | { |
---|
[8848] | 40 | /** |
---|
| 41 | @brief Constructor, initializes the values and registers the instance at OutputManager if requested. |
---|
| 42 | @param bRegister If \c true, the instance is automatically registered at OutputManager. |
---|
| 43 | Should be \c false if the constructor of the derived class generates output. |
---|
| 44 | */ |
---|
[8834] | 45 | OutputListener::OutputListener(bool bRegister) |
---|
[8765] | 46 | { |
---|
| 47 | this->levelMask_ = level::none; |
---|
[8833] | 48 | this->additionalContextsLevelMask_ = level::none; |
---|
| 49 | this->additionalContextsMask_ = context::none; |
---|
[8765] | 50 | |
---|
[8834] | 51 | if (bRegister) |
---|
| 52 | OutputManager::getInstance().registerListener(this); |
---|
[8765] | 53 | } |
---|
| 54 | |
---|
[8848] | 55 | /** |
---|
| 56 | @brief Destructor, unregisters the instance from OutputManager. |
---|
| 57 | */ |
---|
[8765] | 58 | OutputListener::~OutputListener() |
---|
| 59 | { |
---|
[8776] | 60 | OutputManager::getInstance().unregisterListener(this); |
---|
[8765] | 61 | } |
---|
| 62 | |
---|
[8848] | 63 | /** |
---|
| 64 | @brief Defines the level mask in a way which accepts all output up to the level \c max. |
---|
| 65 | */ |
---|
[8765] | 66 | void OutputListener::setLevelMax(OutputLevel max) |
---|
| 67 | { |
---|
[8808] | 68 | this->setLevelRange(static_cast<OutputLevel>(0x1), max); |
---|
[8765] | 69 | } |
---|
| 70 | |
---|
[8848] | 71 | /** |
---|
| 72 | @brief Defines the level mask in a way which accepts all output between the levels \c min and \c max. |
---|
| 73 | */ |
---|
[8765] | 74 | void OutputListener::setLevelRange(OutputLevel min, OutputLevel max) |
---|
| 75 | { |
---|
[8808] | 76 | int mask = 0; |
---|
| 77 | for (int level = min; level <= max; level = level << 1) |
---|
[8765] | 78 | mask |= level; |
---|
| 79 | |
---|
[8808] | 80 | this->setLevelMask(static_cast<OutputLevel>(mask)); |
---|
[8765] | 81 | } |
---|
| 82 | |
---|
[8848] | 83 | /** |
---|
| 84 | @brief Defines the level mask. |
---|
| 85 | */ |
---|
[8765] | 86 | void OutputListener::setLevelMask(OutputLevel mask) |
---|
| 87 | { |
---|
| 88 | this->levelMask_ = mask; |
---|
| 89 | |
---|
[8776] | 90 | OutputManager::getInstance().updateCombinedLevelMask(); |
---|
[8765] | 91 | } |
---|
| 92 | |
---|
[8848] | 93 | /** |
---|
| 94 | @brief Defines the level mask of additional contexts in a way which accepts all output up to the level \c max. |
---|
| 95 | */ |
---|
[8833] | 96 | void OutputListener::setAdditionalContextsLevelMax(OutputLevel max) |
---|
[8765] | 97 | { |
---|
[8833] | 98 | this->setAdditionalContextsLevelRange(static_cast<OutputLevel>(0x1), max); |
---|
| 99 | } |
---|
[8765] | 100 | |
---|
[8848] | 101 | /** |
---|
| 102 | @brief Defines the level mask of additional contexts in a way which accepts all output between the levels \c min and \c max. |
---|
| 103 | */ |
---|
[8833] | 104 | void OutputListener::setAdditionalContextsLevelRange(OutputLevel min, OutputLevel max) |
---|
| 105 | { |
---|
| 106 | int mask = 0; |
---|
| 107 | for (int level = min; level <= max; level = level << 1) |
---|
| 108 | mask |= level; |
---|
| 109 | |
---|
| 110 | this->setAdditionalContextsLevelMask(static_cast<OutputLevel>(mask)); |
---|
[8765] | 111 | } |
---|
[8833] | 112 | |
---|
[8848] | 113 | /** |
---|
| 114 | @brief Defines the level mask of additional contexts. |
---|
| 115 | */ |
---|
[8833] | 116 | void OutputListener::setAdditionalContextsLevelMask(OutputLevel mask) |
---|
| 117 | { |
---|
| 118 | this->additionalContextsLevelMask_ = mask; |
---|
| 119 | |
---|
| 120 | OutputManager::getInstance().updateCombinedAdditionalContextsLevelMask(); |
---|
| 121 | } |
---|
| 122 | |
---|
[8848] | 123 | /** |
---|
| 124 | @brief Defines the mask of additional contexts. |
---|
| 125 | */ |
---|
[8833] | 126 | void OutputListener::setAdditionalContextsMask(OutputContextMask mask) |
---|
| 127 | { |
---|
| 128 | this->additionalContextsMask_ = mask; |
---|
| 129 | |
---|
| 130 | OutputManager::getInstance().updateCombinedAdditionalContextsMask(); |
---|
| 131 | } |
---|
[8850] | 132 | |
---|
| 133 | /** |
---|
| 134 | @brief Returns true if this listener accepts output of the given level and context, based on the levels and contexts masks. |
---|
| 135 | */ |
---|
| 136 | bool OutputListener::acceptsOutput(OutputLevel level, const OutputContextContainer& context) const |
---|
| 137 | { |
---|
| 138 | // check if the output level is accepted by the level mask (independent of the context) |
---|
| 139 | if (this->levelMask_ & level) |
---|
| 140 | return true; |
---|
| 141 | |
---|
| 142 | // check if the output context is accepted by the additional context mask and if the level matches as well |
---|
| 143 | if ((this->additionalContextsMask_ & context.mask) && (this->additionalContextsLevelMask_ & level)) |
---|
| 144 | return true; |
---|
| 145 | |
---|
| 146 | // otherwise we don't accept the output |
---|
| 147 | return false; |
---|
| 148 | } |
---|
[8765] | 149 | } |
---|