From d51c68ddb4ac5b7c940c28fa74eee2a1ec27d938 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Fri, 6 Mar 2026 22:07:42 +0800 Subject: [PATCH] feat: add cubed_assert lib --- include/Cubed/tools/cubed_assert.hpp | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 include/Cubed/tools/cubed_assert.hpp diff --git a/include/Cubed/tools/cubed_assert.hpp b/include/Cubed/tools/cubed_assert.hpp new file mode 100644 index 0000000..d12f8b1 --- /dev/null +++ b/include/Cubed/tools/cubed_assert.hpp @@ -0,0 +1,35 @@ +#pragma once +#include +namespace Assert { + inline void msg(const char* condition, const char* file, + int line, const char* func, + const std::string& message + ) { + + LOG::error("Assertion failed: {} at {}: {} in function {}", + condition, file, line, func); + if (!message.empty()) { + LOG::error("Message: {}", message); + } + std::abort(); + + } +} + +#ifdef NDEBUG +#define CUBED_ASSERT(cond) ((void)0) +#define CUBED_ASSERT_MSG(cond) ((void)0) +#else +#define CUBED_ASSERT(cond) \ + do { \ + if (!(cond)) { \ + ::Assert::msg(#cond, __FILE__, __LINE__, __func__); \ + } \ + } while (0) +#define CUBED_ASSERT_MSG(cond, message) \ + do { \ + if (!(cond)) { \ + ::Assert::msg(#cond, __FILE__, __LINE__, __func__, message); \ + } \ + } while (0) +#endif \ No newline at end of file