6 #ifndef UT_ASSERT_H_INCLUDED
7 #define UT_ASSERT_H_INCLUDED
11 #define UT_ASSERT_LEVEL_NONE 0
12 #define UT_ASSERT_LEVEL_NORMAL 1
13 #define UT_ASSERT_LEVEL_PARANOID 2
14 #define UT_ASSERT_LEVEL_SLOW 3
16 #ifndef UT_ASSERT_LEVEL
17 #define UT_ASSERT_LEVEL UT_ASSERT_LEVEL_NONE
21 UT_API void UT_Assert(
const char *file,
int linenum,
const char *
function,
22 const char *condition,
const char *reason,
int &ignoreflag);
26 const char *
function,
const char *condition,
int &ignoreflag,
27 const char *reason_fmt...);
63 const char *
what() const noexcept {
return myWhat; }
71 # define UT_ASSERT_FUNC __PRETTY_FUNCTION__
72 #elif defined(_MSC_VER)
73 # define UT_ASSERT_FUNC __FUNCSIG__
74 #elif defined(__FUNCTION__)
75 # define UT_ASSERT_FUNC __FUNCTION__ "()"
77 # define UT_ASSERT_FUNC ((char *)0)
80 #if (UT_ASSERT_LEVEL > UT_ASSERT_LEVEL_NONE)
81 #ifdef UT_INTERNAL_ASSERT
82 #error UT_INTERNAL_UT_ASSERT is already defined!
84 #define UT_INTERNAL_ASSERT(ZZ, ...) \
87 static int ignore = 0; \
89 UT_AssertFormat( __FILE__, __LINE__, UT_ASSERT_FUNC, \
90 #ZZ, ignore, __VA_ARGS__); \
92 #define UT_INTERNAL_VERIFY(ZZ, ...) \
94 static int ignore = 0; \
96 if( !(ZZ) && !ignore ) \
97 UT_AssertFormat( __FILE__, __LINE__, UT_ASSERT_FUNC, \
98 #ZZ, ignore, __VA_ARGS__); \
101 #define UT_INTERNAL_VERIFY_RETURN(ZZ, RV) \
104 static int ignore = 0; \
106 UT_Assert( __FILE__, __LINE__, UT_ASSERT_FUNC, #ZZ, 0, \
112 #ifdef UT_ASSERT_SLOW
113 #error UT_ASSERT_SLOW is already defined!
116 #error UT_ASSERT_P is already defined!
119 #error UT_ASSERT is already defined!
121 #ifdef UT_ASSERT_MSG_SLOW
122 #error UT_ASSERT_MSG_SLOW is already defined!
124 #ifdef UT_ASSERT_MSG_P
125 #error UT_ASSERT_MSG_P is already defined!
128 #error UT_ASSERT_MSG is already defined!
132 #if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_SLOW)
133 #define UT_ASSERT_SLOW(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
134 #define UT_ASSERT_P(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
135 #define UT_ASSERT(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
136 #define UT_ASSERT_MSG_SLOW(ZZ, ...) UT_INTERNAL_ASSERT(ZZ, __VA_ARGS__)
137 #define UT_ASSERT_MSG_P(ZZ, ...) UT_INTERNAL_ASSERT(ZZ, __VA_ARGS__)
138 #define UT_ASSERT_MSG(ZZ, ...) UT_INTERNAL_ASSERT(ZZ, __VA_ARGS__)
139 #elif (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_PARANOID)
140 #define UT_ASSERT_SLOW(ZZ) ((void)0)
141 #define UT_ASSERT_P(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
142 #define UT_ASSERT(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
143 #define UT_ASSERT_MSG_SLOW(ZZ, ...) ((void)0)
144 #define UT_ASSERT_MSG_P(ZZ, ...) UT_INTERNAL_ASSERT(ZZ, __VA_ARGS__)
145 #define UT_ASSERT_MSG(ZZ, ...) UT_INTERNAL_ASSERT(ZZ, __VA_ARGS__)
146 #elif (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL)
147 #define UT_ASSERT_SLOW(ZZ) ((void)0)
148 #define UT_ASSERT_P(ZZ) ((void)0)
149 #define UT_ASSERT(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
150 #define UT_ASSERT_MSG_SLOW(ZZ, ...) ((void)0)
151 #define UT_ASSERT_MSG_P(ZZ, ...) ((void)0)
152 #define UT_ASSERT_MSG(ZZ, ...) UT_INTERNAL_ASSERT(ZZ, __VA_ARGS__)
153 #else // if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NONE)
154 #define UT_ASSERT_SLOW(ZZ) ((void)0)
155 #define UT_ASSERT_P(ZZ) ((void)0)
156 #define UT_ASSERT(ZZ) ((void)0)
157 #define UT_ASSERT_MSG_SLOW(ZZ, ...) ((void)0)
158 #define UT_ASSERT_MSG_P(ZZ, ...) ((void)0)
159 #define UT_ASSERT_MSG(ZZ, ...) ((void)0)
163 #define UT_ASSERT_COMPILETIME(expr) SYS_STATIC_ASSERT(expr)
170 #if UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL
171 #define UT_IF_ASSERT(ZZ) ZZ
172 #define UT_IFNOT_ASSERT(ZZ)
174 #define UT_IF_ASSERT(ZZ)
175 #define UT_IFNOT_ASSERT(ZZ) ZZ
178 #if UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_PARANOID
179 #define UT_IF_ASSERT_P(ZZ) ZZ
180 #define UT_IFNOT_ASSERT_P(ZZ)
182 #define UT_IF_ASSERT_P(ZZ)
183 #define UT_IFNOT_ASSERT_P(ZZ) ZZ
186 #if UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_SLOW
187 #define UT_IF_ASSERT_SLOW(ZZ) ZZ
188 #define UT_IFNOT_ASSERT_SLOW(ZZ)
190 #define UT_IF_ASSERT_SLOW(ZZ)
191 #define UT_IFNOT_ASSERT_SLOW(ZZ) ZZ
196 #if UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL
197 #define UT_VERIFY(expr) UT_INTERNAL_VERIFY(expr, 0)
198 #define UT_VERIFY_MSG(expr, ...) UT_INTERNAL_VERIFY(expr, __VA_ARGS__)
199 #define UT_VERIFY_RETURN(ZZ, RV) UT_INTERNAL_VERIFY_RETURN(ZZ, RV)
200 #define UT_VERIFY_RETURN_VOID(ZZ) UT_INTERNAL_VERIFY_RETURN(ZZ,)
202 #define UT_VERIFY(expr) ((void)(expr))
203 #define UT_VERIFY_MSG(expr, ...) ((void)(expr))
204 #define UT_VERIFY_RETURN(ZZ, RV) if (!(ZZ)) { return RV; }
205 #define UT_VERIFY_RETURN_VOID(ZZ) if (!(ZZ)) { return; }
207 #if UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_PARANOID
208 #define UT_VERIFY_P(expr) UT_INTERNAL_VERIFY(expr, 0)
210 #define UT_VERIFY_P(expr) ((void)(expr))
227 template <
typename TO_T,
typename FROM_T>
231 UT_ASSERT_P(dynamic_cast<TO_T>(from) == from &&
"Invalid static cast");
232 return static_cast<TO_T
>(from);
240 #endif // UT_ASSERT_H_INCLUDED
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
UT_API void UTsubclassResponsibility(const char *classname, const char *member)
UT_API void UTdisableInteractiveAssertsOff()
const char * what() const noexcept
LeafData & operator=(const LeafData &)=delete
UT_API void UT_Assert(const char *file, int linenum, const char *function, const char *condition, const char *reason, int &ignoreflag)
UT_API void UT_AssertFormat(const char *file, int linenum, const char *function, const char *condition, int &ignoreflag, const char *reason_fmt...)
UT_API void UTdisableInteractiveAssertsOn()