Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

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