Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/core/Debug.h @ 621

Last change on this file since 621 was 560, checked in by landauf, 17 years ago
  • changed output from std::cout to COUT(level)
  • added SoftDebugLevel config-variable (its a hack, but it works fine)
File size: 5.9 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16/*!
17 * @file Debug.h
18 * @brief Handles the output for different verbose-modes.
19 *
20 * There are two modes: HARD and SOFT. HARD is precessed during compiletime, while SOFT is for runtime.
21 */
22
23#ifndef _Debug_H__
24#define _Debug_H__
25
26#include <stdio.h>
27
28int getSoftDebugLevel();
29
30// DEFINE ERROR MODES
31#define ORX_NONE            0
32#define ORX_ERROR           1
33#define ORX_WARNING         2
34#define ORX_INFO            3
35#define ORX_DEBUG           4
36#define ORX_vDEBUG          5
37
38//definitions
39#define ORX_PRINT_DEBUG_OUTPUT 1 // <-- fix that! should be a configurable setting
40
41#define ORX_HARD_DEBUG_LEVEL ORX_DEBUG
42//#define ORX_SOFT_DEBUG_LEVEL ORX_WARNING // <-- fix that! should be a configurable setting
43
44///////////////////////////////////////////////////
45/// PRINTF: prints with filename and linenumber ///
46///////////////////////////////////////////////////
47#define PRINTFORX_NONE    PRINTF0
48#define PRINTFORX_ERROR   PRINTF1
49#define PRINTFORX_WARNING PRINTF2
50#define PRINTFORX_INFO    PRINTF3
51#define PRINTFORX_DEBUG   PRINTF4
52#define PRINTFORX_vDEBUG  PRINTF5
53
54#define PRINT_EXEC  printf
55#define COUT_EXEC   std::cout
56
57#ifndef PRINTF
58 #if ORX_PRINT_DEBUG_OUTPUT
59
60  #define PRINTF(x) \
61   PRINTF ## x
62
63  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
64   #define PRINTF1 \
65    if (getSoftDebugLevel() >= ORX_ERROR) \
66     printf("Error (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
67  #else
68   #define PRINTF1 if (ORX_NONE) PRINT_EXEC
69  #endif
70
71  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
72   #define PRINTF2 \
73    if (getSoftDebugLevel() >= ORX_WARNING) \
74     printf("Warning (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
75  #else
76   #define PRINTF2 if (ORX_NONE) PRINT_EXEC
77  #endif
78
79  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
80   #define PRINTF3 \
81    if (getSoftDebugLevel() >= ORX_INFO) \
82     printf("Info (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
83  #else
84   #define PRINTF3 if (ORX_NONE) PRINT_EXEC
85  #endif
86
87  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
88   #define PRINTF4 \
89    if (getSoftDebugLevel() >= ORX_DEBUG) \
90     printf("Debug (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
91  #else
92   #define PRINTF4 if (ORX_NONE) PRINT_EXEC
93  #endif
94
95  #if ORX_HARD_DEBUG_LEVEL >= ORX_vDEBUG
96   #define PRINTF5 \
97    if (getSoftDebugLevel() >= ORX_vDEBUG) \
98     printf("vDebug (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
99  #else
100   #define PRINTF5 if (ORX_NONE) PRINT_EXEC
101  #endif
102
103 #else /* if ORX_PRINT_DEBUG_OUTPUT */
104  #define PRINTF(x) if (ORX_NONE) PRINT_EXEC
105 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
106
107 #define PRINTF0 \
108  PRINT_EXEC
109#endif /* ifndef PRINTF */
110
111///////////////////////////////////////////////////
112///  PRINT: just prints output as is            ///
113///////////////////////////////////////////////////
114#define PRINTORX_NONE    PRINT0
115#define PRINTORX_ERROR   PRINT1
116#define PRINTORX_WARNING PRINT2
117#define PRINTORX_INFO    PRINT3
118#define PRINTORX_DEBUG   PRINT4
119#define PRINTORX_vDEBUG  PRINT5
120
121#ifndef PRINT
122 #if ORX_PRINT_DEBUG_OUTPUT
123  #define PRINT(x) \
124   PRINT ## x
125
126  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
127   #define PRINT1  \
128    if (getSoftDebugLevel() >= ORX_ERROR)  \
129     PRINT_EXEC
130  #else
131   #define PRINT1 if (ORX_NONE) PRINT_EXEC
132  #endif
133
134  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
135   #define PRINT2 \
136    if (getSoftDebugLevel() >= ORX_WARNING) \
137     PRINT_EXEC
138  #else
139   #define PRINT2 if (ORX_NONE) PRINT_EXEC
140  #endif
141
142  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
143   #define PRINT3 \
144    if (getSoftDebugLevel() >= ORX_INFO) \
145     PRINT_EXEC
146  #else
147   #define PRINT3 if (ORX_NONE) PRINT_EXEC
148  #endif
149
150  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
151   #define PRINT4 \
152    if (getSoftDebugLevel() >= ORX_DEBUG) \
153     PRINT_EXEC
154  #else
155   #define PRINT4 if (ORX_NONE) PRINT_EXEC
156  #endif
157
158  #if ORX_HARD_DEBUG_LEVEL >= ORX_vDEBUG
159   #define PRINT5 \
160    if (getSoftDebugLevel() >= ORX_vDEBUG) \
161     PRINT_EXEC
162  #else
163   #define PRINT5 if (ORX_NONE) PRINT_EXEC
164  #endif
165
166 #else /* if ORX_PRINT_DEBUG_OUTPUT */
167  #define PRINT(x) if (ORX_NONE) PRINT_EXEC
168 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
169
170 #define PRINT0 \
171  PRINT_EXEC
172#endif /* ifndef PRINT */
173
174
175////////////////////////////////////////////////////////
176///  COUT: just prints output as is with std::cout   ///
177////////////////////////////////////////////////////////
178#define COUTORX_NONE    COUT0
179#define COUTORX_ERROR   COUT1
180#define COUTORX_WARNING COUT2
181#define COUTORX_INFO    COUT3
182#define COUTORX_DEBUG   COUT4
183#define COUTORX_vDEBUG  COUT5
184
185#ifndef COUT
186 #if ORX_PRINT_DEBUG_OUTPUT
187  #define COUT(x) \
188   COUT ## x
189
190  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
191   #define COUT1  \
192    if (getSoftDebugLevel() >= ORX_ERROR)  \
193     COUT_EXEC
194  #else
195   #define COUT1 if (ORX_NONE)\
196    COUT_EXEC
197  #endif
198
199  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
200   #define COUT2 \
201    if (getSoftDebugLevel() >= ORX_WARNING) \
202     COUT_EXEC
203  #else
204   #define COUT2 if (ORX_NONE) \
205    COUT_EXEC
206  #endif
207
208  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
209   #define COUT3 \
210    if (getSoftDebugLevel() >= ORX_INFO) \
211     COUT_EXEC
212  #else
213   #define COUT3 if (ORX_NONE) \
214    COUT_EXEC
215  #endif
216
217  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
218   #define COUT4 \
219    if (getSoftDebugLevel() >= ORX_DEBUG) \
220     COUT_EXEC
221  #else
222   #define COUT4 if (ORX_NONE) \
223    COUT_EXEC
224  #endif
225
226  #if ORX_HARD_DEBUG_LEVEL >= ORX_vDEBUG
227   #define COUT5 \
228    if (getSoftDebugLevel() >= ORX_vDEBUG) \
229     COUT_EXEC
230  #else
231   #define COUT5 if (ORX_NONE) \
232    COUT_EXEC
233  #endif
234
235 #else /* if ORX_PRINT_DEBUG_OUTPUT */
236  #define COUT(x) if (ORX_NONE) \
237   COUT_EXEC
238 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
239
240 #define COUT0 \
241  COUT_EXEC
242#endif /* ifndef COUT */
243
244#endif /* _Debug_H__ */
Note: See TracBrowser for help on using the repository browser.