ezEngine  Milestone 7
Assert.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <Foundation/Basics.h>
6 
29 
30 
31 
33 typedef bool (*ezAssertHandler)(const char* szSourceFile, ezUInt32 uiLine, const char* szFunction, const char* szExpression, const char* szAssertMsg);
34 
36 EZ_FOUNDATION_DLL ezAssertHandler ezGetAssertHandler();
37 
39 EZ_FOUNDATION_DLL void ezSetAssertHandler(ezAssertHandler handler);
40 
41 
43 EZ_FOUNDATION_DLL bool ezFailedCheck(const char* szSourceFile, ezUInt32 uiLine, const char* szFunction, const char* szExpression, const char* szErrorMsg, ...);
44 
46 #define EZ_REPORT_FAILURE(szErrorMsg, ...) \
47  { if (ezFailedCheck(EZ_SOURCE_FILE, EZ_SOURCE_LINE, EZ_SOURCE_FUNCTION, "", szErrorMsg, ##__VA_ARGS__)) EZ_DEBUG_BREAK; }
48 
50 #define EZ_ASSERT_ALWAYS(bCondition, szErrorMsg, ...) \
51  do { \
52  EZ_ANALYSIS_ASSUME(bCondition); \
53  if ((bCondition) == false) \
54  { if (ezFailedCheck(EZ_SOURCE_FILE, EZ_SOURCE_LINE, EZ_SOURCE_FUNCTION, #bCondition, szErrorMsg, ##__VA_ARGS__)) EZ_DEBUG_BREAK; } \
55  } while (false)
56 
57 
59 #define EZ_ASSERT_NOT_IMPLEMENTED EZ_REPORT_FAILURE("Not implemented")
60 
61 // Occurrences of EZ_ASSERT_DEBUG are compiled out in non-debug builds
62 #if EZ_ENABLED(EZ_COMPILE_FOR_DEBUG)
63 
64 
65 
66 
67 
68  #define EZ_ASSERT_DEBUG EZ_ASSERT_ALWAYS
69 #else
70 
71 
72 
73 
74 
75  #define EZ_ASSERT_DEBUG(bCondition, szErrorMsg, ...) EZ_ANALYSIS_ASSUME(bCondition)
76 #endif
77 
78 
79 // Occurrences of EZ_ASSERT_DEV are compiled out in non-development builds
80 #if EZ_ENABLED(EZ_COMPILE_FOR_DEVELOPMENT) || EZ_ENABLED(EZ_COMPILE_FOR_DEBUG)
81 
87  #define EZ_ASSERT_DEV EZ_ASSERT_ALWAYS
88 
94  #define EZ_VERIFY EZ_ASSERT_ALWAYS
95 
96 #else
97 
103  #define EZ_ASSERT_DEV(bCondition, szErrorMsg, ...) EZ_ANALYSIS_ASSUME(bCondition)
104 
110  #define EZ_VERIFY(bCondition, szErrorMsg, ...) \
111  if ((bCondition) == false) \
112  { /* The condition is evaluated, even though nothing is done with it. */ }
113 
114 #endif
115 
116 #if EZ_DISABLE_RELEASE_ASSERTS
117 
123  #define EZ_ASSERT_RELEASE(bCondition, szErrorMsg, ...) EZ_ANALYSIS_ASSUME(bCondition)
124 
125 #else
126 
132  #define EZ_ASSERT_RELEASE EZ_ASSERT_ALWAYS
133 
134 #endif
135