diff --git a/debug.hpp b/debug.hpp index 56a86c1..6cadc4e 100644 --- a/debug.hpp +++ b/debug.hpp @@ -193,6 +193,18 @@ #ifndef DEBUG_OUTPUT # define DEBUG_OUTPUT std::cerr << #endif +#ifndef DEBUG_GROUP +# define DEBUG_GROUP 0 +#endif +#ifndef DEBUG_OUTPUT_GROUP +# define DEBUG_OUTPUT_GROUP(x) do { \ + if (DEBUG_GROUP == 0) { \ + DEBUG_OUTPUT(x); \ + } else if (group == DEBUG_GROUP) { \ + DEBUG_OUTPUT(x); \ + } \ +} while (0) +#endif #ifndef DEBUG_ENABLE_FILES_MATCH # define DEBUG_ENABLE_FILES_MATCH 0 #endif @@ -1310,6 +1322,7 @@ struct DEBUG_NODISCARD debug { panic = 2, supress = 3, } state; + int group; DEBUG_SOURCE_LOCATION loc; # if DEBUG_SHOW_TIMESTAMP == 2 @@ -1524,7 +1537,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 +1546,8 @@ struct DEBUG_NODISCARD debug { # endif ? silent : supress), - loc(loc) { + loc(loc), + group(group) { } debug &setloc(DEBUG_SOURCE_LOCATION const &newloc = @@ -1603,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; @@ -1622,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; @@ -1971,7 +1985,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 +2102,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