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 | * Fabian 'x3n' Landau |
---|
24 | * Reto Grieder |
---|
25 | * Co-authors: |
---|
26 | * ... |
---|
27 | * |
---|
28 | */ |
---|
29 | |
---|
30 | /** |
---|
31 | @file |
---|
32 | @brief |
---|
33 | Handles different output-levels of errors, warnings, infos and debug information. |
---|
34 | |
---|
35 | The COUT(level) macro acts like std::cout, but the output is only performed if the given |
---|
36 | level is <= the soft debug level. |
---|
37 | |
---|
38 | There are two used values in this file: |
---|
39 | - The hard debug level is used during compile time. It describes the highest allowed output level. |
---|
40 | - The soft debug level is used during runtime and is the maximum of the three configurable |
---|
41 | output-levels for console, log file and in game shell. |
---|
42 | |
---|
43 | The separation between the three devices is done by the OutputHandler. |
---|
44 | |
---|
45 | Possible levels are: |
---|
46 | 0: Very important output |
---|
47 | 1: Errors |
---|
48 | 2: Warnings |
---|
49 | 3: Information |
---|
50 | 4: Debug information |
---|
51 | 5: More debug information |
---|
52 | 6: Crazy debug information |
---|
53 | |
---|
54 | Example: |
---|
55 | @code |
---|
56 | COUT(0) << "Very important output" << std::endl; |
---|
57 | COUT(1) << "Error: Something went wrong!" << std::endl; |
---|
58 | COUT(2) << "Warning: There might be a problem." << std::endl; |
---|
59 | COUT(3) << "Info: It's Monday" << std::endl; |
---|
60 | COUT(4) << "Debug: x is 1.23456" << std::endl; |
---|
61 | @endcode |
---|
62 | */ |
---|
63 | |
---|
64 | #ifndef _Util_Debug_H__ |
---|
65 | #define _Util_Debug_H__ |
---|
66 | |
---|
67 | #include "UtilPrereqs.h" |
---|
68 | #include "OutputHandler.h" |
---|
69 | |
---|
70 | namespace orxonox |
---|
71 | { |
---|
72 | // Just for convenience |
---|
73 | using std::endl; |
---|
74 | |
---|
75 | // Adjust this to discard certain output with level > hardDebugLevel at compile time already |
---|
76 | #ifdef ORXONOX_RELEASE |
---|
77 | const int hardDebugLevel = OutputLevel::Verbose; |
---|
78 | #elif defined(NDEBUG) |
---|
79 | const int hardDebugLevel = OutputLevel::Verbose; |
---|
80 | #else |
---|
81 | //! Maximum level for debug output that should be even processed at run time |
---|
82 | const int hardDebugLevel = OutputLevel::Ultra; |
---|
83 | #endif |
---|
84 | |
---|
85 | //! This function simply returns 0 and helps to suppress the "statement has no effect" compiler warning |
---|
86 | inline int debugDummyFunction() |
---|
87 | { |
---|
88 | return 0; |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | @brief |
---|
94 | Logs text output: use exactly like std::cout, but specify an output |
---|
95 | level as argument. |
---|
96 | @details |
---|
97 | (a > b ? 0 : c << "text") is equivalent to (a > b ? 0 : (c << "text")) |
---|
98 | where (a > b ? 0 : ) stands for COUT(x). This should explain how |
---|
99 | this macro magic can possibly even work ;) |
---|
100 | |
---|
101 | Example: |
---|
102 | @code |
---|
103 | COUT(3) << "Some info" << std::endl; |
---|
104 | @endcode |
---|
105 | @note |
---|
106 | The ? : operator requires both possible results to have the type of |
---|
107 | the first. This is achieved by the int conversion operator dummy |
---|
108 | in the OutputHandler. |
---|
109 | */ |
---|
110 | #define COUT(level) \ |
---|
111 | /*if*/ (level > orxonox::hardDebugLevel) ? \ |
---|
112 | orxonox::debugDummyFunction() \ |
---|
113 | /*else*/ : \ |
---|
114 | /*if*/ (level > orxonox::OutputHandler::getSoftDebugLevel()) ? \ |
---|
115 | orxonox::debugDummyFunction() \ |
---|
116 | /*else*/ : \ |
---|
117 | orxonox::OutputHandler::getOutStream(level) |
---|
118 | |
---|
119 | #endif /* _Util_Debug_H__ */ |
---|