From 3140590d0ad91acee5981ad734c00c361f78cfd0 Mon Sep 17 00:00:00 2001 From: xpxz <97490782+heheda123123@users.noreply.github.com> Date: Sat, 31 May 2025 07:35:03 +0800 Subject: [PATCH 1/3] add group function --- debug.hpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/debug.hpp b/debug.hpp index 56a86c1..76ca35c 100644 --- a/debug.hpp +++ b/debug.hpp @@ -190,8 +190,19 @@ #ifndef DEBUG_NAMESPACE_END # define DEBUG_NAMESPACE_END #endif +#ifndef DEBUG_GROUP +# define DEBUG_GROUP 0 +#endif #ifndef DEBUG_OUTPUT -# define DEBUG_OUTPUT std::cerr << +# define DEBUG_OUTPUT(x) do { \ + if (DEBUG_GROUP == 0) { \ + std::cerr << x; \ + } else { \ + if (DEBUG_GROUP == group) { \ + std::cerr << x; \ + } \ + } \ +} while (0) #endif #ifndef DEBUG_ENABLE_FILES_MATCH # define DEBUG_ENABLE_FILES_MATCH 0 @@ -1310,6 +1321,7 @@ struct DEBUG_NODISCARD debug { panic = 2, supress = 3, } state; + int group; DEBUG_SOURCE_LOCATION loc; # if DEBUG_SHOW_TIMESTAMP == 2 @@ -1524,7 +1536,7 @@ struct DEBUG_NODISCARD debug { } # endif public: - explicit debug(bool enable = true, + explicit debug(int group = 0, bool enable = true, DEBUG_SOURCE_LOCATION const &loc = DEBUG_SOURCE_LOCATION::current()) noexcept : state(enable @@ -1533,7 +1545,8 @@ struct DEBUG_NODISCARD debug { # endif ? silent : supress), - loc(loc) { + loc(loc), + group(group) { } debug &setloc(DEBUG_SOURCE_LOCATION const &newloc = @@ -1971,7 +1984,7 @@ DEBUG_NAMESPACE_END DEBUG_NAMESPACE_BEGIN struct debug { - debug(bool = true, char const * = nullptr) noexcept {} + debug(int = 0, bool = true, char const * = nullptr) noexcept {} debug(debug &&) = delete; debug(debug const &) = delete; @@ -2088,6 +2101,6 @@ DEBUG_NAMESPACE_END # undef debug #elif DEBUG_LEVEL # ifdef DEBUG_SOURCE_LOCATION_FAKER -# define debug() debug(true, DEBUG_SOURCE_LOCATION_FAKER) +# define debug(...) debug(int(__VA_ARGS__), true, DEBUG_SOURCE_LOCATION_FAKER) # endif #endif From a97453f5502c8336f0c63847271cc26e933425c2 Mon Sep 17 00:00:00 2001 From: xpxz <97490782+heheda123123@users.noreply.github.com> Date: Sat, 31 May 2025 07:55:03 +0800 Subject: [PATCH 2/3] keep DEBUG_OUTPUT --- debug.hpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/debug.hpp b/debug.hpp index 76ca35c..288a3ff 100644 --- a/debug.hpp +++ b/debug.hpp @@ -190,17 +190,18 @@ #ifndef DEBUG_NAMESPACE_END # define DEBUG_NAMESPACE_END #endif +#ifndef DEBUG_OUTPUT +# define DEBUG_OUTPUT std::cerr << +#endif #ifndef DEBUG_GROUP # define DEBUG_GROUP 0 #endif -#ifndef DEBUG_OUTPUT -# define DEBUG_OUTPUT(x) do { \ +#ifndef DEBUG_OUTPUT_GROUP +# define DEBUG_OUTPUT_GROUP(x) do { \ if (DEBUG_GROUP == 0) { \ - std::cerr << x; \ - } else { \ - if (DEBUG_GROUP == group) { \ - std::cerr << x; \ - } \ + DEBUG_OUTPUT(x); \ + } else if (group == DEBUG_GROUP) { \ + DEBUG_OUTPUT(x); \ } \ } while (0) #endif @@ -1616,7 +1617,7 @@ struct DEBUG_NODISCARD debug { throw std::runtime_error(oss.str()); # elif DEBUG_PANIC_METHOD == 1 oss << '\n'; - DEBUG_OUTPUT(oss.str()); + DEBUG_OUTPUT_GROUP(oss.str()); # if defined(DEBUG_PANIC_CUSTOM_TRAP) DEBUG_PANIC_CUSTOM_TRAP; return; @@ -1635,18 +1636,18 @@ struct DEBUG_NODISCARD debug { # endif # elif DEBUG_PANIC_METHOD == 2 oss << '\n'; - DEBUG_OUTPUT(oss.str()); + DEBUG_OUTPUT_GROUP(oss.str()); std::terminate(); # else oss << '\n'; - DEBUG_OUTPUT(oss.str()); + DEBUG_OUTPUT_GROUP(oss.str()); return; # endif } } if (state == print) { oss << '\n'; - DEBUG_OUTPUT(oss.str()); + DEBUG_OUTPUT_GROUP(oss.str()); } # if DEBUG_STEPPING == 1 static std::mutex mutex; From f8ead01a0f2f0c1cae2b1df3912c776f7496e256 Mon Sep 17 00:00:00 2001 From: xpxz <97490782+heheda123123@users.noreply.github.com> Date: Sat, 31 May 2025 07:57:26 +0800 Subject: [PATCH 3/3] format --- debug.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug.hpp b/debug.hpp index 288a3ff..6cadc4e 100644 --- a/debug.hpp +++ b/debug.hpp @@ -201,7 +201,7 @@ if (DEBUG_GROUP == 0) { \ DEBUG_OUTPUT(x); \ } else if (group == DEBUG_GROUP) { \ - DEBUG_OUTPUT(x); \ + DEBUG_OUTPUT(x); \ } \ } while (0) #endif