summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/include/glib/assertutils.inc
blob: 83cd90d920f148e07757f77d28a77dbc3855ee0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#if defined _assertutils_included
#endinput
#endif
#define _assertutils_included

/* Compile time settings for this include. Should be defined before including this file.
*  #define ASSERTUTILS_DISABLE			//Disables all assertions
*  #define ASSERTUTILS_FAILSTATE_FUNC	//Define the name of the function that should be called when assertion is hit
*/

#if !defined SNAME
#define __SNAME ""
#else
#define __SNAME SNAME
#endif

#define ASSERT_FMT_STRING_LEN 512

#if defined ASSERTUTILS_DISABLE

#define ASSERT(%1)%2;
#define ASSERT_MSG(%1,%2)%3;
#define ASSERT_FMT(%1,%2)%3;
#define ASSERT_FINAL(%1)%2;
#define ASSERT_FINAL_MSG(%1,%2)%3;

#elseif defined ASSERTUTILS_FAILSTATE_FUNC

#define ASSERT(%1) if(!(%1)) ASSERTUTILS_FAILSTATE_FUNC(__SNAME..."Assertion failed: \""...#%1..."\"")
#define ASSERT_MSG(%1,%2) if(!(%1)) ASSERTUTILS_FAILSTATE_FUNC(__SNAME...%2)
#define ASSERT_FMT(%1,%2) if(!(%1)) ASSERTUTILS_FAILSTATE_FUNC(__SNAME...%2)
#define ASSERT_FINAL(%1) if(!(%1)) SetFailState(__SNAME..."Assertion failed: \""...#%1..."\"")
#define ASSERT_FINAL_MSG(%1,%2) if(!(%1)) SetFailState(__SNAME...%2)

#else

#define ASSERT(%1) if(!(%1)) SetFailState(__SNAME..."Assertion failed: \""...#%1..."\"")
#define ASSERT_MSG(%1,%2) if(!(%1)) SetFailState(__SNAME...%2)
#define ASSERT_FMT(%1,%2) if(!(%1)) SetFailState(__SNAME...%2)
#define ASSERT_FINAL(%1) ASSERT(%1)
#define ASSERT_FINAL_MSG(%1,%2) ASSERT_MSG(%1,%2)

#endif

// Might be redundant as default ASSERT_MSG accept format arguments just fine.
#if 0
stock void ASSERT_FMT(bool result, char[] fmt, any ...)
{
#if !defined ASSERTUTILS_DISABLE
	if(!result)
	{
		char buff[ASSERT_FMT_STRING_LEN];
		VFormat(buff, sizeof(buff), fmt, 3);
		
		SetFailState(__SNAME..."%s", buff);
	}
#endif
}
#endif

#undef ASSERT_FMT_STRING_LEN