Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/src/core/Debug.h @ 1427

Last change on this file since 1427 was 1416, checked in by landauf, 17 years ago
  • fixed a bug in CommandExecutor
  • InGameConsole wraps now too long output lines and does something similar for the input line
File size: 8.8 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_NONE
209   #define COUT0  \
210    if (getSoftDebugLevel() >= ORX_NONE)  \
211     COUT_EXEC(0)
212  #else
213   #define COUT0 if (ORX_NONE)\
214    COUT_EXEC(0)
215  #endif
216
217  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
218   #define COUT1  \
219    if (getSoftDebugLevel() >= ORX_ERROR)  \
220     COUT_EXEC(1)
221  #else
222   #define COUT1 if (ORX_NONE)\
223    COUT_EXEC(1)
224  #endif
225
226  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
227   #define COUT2 \
228    if (getSoftDebugLevel() >= ORX_WARNING) \
229     COUT_EXEC(2)
230  #else
231   #define COUT2 if (ORX_NONE) \
232    COUT_EXEC(2)
233  #endif
234
235  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
236   #define COUT3 \
237    if (getSoftDebugLevel() >= ORX_INFO) \
238     COUT_EXEC(3)
239  #else
240   #define COUT3 if (ORX_NONE) \
241    COUT_EXEC(3)
242  #endif
243
244  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
245   #define COUT4 \
246    if (getSoftDebugLevel() >= ORX_DEBUG) \
247     COUT_EXEC(4)
248  #else
249   #define COUT4 if (ORX_NONE) \
250    COUT_EXEC(4)
251  #endif
252
253  #if ORX_HARD_DEBUG_LEVEL >= ORX_vDEBUG
254   #define COUT5 \
255    if (getSoftDebugLevel() >= ORX_vDEBUG) \
256     COUT_EXEC(5)
257  #else
258   #define COUT5 if (ORX_NONE) \
259    COUT_EXEC(5)
260  #endif
261
262 #else /* if ORX_PRINT_DEBUG_OUTPUT */
263  #define COUT(x) if (ORX_NONE) \
264   COUT_EXEC(5)
265 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
266
267#endif /* ifndef COUT */
268
269
270/////////////////////////////////////////////////////////////////////
271///  CCOUT: Prints output with std::cout and adds the classname   ///
272/////////////////////////////////////////////////////////////////////
273
274#define CCOUT_EXEC(x) \
275  orxonox::OutputHandler::getOutStream().setOutputLevel(x) \
276  << "*** " << this->getIdentifier()->getName() << ": "
277
278#ifndef CCOUT
279 #if ORX_PRINT_DEBUG_OUTPUT
280  #define CCOUT(x) \
281   CCOUT ## x
282
283  #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
284   #define CCOUT0  \
285    if (getSoftDebugLevel() >= ORX_NONE)  \
286     CCOUT_EXEC(0)
287  #else
288   #define CCOUT0 if (ORX_NONE)\
289    CCOUT_EXEC(0)
290  #endif
291
292  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
293   #define CCOUT1  \
294    if (getSoftDebugLevel() >= ORX_ERROR)  \
295     CCOUT_EXEC(1)
296  #else
297   #define CCOUT1 if (ORX_NONE)\
298    CCOUT_EXEC(1)
299  #endif
300
301  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
302   #define CCOUT2 \
303    if (getSoftDebugLevel() >= ORX_WARNING) \
304     CCOUT_EXEC(2)
305  #else
306   #define CCOUT2 if (ORX_NONE) \
307    CCOUT_EXEC(2)
308  #endif
309
310  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
311   #define CCOUT3 \
312    if (getSoftDebugLevel() >= ORX_INFO) \
313     CCOUT_EXEC(3)
314  #else
315   #define CCOUT3 if (ORX_NONE) \
316    CCOUT_EXEC(3)
317  #endif
318
319  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
320   #define CCOUT4 \
321    if (getSoftDebugLevel() >= ORX_DEBUG) \
322     CCOUT_EXEC(4)
323  #else
324   #define CCOUT4 if (ORX_NONE) \
325    CCOUT_EXEC(4)
326  #endif
327
328  #if ORX_HARD_DEBUG_LEVEL >= ORX_vDEBUG
329   #define CCOUT5 \
330    if (getSoftDebugLevel() >= ORX_vDEBUG) \
331     CCOUT_EXEC(5)
332  #else
333   #define CCOUT5 if (ORX_NONE) \
334    CCOUT_EXEC(5)
335  #endif
336
337 #else /* if ORX_PRINT_DEBUG_OUTPUT */
338  #define CCOUT(x) if (ORX_NONE) \
339   CCOUT_EXEC(5)
340 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
341
342#endif /* ifndef CCOUT */
343
344#endif /* _Debug_H__ */
Note: See TracBrowser for help on using the repository browser.