63 lines
1.6 KiB
C
63 lines
1.6 KiB
C
#pragma once
|
|
#include "spdlog/spdlog.h"
|
|
#include <cassert>
|
|
|
|
// 定义 check 宏
|
|
#if BUILD_DEBUG
|
|
#define check(expr) \
|
|
do { \
|
|
if (!(expr)) { \
|
|
spdlog::critical("Check failed: {} in file {} at line {}", #expr, __FILE__, __LINE__); \
|
|
assert(expr); \
|
|
} \
|
|
} while (0)
|
|
|
|
// 定义 checkf 宏
|
|
#define checkf(expr, msg, ...) \
|
|
do { \
|
|
if (!(expr)) { \
|
|
spdlog::critical("Check failed: {} in file {} at line {}. " msg, #expr, __FILE__, __LINE__, __VA_ARGS__); \
|
|
assert(expr); \
|
|
} \
|
|
} while (0)
|
|
#else
|
|
#define check(expr)
|
|
#define checkf(expr, msg, ...)
|
|
#endif
|
|
|
|
// 定义 ensure 宏
|
|
#if BUILD_DEBUG
|
|
#define ensure(expr) \
|
|
do { \
|
|
if (!(expr)) { \
|
|
spdlog::error("Ensure failed: {} in file {} at line {}", #expr, __FILE__, __LINE__); \
|
|
assert(expr); \
|
|
} \
|
|
} while (0)
|
|
#else
|
|
#define ensure(expr) \
|
|
do { \
|
|
if (!(expr)) { \
|
|
spdlog::error("Ensure condition failed: {} in file {} at line {}", #expr, __FILE__, __LINE__); \
|
|
} \
|
|
} while (0)
|
|
#endif
|
|
|
|
// 定义 ensuref 宏
|
|
#if BUILD_DEBUG
|
|
#define ensuref(expr, msg, ...) \
|
|
do { \
|
|
if (!(expr)) { \
|
|
spdlog::error("Ensure failed: {} in file {} at line {}. " msg, #expr, __FILE__, __LINE__, __VA_ARGS__); \
|
|
assert(expr); \
|
|
} \
|
|
} while (0)
|
|
#else
|
|
#define ensuref(expr, msg, ...) \
|
|
do { \
|
|
if (!(expr)) { \
|
|
spdlog::error("Ensure condition failed: {} in file {} at line {}. " msg, #expr, __FILE__, __LINE__, __VA_ARGS__); \
|
|
} \
|
|
} while (0)
|
|
#endif
|