Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/Debug.h @ 1101

Last change on this file since 1101 was 1089, checked in by rgrieder, 17 years ago
  • bugfix in audiomanager
  • added CCOUT(level): like COUT, but prints "* Classname: " in front
File size: 8.5 KB
Line 
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
39#include "CorePrereqs.h"
40
41#include <stdio.h>
42
43#include "OutputHandler.h"
44
45extern "C" _CoreExport int getSoftDebugLevel();
46
47// DEFINE ERROR MODES
48#define ORX_NONE            0
49#define ORX_ERROR           1
50#define ORX_WARNING         2
51#define ORX_INFO            3
52#define ORX_DEBUG           4
53#define ORX_vDEBUG          5
54
55//definitions
56#define ORX_PRINT_DEBUG_OUTPUT 1 // <-- fix that! should be a configurable setting
57
58#define ORX_HARD_DEBUG_LEVEL ORX_vDEBUG
59//#define ORX_SOFT_DEBUG_LEVEL ORX_WARNING // <-- fix that! should be a configurable setting
60
61///////////////////////////////////////////////////
62/// PRINTF: prints with filename and linenumber ///
63///////////////////////////////////////////////////
64#define PRINTFORX_NONE    PRINTF0
65#define PRINTFORX_ERROR   PRINTF1
66#define PRINTFORX_WARNING PRINTF2
67#define PRINTFORX_INFO    PRINTF3
68#define PRINTFORX_DEBUG   PRINTF4
69#define PRINTFORX_vDEBUG  PRINTF5
70
71#define PRINT_EXEC  printf
72#define COUT_EXEC(x) \
73  orxonox::OutputHandler::getOutStream().setOutputLevel(x)
74
75#ifndef PRINTF
76 #if ORX_PRINT_DEBUG_OUTPUT
77
78  #define PRINTF(x) \
79   PRINTF ## x
80
81  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
82   #define PRINTF1 \
83    if (getSoftDebugLevel() >= ORX_ERROR) \
84     printf("Error (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
85  #else
86   #define PRINTF1 if (ORX_NONE) PRINT_EXEC
87  #endif
88
89  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
90   #define PRINTF2 \
91    if (getSoftDebugLevel() >= ORX_WARNING) \
92     printf("Warning (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
93  #else
94   #define PRINTF2 if (ORX_NONE) PRINT_EXEC
95  #endif
96
97  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
98   #define PRINTF3 \
99    if (getSoftDebugLevel() >= ORX_INFO) \
100     printf("Info (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
101  #else
102   #define PRINTF3 if (ORX_NONE) PRINT_EXEC
103  #endif
104
105  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
106   #define PRINTF4 \
107    if (getSoftDebugLevel() >= ORX_DEBUG) \
108     printf("Debug (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
109  #else
110   #define PRINTF4 if (ORX_NONE) PRINT_EXEC
111  #endif
112
113  #if ORX_HARD_DEBUG_LEVEL >= ORX_vDEBUG
114   #define PRINTF5 \
115    if (getSoftDebugLevel() >= ORX_vDEBUG) \
116     printf("vDebug (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
117  #else
118   #define PRINTF5 if (ORX_NONE) PRINT_EXEC
119  #endif
120
121 #else /* if ORX_PRINT_DEBUG_OUTPUT */
122  #define PRINTF(x) if (ORX_NONE) PRINT_EXEC
123 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
124
125 #define PRINTF0 \
126  PRINT_EXEC
127#endif /* ifndef PRINTF */
128
129///////////////////////////////////////////////////
130///  PRINT: just prints output as is            ///
131///////////////////////////////////////////////////
132#define PRINTORX_NONE    PRINT0
133#define PRINTORX_ERROR   PRINT1
134#define PRINTORX_WARNING PRINT2
135#define PRINTORX_INFO    PRINT3
136#define PRINTORX_DEBUG   PRINT4
137#define PRINTORX_vDEBUG  PRINT5
138
139#ifndef PRINT
140 #if ORX_PRINT_DEBUG_OUTPUT
141  #define PRINT(x) \
142   PRINT ## x
143
144  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
145   #define PRINT1  \
146    if (getSoftDebugLevel() >= ORX_ERROR)  \
147     PRINT_EXEC
148  #else
149   #define PRINT1 if (ORX_NONE) PRINT_EXEC
150  #endif
151
152  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
153   #define PRINT2 \
154    if (getSoftDebugLevel() >= ORX_WARNING) \
155     PRINT_EXEC
156  #else
157   #define PRINT2 if (ORX_NONE) PRINT_EXEC
158  #endif
159
160  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
161   #define PRINT3 \
162    if (getSoftDebugLevel() >= ORX_INFO) \
163     PRINT_EXEC
164  #else
165   #define PRINT3 if (ORX_NONE) PRINT_EXEC
166  #endif
167
168  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
169   #define PRINT4 \
170    if (getSoftDebugLevel() >= ORX_DEBUG) \
171     PRINT_EXEC
172  #else
173   #define PRINT4 if (ORX_NONE) PRINT_EXEC
174  #endif
175
176  #if ORX_HARD_DEBUG_LEVEL >= ORX_vDEBUG
177   #define PRINT5 \
178    if (getSoftDebugLevel() >= ORX_vDEBUG) \
179     PRINT_EXEC
180  #else
181   #define PRINT5 if (ORX_NONE) PRINT_EXEC
182  #endif
183
184 #else /* if ORX_PRINT_DEBUG_OUTPUT */
185  #define PRINT(x) if (ORX_NONE) PRINT_EXEC
186 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
187
188 #define PRINT0 \
189  PRINT_EXEC
190#endif /* ifndef PRINT */
191
192
193////////////////////////////////////////////////////////
194///  COUT: just prints output as is with std::cout   ///
195////////////////////////////////////////////////////////
196#define COUTORX_NONE    COUT0
197#define COUTORX_ERROR   COUT1
198#define COUTORX_WARNING COUT2
199#define COUTORX_INFO    COUT3
200#define COUTORX_DEBUG   COUT4
201#define COUTORX_vDEBUG  COUT5
202
203#ifndef COUT
204 #if ORX_PRINT_DEBUG_OUTPUT
205  #define COUT(x) \
206   COUT ## x
207
208  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
209   #define COUT1  \
210    if (getSoftDebugLevel() >= ORX_ERROR)  \
211     COUT_EXEC(1)
212  #else
213   #define COUT1 if (ORX_NONE)\
214    COUT_EXEC(1)
215  #endif
216
217  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
218   #define COUT2 \
219    if (getSoftDebugLevel() >= ORX_WARNING) \
220     COUT_EXEC(2)
221  #else
222   #define COUT2 if (ORX_NONE) \
223    COUT_EXEC(2)
224  #endif
225
226  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
227   #define COUT3 \
228    if (getSoftDebugLevel() >= ORX_INFO) \
229     COUT_EXEC(3)
230  #else
231   #define COUT3 if (ORX_NONE) \
232    COUT_EXEC(3)
233  #endif
234
235  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
236   #define COUT4 \
237    if (getSoftDebugLevel() >= ORX_DEBUG) \
238     COUT_EXEC(4)
239  #else
240   #define COUT4 if (ORX_NONE) \
241    COUT_EXEC(4)
242  #endif
243
244  #if ORX_HARD_DEBUG_LEVEL >= ORX_vDEBUG
245   #define COUT5 \
246    if (getSoftDebugLevel() >= ORX_vDEBUG) \
247     COUT_EXEC(5)
248  #else
249   #define COUT5 if (ORX_NONE) \
250    COUT_EXEC(5)
251  #endif
252
253 #else /* if ORX_PRINT_DEBUG_OUTPUT */
254  #define COUT(x) if (ORX_NONE) \
255   COUT_EXEC(5)
256 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
257
258 #define COUT0 \
259  COUT_EXEC(0)
260#endif /* ifndef COUT */
261
262
263/////////////////////////////////////////////////////////////////////
264///  CCOUT: Prints output with std::cout and adds the classname   ///
265/////////////////////////////////////////////////////////////////////
266
267#define CCOUT_EXEC(x) \
268  orxonox::OutputHandler::getOutStream().setOutputLevel(x) \
269  << "*** " << this->getIdentifier()->getName() << ": "
270
271#ifndef CCOUT
272 #if ORX_PRINT_DEBUG_OUTPUT
273  #define CCOUT(x) \
274   CCOUT ## x
275
276  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
277   #define CCOUT1  \
278    if (getSoftDebugLevel() >= ORX_ERROR)  \
279     CCOUT_EXEC(1)
280  #else
281   #define CCOUT1 if (ORX_NONE)\
282    CCOUT_EXEC(1)
283  #endif
284
285  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
286   #define CCOUT2 \
287    if (getSoftDebugLevel() >= ORX_WARNING) \
288     CCOUT_EXEC(2)
289  #else
290   #define CCOUT2 if (ORX_NONE) \
291    CCOUT_EXEC(2)
292  #endif
293
294  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
295   #define CCOUT3 \
296    if (getSoftDebugLevel() >= ORX_INFO) \
297     CCOUT_EXEC(3)
298  #else
299   #define CCOUT3 if (ORX_NONE) \
300    CCOUT_EXEC(3)
301  #endif
302
303  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
304   #define CCOUT4 \
305    if (getSoftDebugLevel() >= ORX_DEBUG) \
306     CCOUT_EXEC(4)
307  #else
308   #define CCOUT4 if (ORX_NONE) \
309    CCOUT_EXEC(4)
310  #endif
311
312  #if ORX_HARD_DEBUG_LEVEL >= ORX_vDEBUG
313   #define CCOUT5 \
314    if (getSoftDebugLevel() >= ORX_vDEBUG) \
315     CCOUT_EXEC(5)
316  #else
317   #define CCOUT5 if (ORX_NONE) \
318    CCOUT_EXEC(5)
319  #endif
320
321 #else /* if ORX_PRINT_DEBUG_OUTPUT */
322  #define CCOUT(x) if (ORX_NONE) \
323   CCOUT_EXEC(5)
324 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
325
326 #define CCOUT0 \
327  CCOUT_EXEC(0)
328#endif /* ifndef CCOUT */
329
330#endif /* _Debug_H__ */
Note: See TracBrowser for help on using the repository browser.