Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/output/src/libraries/util/output/OutputListener.h @ 8850

Last change on this file since 8850 was 8850, checked in by landauf, 13 years ago

moved filtering of sub-contexts from BaseWriter to a new interface SubcontextOutputListener

  • Property svn:eol-style set to native
File size: 6.6 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    @ingroup Output
32    @brief Declaration of the OutputListener interface which receives output
33    from orxonox::OutputManager.
34*/
35
36#ifndef _OutputListener_H__
37#define _OutputListener_H__
38
39#include "util/UtilPrereqs.h"
40
41#include <vector>
42
43#include "OutputDefinitions.h"
44
45namespace orxonox
46{
47    /**
48        @brief OutputListener is an interface which is used to receive output of a certain level and context from OutputManager.
49    */
50    //  See below the class declaration for a more detailed description.
51    class _UtilExport OutputListener
52    {
53        public:
54            OutputListener(bool bRegister = true);
55            virtual ~OutputListener();
56
57            void setLevelMax(OutputLevel max);
58            void setLevelRange(OutputLevel min, OutputLevel max);
59            void setLevelMask(OutputLevel mask);
60
61            void setAdditionalContextsLevelMax(OutputLevel max);
62            void setAdditionalContextsLevelRange(OutputLevel min, OutputLevel max);
63            void setAdditionalContextsLevelMask(OutputLevel mask);
64
65            void setAdditionalContextsMask(OutputContextMask mask);
66
67            /// @brief Returns the level mask.
68            inline OutputLevel getLevelMask() const
69                { return this->levelMask_; }
70            /// @brief Returns the additional contexts mask.
71            inline OutputContextMask getAdditionalContextsMask() const
72                { return this->additionalContextsMask_; }
73            /// @brief Returns the additional contexts level mask.
74            inline OutputLevel getAdditionalContextsLevelMask() const
75                { return this->additionalContextsLevelMask_; }
76
77            virtual bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const;
78
79            /// @brief Called by OutputManager for each line of output, checks if this listener actually accepts this output before it calls the output() function.
80            inline void unfilteredOutput(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines)
81                { if (this->acceptsOutput(level, context)) this->output(level, context, lines); }
82
83        protected:
84            /// @brief Pure virtual function, needs to be implemented in order to receive output.
85            virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) = 0;
86
87        private:
88            OutputLevel       levelMask_;                   ///< Mask of accepted output levels, independent of contexts
89            OutputContextMask additionalContextsMask_;      ///< Mask of accepted additional contexts
90            OutputLevel       additionalContextsLevelMask_; ///< Mask of accepted output levels of the additional contexts
91    };
92
93    /**
94        @class OutputListener
95
96        An instance of OutputListener registers itself at OutputManager and
97        declares the desired output levels and contexts. OutputManager will
98        then send output to it by calling the output() function.
99
100        OutputListener has 3 masks to define the desired output. These masks
101        can be used in two different ways (or as a combination of both):
102        \li 1. By defining the \a "level mask": The OutputListener will then
103               receive all output of these levels independent of the context.
104        \li 2. By defining the \a "additional contexts mask" and the
105               \a "additional contexts level mask": This way the listener
106               receives only output of a particular context and level.
107        \li 3. By using all 3 masks which combines the output defined by the
108               first two ways.
109
110        This can be illustrated as follows:
111
112        1. Only level mask:
113        \li level-mask = error | warning;
114
115        @verbatim
116                |   Contexts:   |
117                | A | B | C | D |
118        --------|---|---|---|---|
119        debug   | - | - | - | - |
120        --------|---|---|---|---|
121        error   | x | x | x | x |
122        --------|---|---|---|---|       [x] Receives output
123        warning | x | x | x | x |       [-] Does not receive output
124        --------|---|---|---|---|
125        status  | - | - | - | - |
126        --------|---|---|---|---|
127        verbose | - | - | - | - |
128        --------|---|---|---|---|
129        @endverbatim
130
131        2. Only additional contexts:
132        \li additional-contexts-mask = B | D;
133        \li additional-contexts-level-mask = debug | verbose;
134
135        @verbatim
136                |   Contexts:   |
137                | A | B | C | D |
138        --------|---|---|---|---|
139        debug   | - | x | - | x |
140        --------|---|---|---|---|
141        error   | - | - | - | - |
142        --------|---|---|---|---|       [x] Receives output
143        warning | - | - | - | - |       [-] Does not receive output
144        --------|---|---|---|---|
145        status  | - | - | - | - |
146        --------|---|---|---|---|
147        verbose | - | x | - | x |
148        --------|---|---|---|---|
149        @endverbatim
150
151        3. Both level mask plus additional contexts:
152        \li level-mask = error | warning;
153        \li additional-contexts-mask = B | D;
154        \li additional-contexts-level-mask = debug | verbose;
155
156        @verbatim
157                |   Contexts:   |
158                | A | B | C | D |
159        --------|---|---|---|---|
160        debug   | - | x | - | x |
161        --------|---|---|---|---|
162        error   | x | x | x | x |
163        --------|---|---|---|---|       [x] Receives output
164        warning | x | x | x | x |       [-] Does not receive output
165        --------|---|---|---|---|
166        status  | - | - | - | - |
167        --------|---|---|---|---|
168        verbose | - | x | - | x |
169        --------|---|---|---|---|
170        @endverbatim
171    */
172}
173
174#endif /* _OutputListener_H__ */
Note: See TracBrowser for help on using the repository browser.