SA_Logger
Sapphire's Suite's C++ Logger.
Loading...
Searching...
No Matches
AssertMacro.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 Sapphire's Suite. All Rights Reserved.
2
3#pragma once
4
5#ifndef SAPPHIRE_LOGGER_ASSERT_MACRO_GUARD
6#define SAPPHIRE_LOGGER_ASSERT_MACRO_GUARD
7
9
20namespace SA
21{
22//{ Callback
23
25
26 #define __SA_ASSERT(_exc)\
27 if (SA::Debug::logger)\
28 SA::Debug::logger->Assert(std::move(_exc));\
29 else if (SA::Debug::logCB)\
30 SA::Debug::logCB(_exc);\
31 else\
32 std::cerr << "Try logging with invalid logger instance or callback! Initialize SA::Debug::logger or SA::Debug::logCB." << std::endl;
33
35
36//}
37
39
40 #define __SA_CREATE_EXCEPTION_TYPE(_chan, _dets, _type, ...) __SA_CREATE_EXCEPTION_##_type(\
41 (SA::Exception::BaseInfo{\
42 __SA_FILE_NAME,\
43 __LINE__,\
44 __SA_FUNC_NAME,\
45 __SA_CHAN_NAME(_chan),\
46 _dets,\
47 __SA_LOG_FRAME_NUM\
48 }),\
49 ##__VA_ARGS__\
50 )
51
52 #define __SA_CREATE_EXCEPTION(_type_params, _chan, _dets)\
53 __SA_EVAL_PASTE(__SA_CREATE_, EXCEPTION_TYPE(_chan, _dets, __SA_UNPARENT(_type_params)))
54
55
56 #define __SA_SELECT_ASSERT_MACRO(_1, _2, _3, _name, ...) _name
57
58 #define __SA_ASSERT3(_type_params, _chan, _dets){\
59 auto exc = __SA_CREATE_EXCEPTION(_type_params, _chan, SA::StringFormat(__SA_UNPARENT(_dets)));\
60 __SA_ASSERT(exc);\
61 if(exc.level == SA::LogLevel::AssertFailure) throw exc;\
62 }
63 #define __SA_ASSERT2(_type_params, _chan) __SA_ASSERT3(_type_params, _chan, L"")
64 #define __SA_ASSERT1(_type_params) __SA_ASSERT2(_type_params, Default)
65
66
67 #define __SA_THROW3(_type_params, _chan, _dets){\
68 auto exc = __SA_CREATE_EXCEPTION(_type_params, _chan, SA::StringFormat(__SA_UNPARENT(_dets)));\
69 __SA_ASSERT(exc);\
70 throw exc;\
71 }
72 #define __SA_THROW2(_type_params, _chan) __SA_THROW3(_type_params, _chan, L"")
73 #define __SA_THROW1(_type_params) __SA_THROW2(_type_params, Default)
74
76
77#if defined(DOXYGEN)
78
91 #define SA_THROW((_type, _params...), _chan, _dets)
92
105 #define SA_ASSERT((_type, _params...), _chan, _dets)
106
107#elif SA_DEBUG || SA_LOG_RELEASE_OPT
108
109 #define SA_THROW(...){ __SA_SELECT_ASSERT_MACRO(__VA_ARGS__, __SA_THROW3, __SA_THROW2, __SA_THROW1)(__VA_ARGS__) }
110
111 #define SA_ASSERT(...) { __SA_SELECT_ASSERT_MACRO(__VA_ARGS__, __SA_ASSERT3, __SA_ASSERT2, __SA_ASSERT1)(__VA_ARGS__) }
112
113#else
114
115 #define SA_THROW(...) {}
116
117 #define SA_ASSERT(...) {}
118
119#endif
120
121}
122
123
126#endif // GUARD
Log Helper Macros implementation.