diff --git a/include/rohrkabel/utils/assert.hpp b/include/rohrkabel/utils/assert.hpp deleted file mode 100644 index 6de9a1b..0000000 --- a/include/rohrkabel/utils/assert.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -namespace pipewire -{ - void check(bool, const char *); -} diff --git a/include/rohrkabel/utils/check.hpp b/include/rohrkabel/utils/check.hpp new file mode 100644 index 0000000..97bb8c8 --- /dev/null +++ b/include/rohrkabel/utils/check.hpp @@ -0,0 +1,7 @@ +#pragma once +#include + +namespace pipewire +{ + void check(bool, const char *, const std::source_location = std::source_location::current()); +} diff --git a/src/assert.cpp b/src/assert.cpp deleted file mode 100644 index 38c13b4..0000000 --- a/src/assert.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "utils/assert.hpp" - -#include - -namespace pipewire -{ - void check(bool condition, const char *message) - { - if (condition) - { - return; - } - - throw std::runtime_error(message); - } -} // namespace pipewire diff --git a/src/check.cpp b/src/check.cpp new file mode 100644 index 0000000..a16293b --- /dev/null +++ b/src/check.cpp @@ -0,0 +1,26 @@ +#include "utils/check.hpp" + +#include +#include +#include + +namespace pipewire +{ +#ifdef NDEBUG + void check(bool, const char *, const std::source_location) {} +#else + void check(bool condition, const char *message, const std::source_location loc) + { + if (condition) + { + return; + } + + const auto *error = strerror(errno); // NOLINT(*-mt-unsafe) + auto [file, line, col, func] = std::make_tuple(loc.file_name(), loc.line(), loc.column(), loc.function_name()); + + std::cerr << std::format("{} ({}:{}) [{}]: check failed \"{}\", error is \"{}\"\n", file, line, col, func, + message, error); + } +#endif +} // namespace pipewire