Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core3/src/util/Debug.h @ 1593

Last change on this file since 1593 was 1593, checked in by landauf, 16 years ago

changed COUT(x) macros to use trinary ?: operator instead of if (…) to avoid problems with nested calls like this:

if (true)

COUT(4) << "DEBUG!" << std::endl;

else

COUT(1) << "ERROR!" << std::endl;

This used to return "ERROR!" if the configured debuglevel was < 4 because of the internal structure of the macro, that turned the above code into something like this:

if (true)

if (configured-debuglevel ≥ 4)

std::cout << "DEBUG!" << std::endl;

else

if (configured-debuglevel ≥ 1)

std::cout << "ERROR!" << std::endl;

But with the changed macro it's like this:

if (true)

(configured-debuglevel ≥ 4) ? std::cout : std::cout << "DEBUG!" << std::endl;

else

(configured-debuglevel ≥ 1) ? std::cout : std::cout << "ERROR!" << std::endl;

…and therefore everything works perfectly fine.

  • Property svn:eol-style set to native
File size: 6.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/**
30 * @file Debug.h
31 * @brief Handles the output for different verbose-modes.
32 *
33 * There are two modes: HARD and SOFT. HARD is precessed during compiletime, while SOFT is for runtime.
34 */
35
36#ifndef _Debug_H__
37#define _Debug_H__
38
[1586]39#include "UtilPrereqs.h"
[1505]40
41#include <stdio.h>
42
43#include "OutputHandler.h"
44
45
[1586]46/**
47    @brief Returns the soft debug level, stored in the only existing instance of the OutputHandler class, configured in the config-file.
48    @return The soft debug level
49*/
50static inline int getSoftDebugLevel()
51{
52    return orxonox::OutputHandler::getSoftDebugLevel();
53}
54
55
[1505]56// DEFINE ERROR MODES
57#define ORX_NONE            0
58#define ORX_ERROR           1
59#define ORX_WARNING         2
60#define ORX_INFO            3
61#define ORX_DEBUG           4
[1585]62#define ORX_VERBOSE         5
63#define ORX_ULTRA           6
[1505]64
65//definitions
[1585]66#define ORX_PRINT_DEBUG_OUTPUT 1
67#define ORX_HARD_DEBUG_LEVEL ORX_VERBOSE
[1505]68
[1585]69#define COUT_EXEC(x) orxonox::OutputHandler::getOutStream().setOutputLevel(x)
[1505]70
71////////////////////////////////////////////////////////
72///  COUT: just prints output as is with std::cout   ///
73////////////////////////////////////////////////////////
74#define COUTORX_NONE    COUT0
75#define COUTORX_ERROR   COUT1
76#define COUTORX_WARNING COUT2
77#define COUTORX_INFO    COUT3
78#define COUTORX_DEBUG   COUT4
[1585]79#define COUTORX_VERBOSE COUT5
80#define COUTORX_ULTRA   COUT6
[1505]81
82#ifndef COUT
83 #if ORX_PRINT_DEBUG_OUTPUT
84  #define COUT(x) \
85   COUT ## x
86
87  #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
88   #define COUT0  \
[1593]89    (getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : COUT_EXEC(0)
[1505]90  #else
[1585]91   #define COUT0 \
92    false ? COUT_EXEC(0) : COUT_EXEC(0)
[1505]93  #endif
94
95  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
96   #define COUT1  \
[1593]97    (getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : COUT_EXEC(1)
[1505]98  #else
[1585]99   #define COUT1 \
100    false ? COUT_EXEC(1) : COUT_EXEC(1)
[1505]101  #endif
102
103  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
104   #define COUT2 \
[1593]105    (getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : COUT_EXEC(2)
[1505]106  #else
[1585]107   #define COUT2 \
108    false ? COUT_EXEC(2) : COUT_EXEC(2)
[1505]109  #endif
110
111  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
112   #define COUT3 \
[1593]113    (getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : COUT_EXEC(3)
[1505]114  #else
[1585]115   #define COUT3 \
116    false ? COUT_EXEC(3) : COUT_EXEC(3)
[1505]117  #endif
118
119  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
120   #define COUT4 \
[1593]121    (getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : COUT_EXEC(4)
[1505]122  #else
[1585]123   #define COUT4 \
124    false ? COUT_EXEC(4) : COUT_EXEC(4)
[1505]125  #endif
126
[1585]127  #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE
[1505]128   #define COUT5 \
[1593]129    (getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : COUT_EXEC(5)
[1505]130  #else
[1585]131   #define COUT5 \
132    false ? COUT_EXEC(5) : COUT_EXEC(5)
[1505]133  #endif
134
[1585]135  #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA
136   #define COUT6 \
[1593]137    (getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : COUT_EXEC(6)
[1585]138  #else
139   #define COUT6 \
140    false ? COUT_EXEC(6) : COUT_EXEC(6)
141  #endif
142
[1505]143 #else /* if ORX_PRINT_DEBUG_OUTPUT */
[1585]144  #define COUT(x) \
145    false ? COUT_EXEC(6) : COUT_EXEC(6)
[1505]146 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
147
148#endif /* ifndef COUT */
149
150
151/////////////////////////////////////////////////////////////////////
152///  CCOUT: Prints output with std::cout and adds the classname   ///
153/////////////////////////////////////////////////////////////////////
154#define CCOUTORX_NONE    CCOUT0
155#define CCOUTORX_ERROR   CCOUT1
156#define CCOUTORX_WARNING CCOUT2
157#define CCOUTORX_INFO    CCOUT3
158#define CCOUTORX_DEBUG   CCOUT4
[1585]159#define CCOUTORX_VERBOSE CCOUT5
160#define CCOUTORX_ULTRA   CCOUT6
[1505]161
162#define CCOUT_EXEC(x) \
163  orxonox::OutputHandler::getOutStream().setOutputLevel(x) \
164  << this->getIdentifier()->getName() << ": "
165
166#ifndef CCOUT
167 #if ORX_PRINT_DEBUG_OUTPUT
168  #define CCOUT(x) \
169   CCOUT ## x
170
171  #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
172   #define CCOUT0  \
[1593]173    (getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : CCOUT_EXEC(0)
[1505]174  #else
[1585]175   #define CCOUT0 \
[1593]176    false ? COUT_EXEC(0) : CCOUT_EXEC(0)
[1505]177  #endif
178
179  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
180   #define CCOUT1  \
[1593]181    (getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : CCOUT_EXEC(1)
[1505]182  #else
[1585]183   #define CCOUT1 \
[1593]184    false ? COUT_EXEC(1) : CCOUT_EXEC(1)
[1505]185  #endif
186
187  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
188   #define CCOUT2 \
[1593]189    (getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : CCOUT_EXEC(2)
[1505]190  #else
[1585]191   #define CCOUT2 \
[1593]192    false ? COUT_EXEC(2) : CCOUT_EXEC(2)
[1505]193  #endif
194
195  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
196   #define CCOUT3 \
[1593]197    (getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : CCOUT_EXEC(3)
[1505]198  #else
[1585]199   #define CCOUT3 \
[1593]200    false ? COUT_EXEC(3) : CCOUT_EXEC(3)
[1505]201  #endif
202
203  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
204   #define CCOUT4 \
[1593]205    (getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : CCOUT_EXEC(4)
[1505]206  #else
[1585]207   #define CCOUT4 \
[1593]208    false ? COUT_EXEC(4) : CCOUT_EXEC(4)
[1505]209  #endif
210
[1585]211  #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE
[1505]212   #define CCOUT5 \
[1593]213    (getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : CCOUT_EXEC(5)
[1505]214  #else
[1585]215   #define CCOUT5 \
[1593]216    false ? COUT_EXEC(5) : CCOUT_EXEC(5)
[1505]217  #endif
218
[1585]219  #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA
220   #define CCOUT6 \
[1593]221    (getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : CCOUT_EXEC(6)
[1585]222  #else
223   #define CCOUT6 \
[1593]224    false ? COUT_EXEC(6) : CCOUT_EXEC(6)
[1585]225  #endif
226
[1505]227 #else /* if ORX_PRINT_DEBUG_OUTPUT */
[1585]228  #define CCOUT(x) \
229   false ? CCOUT_EXEC(6) : CCOUT_EXEC(6)
[1505]230 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
231
232#endif /* ifndef CCOUT */
233
234#endif /* _Debug_H__ */
Note: See TracBrowser for help on using the repository browser.