2
3
4
5
6
7
8
11#ifndef _MSTD_ASSERT_BASE_HPP_
12 #define _MSTD_ASSERT_BASE_HPP_
14 #include <mstd/config.hpp>
17_MSTD_WARNING(
"this is only available for c++17 and greater!");
21 #include <source_location>
24 #include <fmt/format.h>
26 #include <string_view>
28 #include <mstd/function_view.hpp>
30 #pragma region DEBUGBREAK
33 #define WIN32_LEAN_AND_MEAN
37 #define _MSTD_DEBUGBREAK() __debugbreak()
38 #elif defined(__linux__) || defined(__APPLE__)
40 #define _MSTD_DEBUGBREAK() __builtin_trap()
43 #define _MSTD_DEBUGBREAK() std::abort()
46 #define _MSTD_DEBUGBREAK() ((void)0
)
50 #pragma region ASSERT_DEFINES
52 #define _MSTD_SOURCE_LOCATION_ARG const std::source_location& location
53 #define _MSTD_GET_SOURCE_FILE_NAME location.file_name()
54 #define _MSTD_GET_SOURCE_FUNC_NAME location.function_name()
55 #define _MSTD_GET_SOURCE_LINE location.line()
56 #define _MSTD_GET_SOURCE_COLUMN location.column()
57 #define _MSTD_PASS_SOURCE_LOCATION location
58 #define _MSTD_GET_CURRENT_SOURCE_LOCATION ::std::source_location::current()
60 #define _MSTD_SOURCE_LOCATION_ARG const std::string_view &file_name, size_t line, const std::string_view &func_name
61 #define _MSTD_GET_SOURCE_FILE_NAME file_name.data()
62 #define _MSTD_GET_SOURCE_FUNC_NAME func_name.data()
63 #define _MSTD_GET_SOURCE_LINE line
64 #define _MSTD_GET_SOURCE_COLUMN 0
65 #define _MSTD_PASS_SOURCE_LOCATION file_name, line, func_name
66 #define _MSTD_GET_CURRENT_SOURCE_LOCATION __FILE__, __LINE__, __FUNCTION__
70 #pragma region ASSERT_BASE
71 #define MSTD_STOP_ASSERT_BASE(expression, log_error_func, ...)
74 if (::mstd::stop_assert_handler(#expression, log_error_func,
81 #define MSTD_LOG_ASSERT_BASE(expression, log_error_func, ...)
85 #define MSTD_EMPTY_ASSERT_BASE(expression, log_error_func, ...) ((void)0
)
88 #pragma region FUNCTIONS_DEFINES
91 #pragma region FORMAT_LOG
99 if (!message.empty()) { fullMessage += fmt::format(
"\nmessage: {}", message); }
105 #pragma region REPORT_TO_SYSTEM
118 #pragma region ASSERT_HANDLER_NO_MSG
131 return report_to_system(_MSTD_PASS_SOURCE_LOCATION, msg);
139 #pragma region ASSERT_HANDLER_MSG
141 template<
class... Args>
144 fmt::format_string<Args...> fmtFormat, Args&&... args)
noexcept {
150 template<
class... Args>
153 fmt::format_string<Args...> fmtFormat, Args&&... args)
noexcept {
#define _MSTD_GET_SOURCE_FILE_NAME
Definition assert_base.hpp:53
#define _MSTD_GET_SOURCE_LINE
Definition assert_base.hpp:55
#define _MSTD_GET_SOURCE_FUNC_NAME
Definition assert_base.hpp:54
#define _MSTD_GET_SOURCE_COLUMN
Definition assert_base.hpp:56
#define _MSTD_GET_CURRENT_SOURCE_LOCATION
Definition assert_base.hpp:58
#define _MSTD_PASS_SOURCE_LOCATION
Definition assert_base.hpp:57
#define _MSTD_DEBUGBREAK()
Definition assert_base.hpp:46
#define _MSTD_SOURCE_LOCATION_ARG
Definition assert_base.hpp:52
#define _MSTD_HAS_CXX17
Definition config.hpp:45
#define _MSTD_HAS_CXX20
Definition config.hpp:52
Definition arithmetic_types.hpp:23
void log_assert_handler(const std::string_view expression, const mstd::function_view< void(const std::string_view)> &errorLogger, _MSTD_SOURCE_LOCATION_ARG, fmt::format_string< Args... > fmtFormat, Args &&... args) noexcept
Definition assert_base.hpp:142
bool stop_assert_handler(const std::string_view expression, const mstd::function_view< void(const std::string_view)> &errorLogger, _MSTD_SOURCE_LOCATION_ARG, fmt::format_string< Args... > fmtFormat, Args &&... args) noexcept
Definition assert_base.hpp:151
std::string format_log(const std::string_view expression, _MSTD_SOURCE_LOCATION_ARG, const std::string_view message="") noexcept
Definition assert_base.hpp:93
void log_assert_handler(const std::string_view expression, const mstd::function_view< void(const std::string_view)> &errorLogger, _MSTD_SOURCE_LOCATION_ARG) noexcept
Definition assert_base.hpp:120
bool stop_assert_handler(const std::string_view expression, const mstd::function_view< void(const std::string_view)> &errorLogger, _MSTD_SOURCE_LOCATION_ARG) noexcept
Definition assert_base.hpp:126