Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/testing/src/libraries/util/output/OutputManager.h @ 9533

Last change on this file since 9533 was 9533, checked in by landauf, 11 years ago

added more tests

  • Property svn:eol-style set to native
File size: 5.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 OutputManager class which receives output from orxonox::OutputStream
33    and distributes it to all instances of orxonox::OutputListener.
34*/
35
36#ifndef _OutputManager_H__
37#define _OutputManager_H__
38
39#include "util/UtilPrereqs.h"
40
41#include <vector>
42#include <map>
43
44#include "OutputDefinitions.h"
45#include "AdditionalContextListener.h"
46
47namespace orxonox
48{
49    /**
50        @brief OutputManager acts as the center of the output system and is implemented as a singleton.
51
52        All instances of OutputStream (and hence also the orxout() function)
53        send their buffered output to OutputManager. OutputManager then
54        distributes this output to all registered instances of OutputListener.
55
56        For each listener OutputManager checks if it wants to receive output
57        with the given level and context. OutputManager itself also maintains
58        masks that define the accepted levels and concept. They are a
59        combination of the masks of all output listeners. See the description
60        of OutputListener for a more conclusive description of these masks.
61
62        Additionally OutputManager is used to register output contexts.
63    */
64    class _UtilExport OutputManager : public AdditionalContextListener
65    {
66        public:
67            OutputManager();
68            OutputManager(const OutputManager&);
69            virtual ~OutputManager();
70
71            static OutputManager& getInstance();
72            static OutputManager& getInstanceAndCreateListeners();
73
74            void pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message);
75
76            virtual void registerListener(OutputListener* listener);
77            virtual void unregisterListener(OutputListener* listener);
78
79            virtual void updatedLevelMask(const OutputListener* listener)
80                { this->updateCombinedLevelMask(); }
81            virtual void updatedAdditionalContextsLevelMask(const OutputListener* listener)
82                { this->updateCombinedAdditionalContextsLevelMask(); }
83            virtual void updatedAdditionalContextsMask(const OutputListener* listener)
84                { this->updateCombinedAdditionalContextsMask(); }
85
86            /**
87                @brief Returns true if at least one of the output listeners will accept output with the given level and context.
88
89                For the sake of performance, output messages with levels or
90                contexts that are not accepted should be ignored or, even
91                better, not generated at all.
92            */
93            inline bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const
94            {
95                return (this->combinedLevelMask_ & level) ||
96                       ((this->combinedAdditionalContextsLevelMask_ & level) && (this->combinedAdditionalContextsMask_ & context.mask));
97            }
98
99            const OutputContextContainer& registerContext(const std::string& name, const std::string& subname = "");
100
101            const std::string& getLevelName(OutputLevel level) const;
102            std::string getDefaultPrefix(OutputLevel level, const OutputContextContainer& context) const;
103
104        protected:
105            inline const std::vector<OutputListener*>& getListeners() const
106                { return this->listeners_; }
107
108        private:
109            void updateMasks();
110            void updateCombinedLevelMask();
111            void updateCombinedAdditionalContextsLevelMask();
112            void updateCombinedAdditionalContextsMask();
113
114            std::vector<OutputListener*> listeners_;                            ///< List of all registered output listeners
115
116            OutputLevel       combinedLevelMask_;                               ///< The combined mask of accepted levels of all listeners
117            OutputLevel       combinedAdditionalContextsLevelMask_;             ///< The combined mask of accepted additional contexts levels of all listeners
118            OutputContextMask combinedAdditionalContextsMask_;                  ///< The combined mask of accepted additional contexts of all listeners
119
120            std::map<std::string, OutputContextMask> contextMasks_;             ///< Contains all main-contexts and their masks
121            std::map<std::string, OutputContextContainer> contextContainers_;   ///< Contains all contexts including sub-contexts and their containers
122            OutputContextSubID subcontextCounter_;                              ///< Counts the number of sub-contexts (and generates their IDs)
123
124        public:
125            struct _UtilExport Testing
126            {
127                static SharedPtr<OutputManager>& getInstancePointer();
128            };
129    };
130}
131
132#endif /* _OutputManager_H__ */
Note: See TracBrowser for help on using the repository browser.