Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/output/src/libraries/util/Debug.h @ 8779

Last change on this file since 8779 was 8729, checked in by rgrieder, 13 years ago

Merged unity_build branch back to trunk.

Features:

  • Implemented fully automatic build units to speed up compilation if requested
  • Added DOUT macro for quick debug output
  • Activated text colouring in the POSIX IOConsole
  • DeclareToluaInterface is not necessary anymore

Improvements:

  • Output levels now change appropriately when switch back and forth from dev mode
  • Log level for the file output is now also correct during startup
  • Removed some header file dependencies in core and tools to speed up compilation

no more file for command line options

  • Improved util::tribool by adapting some concepts from boost::tribool

Regressions:

  • It is not possible anymore to specify command line arguments in an extra file because we've got config values for that purpose.
  • Property svn:eol-style set to native
File size: 4.5 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 *      Reto Grieder
25 *   Co-authors:
26 *      ...
27 *
28 */
29
30/**
31    @defgroup COUT COUT(x) output macro
32    @ingroup Util
33*/
34
35/**
36@file
37@ingroup COUT
38@brief
39    Handles different output-levels of errors, warnings, infos, and debug information.
40
41    The COUT(level) macro acts like @c std::cout, but the output is only performed if the given
42    level is <= the soft debug level.
43
44    There are two used values in this file:
45     - The hard debug level is used during compile time. It describes the highest allowed output level.
46     - The soft debug level is used during runtime and is the maximum of the three configurable
47       output-levels for console, log file, and in game shell.
48
49    The separation between the three devices is done by the OutputHandler.
50
51    @anchor COUTlevels
52    Possible levels are:
53     - 0: Very important output
54     - 1: Errors
55     - 2: Warnings
56     - 3: Information
57     - 4: Debug information
58     - 5: More debug information
59     - 6: Crazy debug information
60
61    Example:
62    @code
63    COUT(0) << "Very important output" << std::endl;
64    COUT(1) << "Error: Something went wrong!" << std::endl;
65    COUT(2) << "Warning: There might be a problem." << std::endl;
66    COUT(3) << "Info: It's Monday" << std::endl;
67    COUT(4) << "Debug: x is 1.23456" << std::endl;
68    @endcode
69*/
70
71#ifndef _Util_Debug_H__
72#define _Util_Debug_H__
73
74#include "UtilPrereqs.h"
75#include "OutputHandler.h"
76
77namespace orxonox
78{
79    // Just for convenience
80    using std::endl;
81
82    // Adjust this to discard certain output with level > hardDebugLevel at compile time already
83#ifdef ORXONOX_RELEASE
84    const int hardDebugLevel = OutputLevel::Verbose;
85#else
86    //! Maximum level for debug output that should be even processed at run time
87    const int hardDebugLevel = OutputLevel::Ultra;
88#endif
89
90    //! This function simply returns 0 and helps to suppress the "statement has no effect" compiler warning
91    inline int debugDummyFunction()
92    {
93        return 0;
94    }
95}
96
97/**
98@brief
99    Logs text output: You can use COUT(level) exactly like @c std::cout, but you have to specify an output level as argument.
100@param level
101    The level of the following output (passed with <tt><< "text"</tt>). Lower levels are more important. See @ref COUTlevels "the description above" for a list of possible output levels.
102
103    Example:
104    @code
105    COUT(3) << "Some info" << std::endl; // Output with level 3
106    @endcode
107@note
108    <tt>(a > b ? 0 : c << "text")</tt> is equivalent to <tt>(a > b ? 0 : (c << "text")</tt>
109    where <tt>(a > b ? 0 : )</tt> stands for COUT(x). This should explain how
110    this macro magic can possibly even work ;)
111@remarks
112    The <tt>? :</tt> operator requires both possible results to have the type of
113    the first. This is achieved by the int conversion operator dummy
114    in the @ref orxonox::OutputHandler.
115*/
116#define COUT(level)                                                    \
117    /*if*/ (level > orxonox::hardDebugLevel) ?                         \
118        orxonox::debugDummyFunction()                                  \
119    /*else*/ :                                                         \
120        /*if*/ (level > orxonox::OutputHandler::getSoftDebugLevel()) ? \
121            orxonox::debugDummyFunction()                              \
122        /*else*/ :                                                     \
123            orxonox::OutputHandler::getOutStream(level)
124
125/** Logs debug output: You can use DOUT exactly like @c std::cout.
126    Use this macro to produce temporary debug output that will be removed later on.
127    The console output shall have a special colour if available.
128*/
129#define DOUT orxonox::OutputHandler::getOutStream(-1) << "+++ "
130
131#endif /* _Util_Debug_H__ */
Note: See TracBrowser for help on using the repository browser.