Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core3/src/util/Debug.h @ 1586

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

moved Debug.h, OutputHandler and OutputBuffer to util, to make COUT(x) available everywhere

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