From cd93c42cf003721e19fa0668d86c94594e90a246 Mon Sep 17 00:00:00 2001 From: Stefan Pranger Date: Tue, 29 Jun 2021 12:06:51 +0200 Subject: [PATCH] fixed debug macros --- io/debug.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/io/debug.h b/io/debug.h index 9641c2f..358e8d7 100644 --- a/io/debug.h +++ b/io/debug.h @@ -3,19 +3,25 @@ #include #include -struct X { -#ifdef LOG_DEBUG - X() { if(false) std::cout.setstate(std::ios_base::failbit); } - ~X() { if(false) { std::cout.clear(); } else { std::cout << std::endl << std::flush; } } -#else - X() { std::cout.setstate(std::ios_base::failbit); } - ~X() { std::cout.clear(); } -#endif +struct print { + print() { if(false) std::cout.setstate(std::ios_base::failbit); } + ~print() { if(false) { std::cout.clear(); } else { std::cout << std::endl << std::flush; } } +}; + +struct noprint { + noprint() { if(true) std::cout.setstate(std::ios_base::failbit); } + ~noprint() { if(true) { std::cout.clear(); } else { std::cout << std::endl << std::flush; } } }; -#define DEBUG (X(), std::cout << "DEBUG[" << __FILENAME__ << ":" << __LINE__ << " in " << __func__ << "()]: ") -#define WARN (X(), std::cout << "WARN [" << __FILENAME__ << ":" << __LINE__ << " in " << __func__ << "()]: ") + +#ifdef LOG_DEBUG + #define DEBUG (print(), std::cout << "DEBUG[" << __FILENAME__ << ":" << __LINE__ << " in " << __func__ << "()]: ") + #define WARN (print(), std::cout << "WARN [" << __FILENAME__ << ":" << __LINE__ << " in " << __func__ << "()]: ") +#else + #define DEBUG (noprint(), std::cout << "") + #define WARN (noprint(), std::cout << "") +#endif #ifdef LOG_DEBUG #define STEP \