#ifndef CUTES_DEBUG_H #define CUTES_DEBUG_H #include #include #ifndef NDEBUG #include #endif extern int g_debug_error_abort; extern int g_debug_log_lvl; #ifdef NDEBUG #define LOG_INFO(...) #define LOG_ERROR(...) #define LOG_WARNING(...) #define RETURN_ERROR(...) #define RETURN_WARNING(...) #define ASSERT_RETURN(...) #define CHECK(...) #define ASSERT_RETURN_WARN(...) #define UNREACHABLE(...) #else #define LOG_INFO(...) do {\ if(g_debug_log_lvl < 3) break;\ printf("[%s:%d] INFO | ", __FILE__, __LINE__);\ printf(__VA_ARGS__);\ printf("\n");\ } while(0) #define LOG_ERROR(...) do {\ if(g_debug_log_lvl >= 1) {\ printf("[%s:%d] ERROR | ", __FILE__, __LINE__);\ printf(__VA_ARGS__);\ printf("\n");\ fflush(stdout);\ }\ if(g_debug_error_abort != 0) abort();\ } while(0) #define LOG_WARNING(...) do {\ if(g_debug_log_lvl < 2) break;\ printf("[%s:%d] WARNING | ", __FILE__, __LINE__);\ printf(__VA_ARGS__);\ printf("\n");\ } while(0) #define RETURN_ERROR(__VALUE, ...) do {\ LOG_ERROR(__VA_ARGS__);\ return __VALUE;\ } while(0) #define RETURN_WARNING(__VALUE, ...) do {\ LOG_WARNING(__VA_ARGS__);\ return __VALUE;\ } while(0) #define ASSERT_RETURN(__ASSERT, __RETURN, ...) do {\ if(!(__ASSERT)) {\ LOG_ERROR(__VA_ARGS__);\ return __RETURN;\ }\ } while(0) #define CHECK(__ASSERT, ...) do {\ if(!(__ASSERT)) {\ LOG_ERROR(__VA_ARGS__);\ }\ } while(0) #define ASSERT_RETURN_WARN(__ASSERT, __RETURN, ...) do {\ if(!(__ASSERT)) {\ LOG_WARNING(__VA_ARGS__);\ return __RETURN;\ }\ } while(0) #define UNREACHABLE(...) do {\ LOG_ERROR(__VA_ARGS__);\ abort();\ } while(0) #endif #endif // !CUTES_DEBUG_H