Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/util/Debug.h @ 1848

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

added comments to all my classes in util

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