Files
Bigfoot/Bigfoot/Sources/Utils/Include/Utils/Assert.hpp
Romain BOULLARD 6cd9801ef7
Some checks failed
Bigfoot / Build & Test Debug (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test RelWithDebInfo (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test Release (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test Release (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test Debug (Unity Build: OFF) (push) Has been cancelled
GiteaCI (#1)
Reviewed-on: #1
Co-authored-by: Romain BOULLARD <romain.boullard@protonmail.com>
Co-committed-by: Romain BOULLARD <romain.boullard@protonmail.com>
2026-01-28 14:29:12 +00:00

95 lines
7.2 KiB
C++

/*********************************************************************
* \file Assert.hpp
*
* \author Romain BOULLARD
* \date October 2025
*********************************************************************/
#ifndef BIGFOOT_UTILS_ASSERT_HPP
#define BIGFOOT_UTILS_ASSERT_HPP
#if defined BIGFOOT_NOT_OPTIMIZED
#include <cpptrace/cpptrace.hpp>
#include <source_location>
#include <string>
#if defined BIGFOOT_LINUX
#include <csignal>
#endif
#if defined BIGFOOT_WINDOWS
#define BREAK \
do \
{ \
__debugbreak(); \
} while (false)
#elif defined BIGFOOT_LINUX
#define BREAK \
do \
{ \
std::raise(SIGTRAP); \
} while (false)
#endif
#define ASSERT(HANDLER, p_assert, p_message, ...) \
do \
{ \
constexpr std::source_location location = std::source_location::current(); \
if (!(p_assert)) [[unlikely]] \
{ \
constexpr auto stacktrace = []() -> std::string \
{ \
const cpptrace::stacktrace stacktrace = cpptrace::generate_trace(); \
return stacktrace.to_string(); \
}; \
\
HANDLER::Handle(location, stacktrace(), p_message __VA_OPT__(, ) __VA_ARGS__); \
BREAK; \
} \
} while (false)
#define SOFT_ASSERT(HANDLER, p_assert, p_message, ...) \
do \
{ \
constexpr std::source_location location = std::source_location::current(); \
if (!(p_assert)) [[unlikely]] \
{ \
constexpr auto stacktrace = []() -> std::string \
{ \
const cpptrace::stacktrace stacktrace = cpptrace::generate_trace(); \
return stacktrace.to_string(); \
}; \
\
HANDLER::Handle(location, stacktrace(), p_message __VA_OPT__(, ) __VA_ARGS__); \
BREAK; \
} \
} while (false)
#define CRITICAL_ASSERT(HANDLER, p_assert, p_message, ...) \
do \
{ \
constexpr std::source_location location = std::source_location::current(); \
if (!(p_assert)) [[unlikely]] \
{ \
constexpr auto stacktrace = []() -> std::string \
{ \
const cpptrace::stacktrace stacktrace = cpptrace::generate_trace(); \
return stacktrace.to_string(); \
}; \
\
HANDLER::Handle(location, stacktrace(), p_message __VA_OPT__(, ) __VA_ARGS__); \
BREAK; \
std::abort(); \
} \
} while (false)
#else
#define ASSERT(HANDLER, p_assert, p_message, ...)
#define SOFT_ASSERT(HANDLER, p_assert, p_message, ...)
#define CRITICAL_ASSERT(HANDLER, p_assert, p_message, ...)
#endif
#endif