orx  stable
Portable Game Engine
orxDebug.h
Go to the documentation of this file.
1 /* Orx - Portable Game Engine
2  *
3  * Copyright (c) 2008-2017 Orx-Project
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  *
18  * 2. Altered source versions must be plainly marked as such, and must not be
19  * misrepresented as being the original software.
20  *
21  * 3. This notice may not be removed or altered from any source
22  * distribution.
23  */
24 
45 #ifndef _orxDEBUG_H_
46 #define _orxDEBUG_H_
47 
48 #include "orxInclude.h"
49 
50 
51 /* *** orxDEBUG flags *** */
52 
53 #define orxDEBUG_KU32_STATIC_FLAG_NONE 0x00000000
54 
55 #define orxDEBUG_KU32_STATIC_FLAG_TIMESTAMP 0x00000001
56 #define orxDEBUG_KU32_STATIC_FLAG_FULL_TIMESTAMP 0x00000002
57 #define orxDEBUG_KU32_STATIC_FLAG_TYPE 0x00000004
58 #define orxDEBUG_KU32_STATIC_FLAG_TAGGED 0x00000008
59 
60 #define orxDEBUG_KU32_STATIC_FLAG_FILE 0x00000010
61 #define orxDEBUG_KU32_STATIC_FLAG_TERMINAL 0x00000020
62 #define orxDEBUG_KU32_STATIC_FLAG_CONSOLE 0x00000040
63 
64 #define orxDEBUG_KU32_STATIC_MASK_DEFAULT 0x00000075
65 
66 #define orxDEBUG_KU32_STATIC_MASK_DEBUG 0x0000003D
67 
68 #define orxDEBUG_KU32_STATIC_MASK_USER_ALL 0x0FFFFFFF
69 
70 
71 /* *** Misc *** */
72 
73 #define orxDEBUG_KZ_DEFAULT_DEBUG_FILE "orx-debug.log"
74 #define orxDEBUG_KZ_DEFAULT_LOG_FILE "orx.log"
75 #define orxDEBUG_KZ_DEFAULT_LOG_SUFFIX ".log"
76 #define orxDEBUG_KZ_DEFAULT_DEBUG_SUFFIX "-debug.log"
77 
78 
79 /* *** Debug Macros *** */
80 
81 /* Log message, compiler specific */
82 #if defined(__orxGCC__) || defined(__orxLLVM__)
83 
84  #define orxLOG(STRING, ...) \
85  do \
86  { \
87  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, ##__VA_ARGS__); \
88  } while(orxFALSE)
89 
90  #define orxLOG_TERMINAL(STRING, ...) \
91  do \
92  { \
93  orxU32 u32DebugFlags; \
94  u32DebugFlags = _orxDebug_GetFlags(); \
95  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_FLAG_TERMINAL, \
96  orxDEBUG_KU32_STATIC_FLAG_FILE \
97  |orxDEBUG_KU32_STATIC_FLAG_CONSOLE); \
98  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, ##__VA_ARGS__); \
99  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
100  } while(orxFALSE)
101 
102  #define orxLOG_FILE(STRING, ...) \
103  do \
104  { \
105  orxU32 u32DebugFlags; \
106  u32DebugFlags = _orxDebug_GetFlags(); \
107  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_FLAG_FILE, \
108  orxDEBUG_KU32_STATIC_FLAG_CONSOLE \
109  |orxDEBUG_KU32_STATIC_FLAG_TERMINAL); \
110  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, ##__VA_ARGS__); \
111  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
112  } while(orxFALSE)
113 
114  #define orxLOG_CONSOLE(STRING, ...) \
115  do \
116  { \
117  orxU32 u32DebugFlags; \
118  u32DebugFlags = _orxDebug_GetFlags(); \
119  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_FLAG_CONSOLE, \
120  orxDEBUG_KU32_STATIC_FLAG_FILE \
121  orxDEBUG_KU32_STATIC_FLAG_TERMINAL); \
122  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, ##__VA_ARGS__); \
123  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
124  } while(orxFALSE)
125 
126 #else /* __orxGCC__ || __orxLLVM__ */
127  #ifdef __orxMSVC__
128 
129  #define orxLOG(STRING, ...) \
130  do \
131  { \
132  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, __VA_ARGS__); \
133  } while(orxFALSE)
134 
135  #define orxLOG_TERMINAL(STRING, ...) \
136  do \
137  { \
138  orxU32 u32DebugFlags; \
139  u32DebugFlags = _orxDebug_GetFlags(); \
140  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_FLAG_TERMINAL, \
141  orxDEBUG_KU32_STATIC_FLAG_FILE \
142  |orxDEBUG_KU32_STATIC_FLAG_CONSOLE); \
143  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, __VA_ARGS__); \
144  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
145  } while(orxFALSE)
146 
147  #define orxLOG_FILE(STRING, ...) \
148  do \
149  { \
150  orxU32 u32DebugFlags; \
151  u32DebugFlags = _orxDebug_GetFlags(); \
152  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_FLAG_FILE, \
153  orxDEBUG_KU32_STATIC_FLAG_CONSOLE \
154  |orxDEBUG_KU32_STATIC_FLAG_TERMINAL); \
155  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, __VA_ARGS__); \
156  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
157  } while(orxFALSE)
158 
159  #define orxLOG_CONSOLE(STRING, ...) \
160  do \
161  { \
162  orxU32 u32DebugFlags; \
163  u32DebugFlags = _orxDebug_GetFlags(); \
164  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_FLAG_CONSOLE, \
165  orxDEBUG_KU32_STATIC_FLAG_FILE \
166  orxDEBUG_KU32_STATIC_FLAG_TERMINAL); \
167  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, __VA_ARGS__); \
168  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
169  } while(orxFALSE)
170 
171  #endif /* __orxMSVC__ */
172 #endif /* __orcGCC__ || __orxLLVM__ */
173 
174 #define orxDEBUG_INIT() \
175 do \
176 { \
177  orxU32 u32DebugFlags; \
178  _orxDebug_Init(); \
179  u32DebugFlags = _orxDebug_GetFlags(); \
180  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_MASK_DEBUG, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
181  if(orxSystem_GetVersionNumeric() < __orxVERSION__) \
182  { \
183  orxLOG("The version of the runtime library [" orxANSI_KZ_COLOR_FG_GREEN "%s" \
184  orxANSI_KZ_COLOR_FG_DEFAULT "] is " orxANSI_KZ_COLOR_FG_RED orxANSI_KZ_COLOR_BLINK_ON "older" \
185  orxANSI_KZ_COLOR_FG_DEFAULT orxANSI_KZ_COLOR_BLINK_OFF " than the version used when compiling this program [" \
186  orxANSI_KZ_COLOR_FG_GREEN "%s" orxANSI_KZ_COLOR_FG_DEFAULT "]." \
187  orxANSI_KZ_COLOR_FG_RED orxANSI_KZ_COLOR_BLINK_ON " Problems will likely ensue!", \
188  orxSystem_GetVersionFullString(), __orxVERSION_FULL_STRING__); \
189  } \
190  else if(orxSystem_GetVersionNumeric() > __orxVERSION__) \
191  { \
192  orxLOG("The version of the runtime library [" orxANSI_KZ_COLOR_FG_GREEN "%s" \
193  orxANSI_KZ_COLOR_FG_DEFAULT "] is " orxANSI_KZ_COLOR_FG_YELLOW orxANSI_KZ_COLOR_BLINK_ON "more recent" \
194  orxANSI_KZ_COLOR_FG_DEFAULT orxANSI_KZ_COLOR_BLINK_OFF " than the version used when compiling this program [" \
195  orxANSI_KZ_COLOR_FG_GREEN "%s" orxANSI_KZ_COLOR_FG_DEFAULT "]." \
196  orxANSI_KZ_COLOR_FG_YELLOW orxANSI_KZ_COLOR_BLINK_ON " Problems may arise due to possible incompatibilities!",\
197  orxSystem_GetVersionFullString(), __orxVERSION_FULL_STRING__); \
198  } \
199  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
200 } \
201 while(orxFALSE)
202 #define orxDEBUG_EXIT() _orxDebug_Exit()
203 
204 #ifdef __orxDEBUG__
205 
206  /* Debug print, compiler specific */
207  #if defined(__orxGCC__) || defined(__orxLLVM__)
208  #define orxDEBUG_PRINT(LEVEL, STRING, ...) \
209  do \
210  { \
211  orxU32 u32DebugFlags; \
212  u32DebugFlags = _orxDebug_GetFlags(); \
213  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_MASK_DEBUG, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
214  _orxDebug_Log(LEVEL, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, ##__VA_ARGS__); \
215  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
216  } while(orxFALSE)
217  #else /* __orxGCC__ || __orxLLVM__ */
218  #ifdef __orxMSVC__
219  #define orxDEBUG_PRINT(LEVEL, STRING, ...) \
220  do \
221  { \
222  orxU32 u32DebugFlags; \
223  u32DebugFlags = _orxDebug_GetFlags(); \
224  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_MASK_DEBUG, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
225  _orxDebug_Log(LEVEL, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, __VA_ARGS__); \
226  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
227  } while(orxFALSE)
228  #endif /* __orxMSVC__ */
229  #endif /* __orcGCC__ || __orxLLVM__ */
230 
231  /* End platform specific */
232 
233  #define orxDEBUG_ENABLE_LEVEL(LEVEL, ENABLE)_orxDebug_EnableLevel(LEVEL, ENABLE)
234  #define orxDEBUG_IS_LEVEL_ENABLED(LEVEL) _orxDebug_IsLevelEnabled(LEVEL)
235 
236  #define orxDEBUG_SET_FLAGS(SET, UNSET) _orxDebug_SetFlags(SET, UNSET)
237  #define orxDEBUG_GET_FLAGS() _orxDebug_GetFlags()
238 
239  /* Break */
240  #define orxBREAK() _orxDebug_Break()
241 
242  /* Files */
243  #define orxDEBUG_SETDEBUGFILE(FILE) _orxDebug_SetDebugFile(FILE)
244  #define orxDEBUG_SETLOGFILE(FILE) _orxDebug_SetLogFile(FILE)
245  #define orxDEBUG_SETBASEFILENAME(FILE) \
246  do \
247  { \
248  orxCHAR zBuffer[256]; \
249  zBuffer[255] = orxCHAR_NULL; \
250  strncpy(zBuffer, FILE, 255); \
251  strncat(zBuffer, orxDEBUG_KZ_DEFAULT_DEBUG_SUFFIX, 255);\
252  _orxDebug_SetDebugFile(zBuffer); \
253  strncpy(zBuffer, FILE, 255); \
254  strncat(zBuffer, orxDEBUG_KZ_DEFAULT_LOG_SUFFIX, 255); \
255  _orxDebug_SetLogFile(zBuffer); \
256  } while(orxFALSE)
257 
258  /* Assert */
259  #if defined(__orxGCC__) || defined(__orxLLVM__)
260  #define orxASSERT(TEST, ...) \
261  if(!(TEST)) \
262  { \
263  orxDEBUG_PRINT(orxDEBUG_LEVEL_ASSERT, orxANSI_KZ_COLOR_BG_RED orxANSI_KZ_COLOR_FG_WHITE orxANSI_KZ_COLOR_BLINK_ON "FAILED ASSERTION [" #TEST "]", ##__VA_ARGS__); \
264  orxBREAK(); \
265  }
266  #else /* __orxGCC__ || __orxLLVM__ */
267  #ifdef __orxMSVC__
268  #define orxASSERT(TEST, ...) \
269  if(!(TEST)) \
270  { \
271  orxDEBUG_PRINT(orxDEBUG_LEVEL_ASSERT, orxANSI_KZ_COLOR_BG_RED orxANSI_KZ_COLOR_FG_WHITE orxANSI_KZ_COLOR_BLINK_ON "FAILED ASSERTION [" #TEST "]", __VA_ARGS__); \
272  orxBREAK(); \
273  }
274  #endif /* __orxMSVC__ */
275  #endif /* __orcGCC__ || __orxLLVM__ */
276 
277 #else /* __orxDEBUG__ */
278 
279  #define orxDEBUG_PRINT(LEVEL, STRING, ...)
280 
281  #define orxBREAK()
282 
283  #define orxDEBUG_ENABLE_LEVEL(LEVEL, ENABLE)_orxDebug_EnableLevel(LEVEL, ENABLE)
284  #define orxDEBUG_IS_LEVEL_ENABLED(LEVEL) _orxDebug_IsLevelEnabled(LEVEL)
285 
286  #define orxDEBUG_SETDEBUGFILE(FILE)
287  #define orxDEBUG_SETLOGFILE(FILE) _orxDebug_SetLogFile(FILE)
288  #define orxDEBUG_SETBASEFILENAME(FILE) \
289  do \
290  { \
291  orxCHAR zBuffer[256]; \
292  zBuffer[255] = orxCHAR_NULL; \
293  strncpy(zBuffer, FILE, 255); \
294  strncat(zBuffer, orxDEBUG_KZ_DEFAULT_LOG_SUFFIX, 255); \
295  _orxDebug_SetLogFile(zBuffer); \
296  } while(orxFALSE)
297 
298  #define orxASSERT(TEST, ...)
299 
300  #define orxDEBUG_SET_FLAGS(SET, UNSET) _orxDebug_SetFlags(SET, UNSET)
301  #define orxDEBUG_GET_FLAGS() _orxDebug_GetFlags()
302 
303 #endif /* __orxDEBUG__ */
304 
305 
306 
307 /*****************************************************************************/
308 
309 /* *** Debug defines. *** */
310 
311 #define orxDEBUG_KS32_BUFFER_OUTPUT_SIZE 2048
312 
313 #define orxDEBUG_KZ_DATE_FORMAT orxANSI_KZ_COLOR_FG_CYAN "[%H:%M:%S]" orxANSI_KZ_COLOR_RESET
314 #define orxDEBUG_KZ_DATE_FULL_FORMAT orxANSI_KZ_COLOR_FG_CYAN "[%Y-%m-%d %H:%M:%S]" orxANSI_KZ_COLOR_RESET
315 
316 #define orxDEBUG_KZ_TYPE_LOG_FORMAT orxANSI_KZ_COLOR_FG_GREEN "[%s]" orxANSI_KZ_COLOR_RESET
317 #define orxDEBUG_KZ_TYPE_WARNING_FORMAT orxANSI_KZ_COLOR_FG_YELLOW "[%s]" orxANSI_KZ_COLOR_RESET
318 #define orxDEBUG_KZ_TYPE_ERROR_FORMAT orxANSI_KZ_COLOR_FG_RED "[%s]" orxANSI_KZ_COLOR_RESET
319 
320 #define orxDEBUG_KZ_FILE_FORMAT orxANSI_KZ_COLOR_FG_MAGENTA "[%s:%s(%u)]" orxANSI_KZ_COLOR_RESET
321 
322 
323 /*****************************************************************************/
324 
325 /* *** Debug types. *** */
326 typedef enum __orxDEBUG_LEVEL_t
327 {
356 
358 
359  orxDEBUG_LEVEL_ALL = 0xFFFFFFFE,
361  orxDEBUG_LEVEL_NONE = orxENUM_NONE
362 
364 
365 
366 /*****************************************************************************/
367 
368 /* *** Functions *** */
369 
373 extern orxDLLAPI orxSTATUS orxFASTCALL _orxDebug_Init();
374 
376 extern orxDLLAPI void orxFASTCALL _orxDebug_Exit();
377 
385 extern orxDLLAPI void orxCDECL _orxDebug_Log(orxDEBUG_LEVEL _eLevel, const orxSTRING _zFunction, const orxSTRING _zFile, orxU32 _u32Line, const orxSTRING _zFormat, ...);
386 
391 extern orxDLLAPI void orxFASTCALL _orxDebug_EnableLevel(orxDEBUG_LEVEL _eLevel, orxBOOL _bEnable);
392 
396 extern orxDLLAPI orxBOOL orxFASTCALL _orxDebug_IsLevelEnabled(orxDEBUG_LEVEL _eLevel);
397 
402 extern orxDLLAPI void orxFASTCALL _orxDebug_SetFlags(orxU32 _u32Add, orxU32 _u32Remove);
403 
407 extern orxDLLAPI orxU32 orxFASTCALL _orxDebug_GetFlags();
408 
410 extern orxDLLAPI void orxFASTCALL _orxDebug_Break();
411 
415 extern orxDLLAPI void orxFASTCALL _orxDebug_SetDebugFile(const orxSTRING _zFileName);
416 
420 extern orxDLLAPI void orxFASTCALL _orxDebug_SetLogFile(const orxSTRING _zFileName);
421 
422 #endif /* __orxDEBUG_H_ */
423 
orxDLLAPI void orxFASTCALL _orxDebug_SetDebugFile(const orxSTRING _zFileName)
orxDLLAPI void orxFASTCALL _orxDebug_EnableLevel(orxDEBUG_LEVEL _eLevel, orxBOOL _bEnable)
orxDLLAPI void orxFASTCALL _orxDebug_SetLogFile(const orxSTRING _zFileName)
orxDLLAPI void orxCDECL _orxDebug_Log(orxDEBUG_LEVEL _eLevel, const orxSTRING _zFunction, const orxSTRING _zFile, orxU32 _u32Line, const orxSTRING _zFormat,...)
orxDLLAPI void orxFASTCALL _orxDebug_Break()
orxDLLAPI orxBOOL orxFASTCALL _orxDebug_IsLevelEnabled(orxDEBUG_LEVEL _eLevel)
orxDLLAPI void orxFASTCALL _orxDebug_Exit()
orxSTATUS
Definition: orxType.h:243
orxDLLAPI orxSTATUS orxFASTCALL _orxDebug_Init()
orxDLLAPI orxU32 orxFASTCALL _orxDebug_GetFlags()
#define orxDLLAPI
Definition: orxDecl.h:387
orxDLLAPI void orxFASTCALL _orxDebug_SetFlags(orxU32 _u32Add, orxU32 _u32Remove)
orxDEBUG_LEVEL
Definition: orxDebug.h:326

Generated for orx by doxygen 1.5.6