#pragma once #include #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