Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1310,6 +1322,7 @@ struct DEBUG_NODISCARD debug {
panic = 2,
supress = 3,
} state;
int group;

DEBUG_SOURCE_LOCATION loc;
# if DEBUG_SHOW_TIMESTAMP == 2
Expand Down Expand Up @@ -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
Expand All @@ -1533,7 +1546,8 @@ struct DEBUG_NODISCARD debug {
# endif
? silent
: supress),
loc(loc) {
loc(loc),
group(group) {
}

debug &setloc(DEBUG_SOURCE_LOCATION const &newloc =
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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