-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassert.h
135 lines (113 loc) · 4.23 KB
/
assert.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//-----------------------------------------------------------------------------
// Application Core Library
// Copyright (c) 2009-2012 DuJardin Consulting, LLC.
// Portions Copyright (c) 2009 GarageGames, Inc.
//-----------------------------------------------------------------------------
#ifndef ACL_CORE_ASSERT_H_
#define ACL_CORE_ASSERT_H_
#ifndef _ACL_TYPES_H_
#include "core/types.h"
#endif
#ifdef _DEBUG
#define ACL_ENABLE_ASSERTS
#endif
namespace ACLib
{
#ifdef ACL_ENABLE_ASSERTS
#define AssertWarn(x, y) \
do {\
if(((bool)(x)) == (bool)0) \
if(Assert::Get().processAssert(Assert::Warning, __FILE__, __LINE__, ACL_PRETTY_FUNCTION, y))\
ACL_DEBUG_BREAK\
} while(0)
#define AssertFatal(x, y)\
do {\
if(((bool)(x)) == (bool)0) \
if(Assert::Get().processAssert(Assert::Fatal, __FILE__, __LINE__, ACL_PRETTY_FUNCTION, y))\
ACL_DEBUG_BREAK\
} while(0)
#else
#define AssertFatal(x, y) { (void)sizeof(x); (void)sizeof(y); }
#define AssertWarn(x, y) { (void)sizeof(x); (void)sizeof(y); }
#endif
#define AssertISV(x, y)\
do {\
if(((bool)(x)) == (bool)0) \
if(Assert::Get().processAssert(Assert::Fatal_ISV, __FILE__, __LINE__, ACL_PRETTY_FUNCTION, y))\
ACL_DEBUG_BREAK\
} while(0)
class AssertImpl;
class Assert
{
public:
enum Type
{
Fatal_ISV, ///< Triggers in all build configurations
Fatal, ///< Only triggers in debug build configurations
Warning ///< Only triggers in debug build configurations and by default only prints to the console
};
/// @brief Trigger an assert.
/// @details This method will block until the assert is somehow dealt with, and will likely result
/// in the app exiting.
/// @param type The type of the assert.
/// @param filename The file in which the assert occurred
/// @param lineNumber The line on which the Assert* macro is
/// @param message A message that will be displayed/printed with the assert. Please make it informational!
bool processAssert(Type type, const char* filename, U32 lineNumber, const char* function, const char* message);
bool isProcessingAssert() const;
/// @brief Returns the global asserter
static Assert& Get();
/// Pushes impl to the top of the stack. The topmost impl will be used
/// to handle all asserts. Assert takes ownership of the given impl,
/// you should not keep a reference to it.
void pushImpl(AssertImpl* impl);
/// Pops the topmost impl from the stack.
/// @warning Don't call this if there's only one impl in the stack
void popImpl();
private:
struct Internal;
Internal* mInternal;
Assert();
~Assert();
Assert(const Assert&);
Assert& operator=(const Assert&);
};
namespace Private
{
template<int> struct CompileTimeError;
template<> struct CompileTimeError<true> {};
}
/// Compile time assert at function scope.
/// If the expression is false this macro will generate a compile
/// time error. The expression must be something that can be evaluated
/// at compile time, and the msg argument must be a legal variable name.
/// For example:
///@code
/// AssertStatic(sizeof(Node) <= 32,Structure_exceeds_cache_line_size);
///@endcode
/// @hideinitializer
#define AssertStatic(expr, msg) \
do { Private::CompileTimeError<((expr) != 0)> \
ASSERT_##msg; (void)ASSERT_##msg; } while(false)
/// Compile time assert at class or namespace scope.
/// See AssertStatic for more information.
#define AssertStaticNamespace(expr, msg) \
template<int test> struct ASSERT_##msg { Private::CompileTimeError<test> FAILED; }; \
enum { Bogus_##msg = sizeof(ASSERT_##msg<((expr) != 0)>) };
/*!
sprintf style string formating into a fixed temporary buffer.
@param in_msg sprintf style format string
@returns pointer to fixed buffer containing formatted string
\b Example:
\code
U8 a = 5;
S16 b = -10;
char *output = avar("hello %s! a=%u, b=%d", "world");
output = "hello world! a=5, b=-10"
\endcode
@warning avar uses a static fixed buffer. Treat the buffer as volatile data
and use it immediately. Other functions my use avar too and clobber the buffer.
*/
const char* avar(const char *in_msg, ...);
}
#endif