Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/release2012/src/libraries/util/output/OutputManager.h @ 10256

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

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

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