LkEngine 0.1.2
 
Loading...
Searching...
No Matches
Assert.h
1/******************************************************************
2 * Assert
3 *
4 *******************************************************************/
5#pragma once
6
7#include "PlatformDetection.h"
8
12#if defined(LK_ENGINE_MSVC) || defined(LK_ENGINE_GCC) || defined(LK_ENGINE_CLANG)
13# define LK_VARIADIC_ARGS 0
14# define LK_ENABLE_ASSERTS 1
15# define LK_ENABLE_VERIFY 1
16#endif
17
21#if LK_ENABLE_ASSERTS
22# if LK_VARIADIC_ARGS
23# define LK_CORE_ASSERT_MESSAGE_INTERNAL(...) ::LkEngine::LLog::PrintAssertMessage(::LkEngine::ELoggerType::Core, "Assertion Failed", ##__VA_ARGS__)
24# define LK_ASSERT_MESSAGE_INTERNAL(...) ::LkEngine::LLog::PrintAssertMessage(::LkEngine::ELoggerType::Client, "Assertion Failed", ##__VA_ARGS__)
25# else
26# define LK_CORE_ASSERT_MESSAGE_INTERNAL(...) ::LkEngine::LLog::PrintAssertMessage(::LkEngine::ELoggerType::Core, "Assertion Failed" __VA_OPT__(, ) __VA_ARGS__)
27# define LK_ASSERT_MESSAGE_INTERNAL(...) ::LkEngine::LLog::PrintAssertMessage(::LkEngine::ELoggerType::Client, "Assertion Failed" __VA_OPT__(, ) __VA_ARGS__)
28# endif
29# define LK_CORE_ASSERT(Condition, ...) \
30 { \
31 if (!(Condition)) \
32 { \
33 if constexpr (sizeof(#__VA_ARGS__) > 1) \
34 { \
35 LK_CORE_ASSERT_MESSAGE_INTERNAL(__VA_ARGS__); \
36 } \
37 else \
38 { \
39 LK_CORE_ASSERT_MESSAGE_INTERNAL("{}", LK_FUNCSIG); \
40 } \
41 LK_DEBUG_BREAK; \
42 } \
43 }
44# define LK_ASSERT(Condition, ...) \
45 { \
46 if (!(Condition)) \
47 { \
48 if constexpr (sizeof(#__VA_ARGS__) > 1) \
49 { \
50 LK_ASSERT_MESSAGE_INTERNAL(__VA_ARGS__); \
51 } \
52 else \
53 { \
54 LK_ASSERT_MESSAGE_INTERNAL("{}", LK_FUNCSIG); \
55 } \
56 LK_DEBUG_BREAK; \
57 } \
58 }
59#else
60# define LK_CORE_ASSERT(Condition, ...) static_cast<void>(0)
61# define LK_ASSERT(Condition, ...) static_cast<void>(0)
62#endif
63
67#if LK_ENABLE_VERIFY
68# if LK_VARIADIC_ARGS
69# define LK_CORE_VERIFY_MESSAGE_INTERNAL(...) ::LkEngine::LLog::PrintAssertMessage(::LkEngine::ELoggerType::Core, "Verify Failed", ##__VA_ARGS__)
70# define LK_VERIFY_MESSAGE_INTERNAL(...) ::LkEngine::LLog::PrintAssertMessage(::LkEngine::ELoggerType::Client, "Verify Failed", ##__VA_ARGS__)
71# else
72# define LK_CORE_VERIFY_MESSAGE_INTERNAL(...) ::LkEngine::LLog::PrintAssertMessage(::LkEngine::ELoggerType::Core, "Verify Failed" __VA_OPT__(, ) __VA_ARGS__)
73# define LK_VERIFY_MESSAGE_INTERNAL(...) ::LkEngine::LLog::PrintAssertMessage(::LkEngine::ELoggerType::Client, "Verify Failed" __VA_OPT__(, ) __VA_ARGS__)
74# endif
75# define LK_CORE_VERIFY(Condition, ...) \
76 { \
77 if (!(Condition)) \
78 { \
79 if constexpr (sizeof(#__VA_ARGS__) > 1) \
80 { \
81 LK_CORE_VERIFY_MESSAGE_INTERNAL(__VA_ARGS__); \
82 } \
83 else \
84 { \
85 LK_CORE_VERIFY_MESSAGE_INTERNAL("{}", LK_FUNCSIG); \
86 } \
87 LK_DEBUG_BREAK; \
88 } \
89 }
90# define LK_VERIFY(Condition, ...) \
91 { \
92 if (!(Condition)) \
93 { \
94 if constexpr (sizeof(#__VA_ARGS__) > 1) \
95 { \
96 LK_VERIFY_MESSAGE_INTERNAL(__VA_ARGS__); \
97 } \
98 else \
99 { \
100 LK_VERIFY_MESSAGE_INTERNAL("{}", LK_FUNCSIG); \
101 } \
102 LK_DEBUG_BREAK; \
103 } \
104 }
105#else
106# define LK_CORE_VERIFY(Condition, ...)
107# define LK_VERIFY(Condition, ...)
108#endif
Platform detection.