Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/doc/src/libraries/util/Debug.h @ 7316

Last change on this file since 7316 was 7316, checked in by landauf, 14 years ago

hide the referenced/references lists
improved documentation of Debug.h

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