Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/util/Debug.h @ 2157

Last change on this file since 2157 was 2114, checked in by rgrieder, 16 years ago

Replaced all "@file Blah.cc" with "@file" for better flexibility. DoxyGen will use the filename as default.

  • Property svn:eol-style set to native
File size: 7.2 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
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;
58 */
59
60#ifndef _Debug_H__
61#define _Debug_H__
62
63#include "UtilPrereqs.h"
64
65#include <stdio.h>
66
67#include "OutputHandler.h"
68
69namespace orxonox
70{
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    }
79
80    using std::endl;
81}
82
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
89#define ORX_VERBOSE         5
90#define ORX_ULTRA           6
91
92//definitions
93#define ORX_PRINT_DEBUG_OUTPUT 1
94#define ORX_HARD_DEBUG_LEVEL ORX_VERBOSE
95
96#define COUT_EXEC(x) orxonox::OutputHandler::getOutStream().setOutputLevel(x)
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
106#define COUTORX_VERBOSE COUT5
107#define COUTORX_ULTRA   COUT6
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
115   #define COUT0 \
116   (orxonox::getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : COUT_EXEC(0)
117  #else
118   #define COUT0 \
119    false ? COUT_EXEC(0) : COUT_EXEC(0)
120  #endif
121
122  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
123   #define COUT1 \
124    (orxonox::getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : COUT_EXEC(1)
125  #else
126   #define COUT1 \
127    false ? COUT_EXEC(1) : COUT_EXEC(1)
128  #endif
129
130  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
131   #define COUT2 \
132    (orxonox::getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : COUT_EXEC(2)
133  #else
134   #define COUT2 \
135    false ? COUT_EXEC(2) : COUT_EXEC(2)
136  #endif
137
138  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
139   #define COUT3 \
140    (orxonox::getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : COUT_EXEC(3)
141  #else
142   #define COUT3 \
143    false ? COUT_EXEC(3) : COUT_EXEC(3)
144  #endif
145
146  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
147   #define COUT4 \
148    (orxonox::getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : COUT_EXEC(4)
149  #else
150   #define COUT4 \
151    false ? COUT_EXEC(4) : COUT_EXEC(4)
152  #endif
153
154  #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE
155   #define COUT5 \
156    (orxonox::getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : COUT_EXEC(5)
157  #else
158   #define COUT5 \
159    false ? COUT_EXEC(5) : COUT_EXEC(5)
160  #endif
161
162  #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA
163   #define COUT6 \
164    (orxonox::getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : COUT_EXEC(6)
165  #else
166   #define COUT6 \
167    false ? COUT_EXEC(6) : COUT_EXEC(6)
168  #endif
169
170 #else /* if ORX_PRINT_DEBUG_OUTPUT */
171  #define COUT(x) \
172    false ? COUT_EXEC(6) : COUT_EXEC(6)
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
186#define CCOUTORX_VERBOSE CCOUT5
187#define CCOUTORX_ULTRA   CCOUT6
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
199   #define CCOUT0 \
200    (orxonox::getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : CCOUT_EXEC(0)
201  #else
202   #define CCOUT0 \
203    false ? COUT_EXEC(0) : CCOUT_EXEC(0)
204  #endif
205
206  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
207   #define CCOUT1 \
208    (orxonox::getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : CCOUT_EXEC(1)
209  #else
210   #define CCOUT1 \
211    false ? COUT_EXEC(1) : CCOUT_EXEC(1)
212  #endif
213
214  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
215   #define CCOUT2 \
216    (orxonox::getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : CCOUT_EXEC(2)
217  #else
218   #define CCOUT2 \
219    false ? COUT_EXEC(2) : CCOUT_EXEC(2)
220  #endif
221
222  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
223   #define CCOUT3 \
224    (orxonox::getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : CCOUT_EXEC(3)
225  #else
226   #define CCOUT3 \
227    false ? COUT_EXEC(3) : CCOUT_EXEC(3)
228  #endif
229
230  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
231   #define CCOUT4 \
232    (orxonox::getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : CCOUT_EXEC(4)
233  #else
234   #define CCOUT4 \
235    false ? COUT_EXEC(4) : CCOUT_EXEC(4)
236  #endif
237
238  #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE
239   #define CCOUT5 \
240    (orxonox::getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : CCOUT_EXEC(5)
241  #else
242   #define CCOUT5 \
243    false ? COUT_EXEC(5) : CCOUT_EXEC(5)
244  #endif
245
246  #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA
247   #define CCOUT6 \
248    (orxonox::getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : CCOUT_EXEC(6)
249  #else
250   #define CCOUT6 \
251    false ? COUT_EXEC(6) : CCOUT_EXEC(6)
252  #endif
253
254 #else /* if ORX_PRINT_DEBUG_OUTPUT */
255  #define CCOUT(x) \
256   false ? CCOUT_EXEC(6) : CCOUT_EXEC(6)
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.