19 #include <shared_mutex>
24 #elif QX_MACOS && (QX_WITH_DEBUG_INFO)
25 #include <sys/sysctl.h>
26 #include <sys/types.h>
41 enum class assert_type
60 using exit_func = std::function<void(
const category&
category, assert_type eAssertType)>;
61 using verbosity_func = std::function<verbosity(assert_type eAssertType)>;
62 using assertion_func = std::function<void(
63 string_view svCondition,
65 assert_type eAssertType,
66 string_view svUserMessage,
67 string_view svFunction,
79 verbosity_func getVerbosity = [](assert_type eAssertType)
83 case assert_type::assert:
84 case assert_type::verify:
85 return verbosity::critical;
87 case assert_type::expect:
88 case assert_type::ensure:
90 return verbosity::error;
94 assertion_func onAssertion;
96 bool bLogAssertion =
true;
99 using interceptor_func = std::function<bool(
100 string_view svCondition,
102 assert_type eAssertType,
103 string_view svUserMessage,
104 string_view svFunction,
111 interceptor_func callback;
127 string_view svCondition,
129 assert_type eAssertType,
131 string_view svFunction,
162 void add_interceptor(
const void* pOwner, interceptor_func interceptor);
171 mutable std::shared_mutex m_Mutex;
173 std::vector<interceptor_entry> m_Interceptors;
178 #if QX_MSVC_COMPATIBLE
179 #define QX_DETAILS_DEBUG_BREAK() __debugbreak()
180 #elif QX_CLANG || QX_APPLE_CLANG
181 #define QX_DETAILS_DEBUG_BREAK() __builtin_debugtrap()
184 #define QX_DETAILS_DEBUG_BREAK() static_cast<void>(raise(SIGTRAP))
186 #define QX_DETAILS_DEBUG_BREAK() QX_EMPTY_MACRO
189 #ifndef QX_DEBUG_BREAK
193 #define QX_DEBUG_BREAK() QX_DETAILS_DEBUG_BREAK()
196 #define QX_DETAILS_COMMON_ASSERT(condition, category, assert_type, after_debug_break, result_t, ...) \
197 static_cast<result_t>( \
198 qx::predicates::is_valid(condition) \
199 || (qx::asserts_manager::get_instance().do_assert( \
200 qx::details::get_assert_condition_string<QXT(#condition)>(condition), \
204 QX_DETAILS_MACRO_USER_MESSAGE(static_cast<qx::string_pool<>*>(nullptr) __VA_OPT__(, ) __VA_ARGS__) \
206 qx::convert_string_literal<qx::char_type, __FUNCTION__>(), \
211 after_debug_break(category, assert_type), \
214 #ifndef QX_DETAILS_ASSERT_AFTER_DEBUG_BREAK_FATAL
215 #define QX_DETAILS_ASSERT_AFTER_DEBUG_BREAK_FATAL(category, assert_type) \
216 qx::asserts_manager::get_instance().exit(category, assert_type)
219 #ifndef QX_DETAILS_ASSERT_AFTER_DEBUG_BREAK_NON_FATAL
220 #define QX_DETAILS_ASSERT_AFTER_DEBUG_BREAK_NON_FATAL(category, assert_type) false
223 #ifndef QX_WITH_DEBUG_ASSERTS
224 #define QX_WITH_DEBUG_ASSERTS QX_WITH_DEBUG_INFO
227 template<
class char_t>
230 template<
class format_context_t>
231 constexpr
auto format(qx::assert_type eType, format_context_t& ctx)
const -> decltype(ctx.out())
233 qx::basic_string_view<char_t> svName;
236 case qx::assert_type::assert:
240 case qx::assert_type::verify:
244 case qx::assert_type::expect:
248 case qx::assert_type::ensure:
253 return QX_FMT_NS::format_to(ctx.out(),
QX_STR_PREFIX(char_t,
"{}"), svName);
bool is_debugger_present() noexcept
Check whether the current process or thread is being traced by a debugger.
Determines assertions behavior.
void set_config(config config)
Set config.
void exit(const category &category, assert_type eAssertType)
Called in fatal assertions to exit the application.
void add_interceptor(const void *pOwner, interceptor_func interceptor)
Register an assertion interceptor.
void remove_interceptor(const void *pOwner)
Remove an interceptor, waiting for callbacks already in progress.
bool do_assert(string_view svCondition, const category &category, assert_type eAssertType, string sUserMessage, string_view svFunction, string_view svFile, i32 nLine)
An entry point for all assertions.
config get_config() const
Get config.
A category is a class that identifies a particular piece of code. This code can be located in differe...
Inherit the necessary singleton class from this.
#define QX_STR_PREFIX(value_t, str)
Chose witch of prefixes add to string : L or none.
std::int32_t i32
− 9 223 372 036 854 775 808 .. 9 223 372 036 854 775 807