#ifndef SOPHIAR2_DEBUG_MACRO_H #define SOPHIAR2_DEBUG_MACRO_H #include "core/timestamp_helper.hpp" #include "third_party/scope_guard.hpp" #include "utility/versatile_buffer2.hpp" #include #include #include #include #include #include #include #define DEBUG_PRINT(msg) \ std::cout << fmt::format("F:{} L:{} T:{} {}", \ __FILE__, __LINE__, current_timestamp(), msg) \ << std::endl #define FILE_LINE_TRACE DEBUG_PRINT(""); #define FILE_LINE_TRACE_WITH_THIS \ { \ auto __msg = fmt::format("TH:{}", (void *) this); \ DEBUG_PRINT(__msg); \ } #define DEBUG_PRINT_ADDRESS(obj) \ { \ auto __msg = fmt::format("PTR:{}", (void *) std::addressof(obj)); \ DEBUG_PRINT(__msg); \ } #define DEBUG_PRINT_TYPE(type) \ { \ auto __msg = fmt::format("TYPE:{}", boost::core::demangle(typeid(type).name())); \ DEBUG_PRINT(__msg); \ } #define ENSURE(func) \ { \ bool ok = (func); \ if (!ok) return false; \ } #define ENSURE_CO(func) \ { \ bool ok = (func); \ if (!ok) co_return false; \ } #define CO_ENSURE(func) \ { \ bool ok = co_await (func); \ if (!ok) { \ co_return false; \ } \ } #define RUN_ONCE \ static bool __is_called = false; \ if (__is_called) [[likely]] return; \ __is_called = true; namespace sophiar { using boost::asio::awaitable; using boost::asio::use_awaitable; template inline awaitable coro_sleep(DurationType t) { boost::asio::high_resolution_timer timer(co_await boost::asio::this_coro::executor); timer.expires_from_now(t); co_await timer.async_wait(use_awaitable); co_return; } template void print_variable(const char *var_name, const BasicObjType &var) { auto ss = string_writer{}; var->write_to(ss); std::cout << fmt::format("{} = {}", var_name, ss.get_string_and_reset()) << std::endl; } #define PRINT_VARIABLE(var) print_variable(#var, var) } #endif //SOPHIAR2_DEBUG_MACRO_H