[1505] | 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 | /** |
---|
[1791] | 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; |
---|
[1505] | 58 | */ |
---|
| 59 | |
---|
| 60 | #ifndef _Debug_H__ |
---|
| 61 | #define _Debug_H__ |
---|
| 62 | |
---|
[1586] | 63 | #include "UtilPrereqs.h" |
---|
[1505] | 64 | |
---|
| 65 | #include <stdio.h> |
---|
| 66 | |
---|
| 67 | #include "OutputHandler.h" |
---|
| 68 | |
---|
| 69 | |
---|
[1586] | 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 | */ |
---|
| 74 | static inline int getSoftDebugLevel() |
---|
| 75 | { |
---|
| 76 | return orxonox::OutputHandler::getSoftDebugLevel(); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
[1505] | 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 |
---|
[1585] | 86 | #define ORX_VERBOSE 5 |
---|
| 87 | #define ORX_ULTRA 6 |
---|
[1505] | 88 | |
---|
| 89 | //definitions |
---|
[1585] | 90 | #define ORX_PRINT_DEBUG_OUTPUT 1 |
---|
| 91 | #define ORX_HARD_DEBUG_LEVEL ORX_VERBOSE |
---|
[1505] | 92 | |
---|
[1585] | 93 | #define COUT_EXEC(x) orxonox::OutputHandler::getOutStream().setOutputLevel(x) |
---|
[1505] | 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 |
---|
[1585] | 103 | #define COUTORX_VERBOSE COUT5 |
---|
| 104 | #define COUTORX_ULTRA COUT6 |
---|
[1505] | 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 |
---|
[1610] | 112 | #define COUT0 \ |
---|
[1593] | 113 | (getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : COUT_EXEC(0) |
---|
[1505] | 114 | #else |
---|
[1585] | 115 | #define COUT0 \ |
---|
| 116 | false ? COUT_EXEC(0) : COUT_EXEC(0) |
---|
[1505] | 117 | #endif |
---|
| 118 | |
---|
| 119 | #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR |
---|
[1610] | 120 | #define COUT1 \ |
---|
[1593] | 121 | (getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : COUT_EXEC(1) |
---|
[1505] | 122 | #else |
---|
[1585] | 123 | #define COUT1 \ |
---|
| 124 | false ? COUT_EXEC(1) : COUT_EXEC(1) |
---|
[1505] | 125 | #endif |
---|
| 126 | |
---|
| 127 | #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING |
---|
| 128 | #define COUT2 \ |
---|
[1593] | 129 | (getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : COUT_EXEC(2) |
---|
[1505] | 130 | #else |
---|
[1585] | 131 | #define COUT2 \ |
---|
| 132 | false ? COUT_EXEC(2) : COUT_EXEC(2) |
---|
[1505] | 133 | #endif |
---|
| 134 | |
---|
| 135 | #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO |
---|
| 136 | #define COUT3 \ |
---|
[1593] | 137 | (getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : COUT_EXEC(3) |
---|
[1505] | 138 | #else |
---|
[1585] | 139 | #define COUT3 \ |
---|
| 140 | false ? COUT_EXEC(3) : COUT_EXEC(3) |
---|
[1505] | 141 | #endif |
---|
| 142 | |
---|
| 143 | #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG |
---|
| 144 | #define COUT4 \ |
---|
[1593] | 145 | (getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : COUT_EXEC(4) |
---|
[1505] | 146 | #else |
---|
[1585] | 147 | #define COUT4 \ |
---|
| 148 | false ? COUT_EXEC(4) : COUT_EXEC(4) |
---|
[1505] | 149 | #endif |
---|
| 150 | |
---|
[1585] | 151 | #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE |
---|
[1505] | 152 | #define COUT5 \ |
---|
[1593] | 153 | (getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : COUT_EXEC(5) |
---|
[1505] | 154 | #else |
---|
[1585] | 155 | #define COUT5 \ |
---|
| 156 | false ? COUT_EXEC(5) : COUT_EXEC(5) |
---|
[1505] | 157 | #endif |
---|
| 158 | |
---|
[1585] | 159 | #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA |
---|
| 160 | #define COUT6 \ |
---|
[1593] | 161 | (getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : COUT_EXEC(6) |
---|
[1585] | 162 | #else |
---|
| 163 | #define COUT6 \ |
---|
| 164 | false ? COUT_EXEC(6) : COUT_EXEC(6) |
---|
| 165 | #endif |
---|
| 166 | |
---|
[1505] | 167 | #else /* if ORX_PRINT_DEBUG_OUTPUT */ |
---|
[1585] | 168 | #define COUT(x) \ |
---|
| 169 | false ? COUT_EXEC(6) : COUT_EXEC(6) |
---|
[1505] | 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 |
---|
[1585] | 183 | #define CCOUTORX_VERBOSE CCOUT5 |
---|
| 184 | #define CCOUTORX_ULTRA CCOUT6 |
---|
[1505] | 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 |
---|
[1610] | 196 | #define CCOUT0 \ |
---|
[1593] | 197 | (getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : CCOUT_EXEC(0) |
---|
[1505] | 198 | #else |
---|
[1585] | 199 | #define CCOUT0 \ |
---|
[1593] | 200 | false ? COUT_EXEC(0) : CCOUT_EXEC(0) |
---|
[1505] | 201 | #endif |
---|
| 202 | |
---|
| 203 | #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR |
---|
[1610] | 204 | #define CCOUT1 \ |
---|
[1593] | 205 | (getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : CCOUT_EXEC(1) |
---|
[1505] | 206 | #else |
---|
[1585] | 207 | #define CCOUT1 \ |
---|
[1593] | 208 | false ? COUT_EXEC(1) : CCOUT_EXEC(1) |
---|
[1505] | 209 | #endif |
---|
| 210 | |
---|
| 211 | #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING |
---|
| 212 | #define CCOUT2 \ |
---|
[1593] | 213 | (getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : CCOUT_EXEC(2) |
---|
[1505] | 214 | #else |
---|
[1585] | 215 | #define CCOUT2 \ |
---|
[1593] | 216 | false ? COUT_EXEC(2) : CCOUT_EXEC(2) |
---|
[1505] | 217 | #endif |
---|
| 218 | |
---|
| 219 | #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO |
---|
| 220 | #define CCOUT3 \ |
---|
[1593] | 221 | (getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : CCOUT_EXEC(3) |
---|
[1505] | 222 | #else |
---|
[1585] | 223 | #define CCOUT3 \ |
---|
[1593] | 224 | false ? COUT_EXEC(3) : CCOUT_EXEC(3) |
---|
[1505] | 225 | #endif |
---|
| 226 | |
---|
| 227 | #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG |
---|
| 228 | #define CCOUT4 \ |
---|
[1593] | 229 | (getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : CCOUT_EXEC(4) |
---|
[1505] | 230 | #else |
---|
[1585] | 231 | #define CCOUT4 \ |
---|
[1593] | 232 | false ? COUT_EXEC(4) : CCOUT_EXEC(4) |
---|
[1505] | 233 | #endif |
---|
| 234 | |
---|
[1585] | 235 | #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE |
---|
[1505] | 236 | #define CCOUT5 \ |
---|
[1593] | 237 | (getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : CCOUT_EXEC(5) |
---|
[1505] | 238 | #else |
---|
[1585] | 239 | #define CCOUT5 \ |
---|
[1593] | 240 | false ? COUT_EXEC(5) : CCOUT_EXEC(5) |
---|
[1505] | 241 | #endif |
---|
| 242 | |
---|
[1585] | 243 | #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA |
---|
| 244 | #define CCOUT6 \ |
---|
[1593] | 245 | (getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : CCOUT_EXEC(6) |
---|
[1585] | 246 | #else |
---|
| 247 | #define CCOUT6 \ |
---|
[1593] | 248 | false ? COUT_EXEC(6) : CCOUT_EXEC(6) |
---|
[1585] | 249 | #endif |
---|
| 250 | |
---|
[1505] | 251 | #else /* if ORX_PRINT_DEBUG_OUTPUT */ |
---|
[1585] | 252 | #define CCOUT(x) \ |
---|
| 253 | false ? CCOUT_EXEC(6) : CCOUT_EXEC(6) |
---|
[1505] | 254 | #endif /* if ORX_PRINT_DEBUG_OUTPUT */ |
---|
| 255 | |
---|
| 256 | #endif /* ifndef CCOUT */ |
---|
| 257 | |
---|
| 258 | #endif /* _Debug_H__ */ |
---|