OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
gsAssert.h
1#ifndef __GSIASSERT_H__
2#define __GSIASSERT_H__
3
4#if defined(__LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus)
5extern "C" {
6#endif
9// Assert for GameSpy SDKs
10//
11// Usage:
12// 1) #define _DEBUG to enable assert. This should be set by compiler configuration.
13//
14// Todo:
15// Allow user to specify IP to send debug output to (remote log for PS2)
16
17
18// GS_ASSERT Use this to trap any programming bugs, such as range checks, invalid parameters
19// use at start of each function to check all parameters
20// also check all assumptions, ex// assume module is init.
21//
22
23// GS_FAIL() Use instead of GS_ASSERT(0) when reaching an illegal area of code
24// ex// the default: in a case statement that should be completely handled.
25
26
27/*
28 ***The reason for using a GameSpy assert or custom assert***
29
30 although assert is handled very gracefully on the windows platform, most consoles do very little of real use during assert.
31 Furthermore, the program counter is lost, along with the callstack sometimes.
32 By having a custom critical error function, an asm "break" can be set in it, or a debugger break point. a call stack is
33 immediately available. The error can be drawn onto the screen. And the choice to ignore can also be given, in order
34 to continue stepping through code and further debug.
35
36*/
37
40extern void gsDebugAssert (const char *format,const char *szError,const char *szFile, int line);
41#ifndef _DEBUG
42 // On non-debug builds, release builds, ignore all of this.
43 // be carefull never to have function calls within one of these macros, as they will
44 // be ignored.
45 // ex// BAD: GS_ASSERT( i== FN()) // FN() will never be called, i will never be set in release builds
46
47 #define GS_ASSERT(x) {}; // ex// GS_ASSERT( result == GS_OK )
48 #define GS_ASSERT_STR(x, t) {}; // ex// GS_ASSERT_STR( result == GS_OK ,"GSFunction failed")
49 #define GS_ASSERT_ALIGN_16(x) {};
50 #define GS_FAIL()
51 #define GS_FAIL_STR(x)
52
55#else
56
57 #define GS_ASSERT(x) { if(!(x)) { gsDebugAssert("ASSERT on '" #x "' [%s] in %s line:%d\n", "", __FILE__,__LINE__); } };
58 #define GS_ASSERT_STR(x,t) { if(!(x)) { gsDebugAssert("ASSERT on '" #x "' [%s] in %s line:%d\n", t, __FILE__,__LINE__); } };
59 #define GS_ASSERT_ALIGN_16(x) { if(((U32)(x))%16) { gsDebugAssert("ASSERT on '" #x "' [%s] in %s line:%d\n","16 byte misalign", __FILE__,__LINE__); } };
60 #define GS_FAIL() { gsDebugAssert("FAIL [%s] ln %s line:%d\n", "", __FILE__,__LINE__); };
61 #define GS_FAIL_STR(t) { gsDebugAssert("FAIL [%s] ln %s line:%d\n", t, __FILE__,__LINE__); };
62
63
64
65#endif // GSI_COMMON_DEBUG
66
67
68// This is the default assert condition handler
69typedef void (*gsDebugAssertCallback) (const char *string);
70
71// Call this function to override the default assert handler
72// New function should render message / log message based on string passed
73// calling this with NULL is restores the default setting.
74void gsDebugAssertCallbackSet(gsDebugAssertCallback theCallback);
75
76
77// This is like an assert, but test at compile, not run time.
78// ex use STATIC_CHECK(DIM(array) == enumArrayCount)
79#define GS_STATIC_CHECK(expr, msg) { CompileTimeError<((expr) != 0)> ERROR_##msg; (void)ERROR_##msg; }
80
81
82#if defined(__LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus)
83}
84#endif
85
86#endif // __GSIDEBUG_H__
@ string
string value
Definition json.hpp:2859