aboutsummaryrefslogtreecommitdiff
path: root/zencore/include
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-04-28 16:42:01 +0200
committerGitHub <[email protected]>2023-04-28 16:42:01 +0200
commit6a44e6c95031179d29fca433851219eef402d71e (patch)
tree870acc699f3d13ea177dbf6eae79cbd0fc78a905 /zencore/include
parent0.2.8-pre0 (diff)
downloadzen-6a44e6c95031179d29fca433851219eef402d71e.tar.xz
zen-6a44e6c95031179d29fca433851219eef402d71e.zip
add customization of assert implementation (#263)
* add customization of assert implementation
Diffstat (limited to 'zencore/include')
-rw-r--r--zencore/include/zencore/zencore.h63
1 files changed, 36 insertions, 27 deletions
diff --git a/zencore/include/zencore/zencore.h b/zencore/include/zencore/zencore.h
index db089d9ea..5bcd77239 100644
--- a/zencore/include/zencore/zencore.h
+++ b/zencore/include/zencore/zencore.h
@@ -249,38 +249,47 @@ namespace zen
AssertException(const char* Msg) : std::logic_error(Msg) {}
};
+ struct AssertImpl
+ {
+ static void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION ExecAssert
+ [[noreturn]] (const char* Filename, int LineNumber, const char* FunctionName, const char* Msg)
+ {
+ CurrentAssertImpl->OnAssert(Filename, LineNumber, FunctionName, Msg);
+ throw AssertException{Msg};
+ }
+
+ protected:
+ virtual void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION OnAssert(const char* Filename,
+ int LineNumber,
+ const char* FunctionName,
+ const char* Msg)
+ {
+ (void(Filename));
+ (void(LineNumber));
+ (void(FunctionName));
+ (void(Msg));
+ }
+ static AssertImpl DefaultAssertImpl;
+ static AssertImpl* CurrentAssertImpl;
+ };
+
} // namespace zen
-template<typename RetType = void, class InnerType, typename... ArgTypes>
-RetType ZEN_FORCENOINLINE ZEN_DEBUG_SECTION
-DispatchAssert(InnerType&& Inner, ArgTypes const&... Args)
-{
- return Inner(Args...);
-}
-
-#define ZEN_ASSERT(x, ...) \
- do \
- { \
- if (x) [[unlikely]] \
- break; \
- struct Impl \
- { \
- static void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION ExecThrow [[noreturn]] () { throw ::zen::AssertException{#x}; } \
- }; \
- Impl::ExecThrow(); \
+#define ZEN_ASSERT(x, ...) \
+ do \
+ { \
+ if (x) [[unlikely]] \
+ break; \
+ zen::AssertImpl::ExecAssert(__FILE__, __LINE__, __FUNCTION__, #x); \
} while (false)
#ifndef NDEBUG
-# define ZEN_ASSERT_SLOW(x, ...) \
- do \
- { \
- if (x) [[unlikely]] \
- break; \
- struct Impl \
- { \
- static void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION ExecThrow [[noreturn]] () { throw ::zen::AssertException{#x}; } \
- }; \
- Impl::ExecThrow(); \
+# define ZEN_ASSERT_SLOW(x, ...) \
+ do \
+ { \
+ if (x) [[unlikely]] \
+ break; \
+ zen::AssertImpl::ExecAssert(__FILE__, __LINE__, __FUNCTION__, #x); \
} while (false)
#else
# define ZEN_ASSERT_SLOW(x, ...)