Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged objecthierarchy branch back to trunk

  • Property svn:eol-style set to native
File size: 7.1 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/**
[1791]30    @file Debug.h
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 <stdio.h>
66
67#include "OutputHandler.h"
68
69
[1586]70/**
71    @brief Returns the soft debug level, stored in the only existing instance of the OutputHandler class, configured in the config-file.
72    @return The soft debug level
73*/
74static inline int getSoftDebugLevel()
75{
76    return orxonox::OutputHandler::getSoftDebugLevel();
77}
78
[2087]79namespace orxonox
80{
81    using std::endl;
82}
[1586]83
[1505]84// DEFINE ERROR MODES
85#define ORX_NONE            0
86#define ORX_ERROR           1
87#define ORX_WARNING         2
88#define ORX_INFO            3
89#define ORX_DEBUG           4
[1585]90#define ORX_VERBOSE         5
91#define ORX_ULTRA           6
[1505]92
93//definitions
[1585]94#define ORX_PRINT_DEBUG_OUTPUT 1
95#define ORX_HARD_DEBUG_LEVEL ORX_VERBOSE
[1505]96
[1585]97#define COUT_EXEC(x) orxonox::OutputHandler::getOutStream().setOutputLevel(x)
[1505]98
99////////////////////////////////////////////////////////
100///  COUT: just prints output as is with std::cout   ///
101////////////////////////////////////////////////////////
102#define COUTORX_NONE    COUT0
103#define COUTORX_ERROR   COUT1
104#define COUTORX_WARNING COUT2
105#define COUTORX_INFO    COUT3
106#define COUTORX_DEBUG   COUT4
[1585]107#define COUTORX_VERBOSE COUT5
108#define COUTORX_ULTRA   COUT6
[1505]109
110#ifndef COUT
111 #if ORX_PRINT_DEBUG_OUTPUT
112  #define COUT(x) \
113   COUT ## x
114
115  #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
[1610]116   #define COUT0 \
[1593]117    (getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : COUT_EXEC(0)
[1505]118  #else
[1585]119   #define COUT0 \
120    false ? COUT_EXEC(0) : COUT_EXEC(0)
[1505]121  #endif
122
123  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
[1610]124   #define COUT1 \
[1593]125    (getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : COUT_EXEC(1)
[1505]126  #else
[1585]127   #define COUT1 \
128    false ? COUT_EXEC(1) : COUT_EXEC(1)
[1505]129  #endif
130
131  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
132   #define COUT2 \
[1593]133    (getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : COUT_EXEC(2)
[1505]134  #else
[1585]135   #define COUT2 \
136    false ? COUT_EXEC(2) : COUT_EXEC(2)
[1505]137  #endif
138
139  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
140   #define COUT3 \
[1593]141    (getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : COUT_EXEC(3)
[1505]142  #else
[1585]143   #define COUT3 \
144    false ? COUT_EXEC(3) : COUT_EXEC(3)
[1505]145  #endif
146
147  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
148   #define COUT4 \
[1593]149    (getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : COUT_EXEC(4)
[1505]150  #else
[1585]151   #define COUT4 \
152    false ? COUT_EXEC(4) : COUT_EXEC(4)
[1505]153  #endif
154
[1585]155  #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE
[1505]156   #define COUT5 \
[1593]157    (getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : COUT_EXEC(5)
[1505]158  #else
[1585]159   #define COUT5 \
160    false ? COUT_EXEC(5) : COUT_EXEC(5)
[1505]161  #endif
162
[1585]163  #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA
164   #define COUT6 \
[1593]165    (getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : COUT_EXEC(6)
[1585]166  #else
167   #define COUT6 \
168    false ? COUT_EXEC(6) : COUT_EXEC(6)
169  #endif
170
[1505]171 #else /* if ORX_PRINT_DEBUG_OUTPUT */
[1585]172  #define COUT(x) \
173    false ? COUT_EXEC(6) : COUT_EXEC(6)
[1505]174 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
175
176#endif /* ifndef COUT */
177
178
179/////////////////////////////////////////////////////////////////////
180///  CCOUT: Prints output with std::cout and adds the classname   ///
181/////////////////////////////////////////////////////////////////////
182#define CCOUTORX_NONE    CCOUT0
183#define CCOUTORX_ERROR   CCOUT1
184#define CCOUTORX_WARNING CCOUT2
185#define CCOUTORX_INFO    CCOUT3
186#define CCOUTORX_DEBUG   CCOUT4
[1585]187#define CCOUTORX_VERBOSE CCOUT5
188#define CCOUTORX_ULTRA   CCOUT6
[1505]189
190#define CCOUT_EXEC(x) \
191  orxonox::OutputHandler::getOutStream().setOutputLevel(x) \
192  << this->getIdentifier()->getName() << ": "
193
194#ifndef CCOUT
195 #if ORX_PRINT_DEBUG_OUTPUT
196  #define CCOUT(x) \
197   CCOUT ## x
198
199  #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
[1610]200   #define CCOUT0 \
[1593]201    (getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : CCOUT_EXEC(0)
[1505]202  #else
[1585]203   #define CCOUT0 \
[1593]204    false ? COUT_EXEC(0) : CCOUT_EXEC(0)
[1505]205  #endif
206
207  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
[1610]208   #define CCOUT1 \
[1593]209    (getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : CCOUT_EXEC(1)
[1505]210  #else
[1585]211   #define CCOUT1 \
[1593]212    false ? COUT_EXEC(1) : CCOUT_EXEC(1)
[1505]213  #endif
214
215  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
216   #define CCOUT2 \
[1593]217    (getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : CCOUT_EXEC(2)
[1505]218  #else
[1585]219   #define CCOUT2 \
[1593]220    false ? COUT_EXEC(2) : CCOUT_EXEC(2)
[1505]221  #endif
222
223  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
224   #define CCOUT3 \
[1593]225    (getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : CCOUT_EXEC(3)
[1505]226  #else
[1585]227   #define CCOUT3 \
[1593]228    false ? COUT_EXEC(3) : CCOUT_EXEC(3)
[1505]229  #endif
230
231  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
232   #define CCOUT4 \
[1593]233    (getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : CCOUT_EXEC(4)
[1505]234  #else
[1585]235   #define CCOUT4 \
[1593]236    false ? COUT_EXEC(4) : CCOUT_EXEC(4)
[1505]237  #endif
238
[1585]239  #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE
[1505]240   #define CCOUT5 \
[1593]241    (getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : CCOUT_EXEC(5)
[1505]242  #else
[1585]243   #define CCOUT5 \
[1593]244    false ? COUT_EXEC(5) : CCOUT_EXEC(5)
[1505]245  #endif
246
[1585]247  #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA
248   #define CCOUT6 \
[1593]249    (getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : CCOUT_EXEC(6)
[1585]250  #else
251   #define CCOUT6 \
[1593]252    false ? COUT_EXEC(6) : CCOUT_EXEC(6)
[1585]253  #endif
254
[1505]255 #else /* if ORX_PRINT_DEBUG_OUTPUT */
[1585]256  #define CCOUT(x) \
257   false ? CCOUT_EXEC(6) : CCOUT_EXEC(6)
[1505]258 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
259
260#endif /* ifndef CCOUT */
261
262#endif /* _Debug_H__ */
Note: See TracBrowser for help on using the repository browser.