Files
CPP_Core/psc_global_include/assert.h
T
2026-06-16 10:56:40 +08:00

86 lines
2.8 KiB
C++

#pragma once
#include <iostream>
#ifdef NDEBUG
#define PSC_ASSERT(condition, message) ((void)0) // 在发布模式下什么都不做
#define assert(expr) ((void)0)
#define PSC_ASSERT_EQ(a, b) ((void)0)
#define PSC_ASSERT_NE(a, b) ((void)0)
#define PSC_ASSERT_LT(a, b) ((void)0)
#define PSC_ASSERT_LE(a, b) ((void)0)
#define PSC_ASSERT_GT(a, b) ((void)0)
#define PSC_ASSERT_GE(a, b) ((void)0)
#else
#define PSC_ASSERT(condition, message) \
do { \
if (!(condition)) { \
std::cerr << "Assertion failed: " << message \
<< "\nFile: " << __FILE__ \
<< "\nLine: " << __LINE__ \
<< std::endl; \
abort(); \
} \
} while (0)
#define PSC_ASSERT_EQ(a, b) \
do { \
if (!((a) == (b))) { \
printf("Assertion failed: %s == %s, (%lld vs %lld), file %s, line %d\n", \
#a, #b, (long long)(a), (long long)(b), __FILE__, __LINE__); \
abort(); \
} \
} while (0)
#define PSC_ASSERT_NE(a, b) \
do { \
if (!((a) != (b))) { \
printf("Assertion failed: %s != %s, both = %lld, file %s, line %d\n", \
#a, #b, (long long)(a), __FILE__, __LINE__); \
abort(); \
} \
} while (0)
#define PSC_ASSERT_LT(a, b) \
do { \
if (!((a) < (b))) { \
printf("Assertion failed: %s < %s, (%lld vs %lld), file %s, line %d\n", \
#a, #b, (long long)(a), (long long)(b), __FILE__, __LINE__); \
abort(); \
} \
} while (0)
#define PSC_ASSERT_LE(a, b) \
do { \
if (!((a) <= (b))) { \
printf("Assertion failed: %s <= %s, (%lld vs %lld), file %s, line %d\n", \
#a, #b, (long long)(a), (long long)(b), __FILE__, __LINE__); \
abort(); \
} \
} while (0)
#define PSC_ASSERT_GT(a, b) \
do { \
if (!((a) > (b))) { \
printf("Assertion failed: %s > %s, (%lld vs %lld), file %s, line %d\n", \
#a, #b, (long long)(a), (long long)(b), __FILE__, __LINE__); \
abort(); \
} \
} while (0)
#define PSC_ASSERT_GE(a, b) \
do { \
if (!((a) >= (b))) { \
printf("Assertion failed: %s >= %s, (%lld vs %lld), file %s, line %d\n", \
#a, #b, (long long)(a), (long long)(b), __FILE__, __LINE__); \
abort(); \
} \
} while (0)
#endif