Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/util/Debug.h @ 4165

Last change on this file since 4165 was 3196, checked in by rgrieder, 15 years ago

Merged pch branch back to trunk.

  • Property svn:eol-style set to native
File size: 7.2 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:
23 *      Benjamin Grauer
24 *   Co-authors:
25 *      Fabian 'x3n' Landau
26 *
27 */
28
29/**
[2171]30    @file
[1791]31    @brief Handles different output-levels of errors, warnings, infos and debug informations.
32
33    The COUT(level) macro acts like std::cout, but the output is only performed if the given
34    level is <= the soft debug level.
35
36    There are two used values in this file:
37     - The hard debug level is used during compiletime. It describes the highest allowed output level.
38     - The soft debug level is used during runtime and is the maximum of the three configurable
39       output-levels for console, logfile and ingame shell.
40
41    The separation between the three devices is done by the OutputHandler.
42
43    Possible levels are:
44     0: Very important output
45     1: Errors
46     2: Warnings
47     3: Informations
48     4: Debug information
49     5: More debug information
50     6: Crazy debug informations
51
52    @example
53    COUT(0) << "Very important output" << std::endl;
54    COUT(1) << "Error: Something went wrong!" << std::endl;
55    COUT(2) << "Warning: There might be a problem." << std::endl;
56    COUT(3) << "Info: It's monday" << std::endl;
57    COUT(4) << "Debug: x is 1.23456" << std::endl;
[1505]58 */
59
60#ifndef _Debug_H__
61#define _Debug_H__
62
[1586]63#include "UtilPrereqs.h"
[1505]64
65#include "OutputHandler.h"
66
[2171]67namespace orxonox
[1586]68{
[2171]69    /**
70        @brief Returns the soft debug level, stored in the only existing instance of the OutputHandler class, configured in the config-file.
71        @return The soft debug level
72    */
[3196]73    inline int getSoftDebugLevel()
[2171]74    {
75        return OutputHandler::getSoftDebugLevel();
76    }
[1586]77
[2087]78    using std::endl;
79}
[1586]80
[1505]81// DEFINE ERROR MODES
82#define ORX_NONE            0
83#define ORX_ERROR           1
84#define ORX_WARNING         2
85#define ORX_INFO            3
86#define ORX_DEBUG           4
[1585]87#define ORX_VERBOSE         5
88#define ORX_ULTRA           6
[1505]89
90//definitions
[1585]91#define ORX_PRINT_DEBUG_OUTPUT 1
92#define ORX_HARD_DEBUG_LEVEL ORX_VERBOSE
[1505]93
[1585]94#define COUT_EXEC(x) orxonox::OutputHandler::getOutStream().setOutputLevel(x)
[1505]95
96////////////////////////////////////////////////////////
97///  COUT: just prints output as is with std::cout   ///
98////////////////////////////////////////////////////////
99#define COUTORX_NONE    COUT0
100#define COUTORX_ERROR   COUT1
101#define COUTORX_WARNING COUT2
102#define COUTORX_INFO    COUT3
103#define COUTORX_DEBUG   COUT4
[1585]104#define COUTORX_VERBOSE COUT5
105#define COUTORX_ULTRA   COUT6
[1505]106
107#ifndef COUT
108 #if ORX_PRINT_DEBUG_OUTPUT
109  #define COUT(x) \
110   COUT ## x
111
112  #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
[1610]113   #define COUT0 \
[2171]114   (orxonox::getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : COUT_EXEC(0)
[1505]115  #else
[1585]116   #define COUT0 \
117    false ? COUT_EXEC(0) : COUT_EXEC(0)
[1505]118  #endif
119
120  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
[1610]121   #define COUT1 \
[2171]122    (orxonox::getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : COUT_EXEC(1)
[1505]123  #else
[1585]124   #define COUT1 \
125    false ? COUT_EXEC(1) : COUT_EXEC(1)
[1505]126  #endif
127
128  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
129   #define COUT2 \
[2171]130    (orxonox::getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : COUT_EXEC(2)
[1505]131  #else
[1585]132   #define COUT2 \
133    false ? COUT_EXEC(2) : COUT_EXEC(2)
[1505]134  #endif
135
136  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
137   #define COUT3 \
[2171]138    (orxonox::getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : COUT_EXEC(3)
[1505]139  #else
[1585]140   #define COUT3 \
141    false ? COUT_EXEC(3) : COUT_EXEC(3)
[1505]142  #endif
143
144  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
145   #define COUT4 \
[2171]146    (orxonox::getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : COUT_EXEC(4)
[1505]147  #else
[1585]148   #define COUT4 \
149    false ? COUT_EXEC(4) : COUT_EXEC(4)
[1505]150  #endif
151
[1585]152  #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE
[1505]153   #define COUT5 \
[2171]154    (orxonox::getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : COUT_EXEC(5)
[1505]155  #else
[1585]156   #define COUT5 \
157    false ? COUT_EXEC(5) : COUT_EXEC(5)
[1505]158  #endif
159
[1585]160  #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA
161   #define COUT6 \
[2171]162    (orxonox::getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : COUT_EXEC(6)
[1585]163  #else
164   #define COUT6 \
165    false ? COUT_EXEC(6) : COUT_EXEC(6)
166  #endif
167
[1505]168 #else /* if ORX_PRINT_DEBUG_OUTPUT */
[1585]169  #define COUT(x) \
170    false ? COUT_EXEC(6) : COUT_EXEC(6)
[1505]171 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
172
173#endif /* ifndef COUT */
174
175
176/////////////////////////////////////////////////////////////////////
177///  CCOUT: Prints output with std::cout and adds the classname   ///
178/////////////////////////////////////////////////////////////////////
179#define CCOUTORX_NONE    CCOUT0
180#define CCOUTORX_ERROR   CCOUT1
181#define CCOUTORX_WARNING CCOUT2
182#define CCOUTORX_INFO    CCOUT3
183#define CCOUTORX_DEBUG   CCOUT4
[1585]184#define CCOUTORX_VERBOSE CCOUT5
185#define CCOUTORX_ULTRA   CCOUT6
[1505]186
187#define CCOUT_EXEC(x) \
188  orxonox::OutputHandler::getOutStream().setOutputLevel(x) \
189  << this->getIdentifier()->getName() << ": "
190
191#ifndef CCOUT
192 #if ORX_PRINT_DEBUG_OUTPUT
193  #define CCOUT(x) \
194   CCOUT ## x
195
196  #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
[1610]197   #define CCOUT0 \
[2171]198    (orxonox::getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : CCOUT_EXEC(0)
[1505]199  #else
[1585]200   #define CCOUT0 \
[1593]201    false ? COUT_EXEC(0) : CCOUT_EXEC(0)
[1505]202  #endif
203
204  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
[1610]205   #define CCOUT1 \
[2171]206    (orxonox::getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : CCOUT_EXEC(1)
[1505]207  #else
[1585]208   #define CCOUT1 \
[1593]209    false ? COUT_EXEC(1) : CCOUT_EXEC(1)
[1505]210  #endif
211
212  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
213   #define CCOUT2 \
[2171]214    (orxonox::getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : CCOUT_EXEC(2)
[1505]215  #else
[1585]216   #define CCOUT2 \
[1593]217    false ? COUT_EXEC(2) : CCOUT_EXEC(2)
[1505]218  #endif
219
220  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
221   #define CCOUT3 \
[2171]222    (orxonox::getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : CCOUT_EXEC(3)
[1505]223  #else
[1585]224   #define CCOUT3 \
[1593]225    false ? COUT_EXEC(3) : CCOUT_EXEC(3)
[1505]226  #endif
227
228  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
229   #define CCOUT4 \
[2171]230    (orxonox::getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : CCOUT_EXEC(4)
[1505]231  #else
[1585]232   #define CCOUT4 \
[1593]233    false ? COUT_EXEC(4) : CCOUT_EXEC(4)
[1505]234  #endif
235
[1585]236  #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE
[1505]237   #define CCOUT5 \
[2171]238    (orxonox::getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : CCOUT_EXEC(5)
[1505]239  #else
[1585]240   #define CCOUT5 \
[1593]241    false ? COUT_EXEC(5) : CCOUT_EXEC(5)
[1505]242  #endif
243
[1585]244  #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA
245   #define CCOUT6 \
[2171]246    (orxonox::getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : CCOUT_EXEC(6)
[1585]247  #else
248   #define CCOUT6 \
[1593]249    false ? COUT_EXEC(6) : CCOUT_EXEC(6)
[1585]250  #endif
251
[1505]252 #else /* if ORX_PRINT_DEBUG_OUTPUT */
[1585]253  #define CCOUT(x) \
254   false ? CCOUT_EXEC(6) : CCOUT_EXEC(6)
[1505]255 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
256
257#endif /* ifndef CCOUT */
258
259#endif /* _Debug_H__ */
Note: See TracBrowser for help on using the repository browser.