mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-10 06:14:07 +08:00
feat: add cubed_assert lib
This commit is contained in:
35
include/Cubed/tools/cubed_assert.hpp
Normal file
35
include/Cubed/tools/cubed_assert.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include <Cubed/tools/log.hpp>
|
||||
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
|
||||
Reference in New Issue
Block a user