debug_utility.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef SOPHIAR2_DEBUG_MACRO_H
  2. #define SOPHIAR2_DEBUG_MACRO_H
  3. #include "core/timestamp_helper.hpp"
  4. #include <boost/asio/awaitable.hpp>
  5. #include <boost/asio/high_resolution_timer.hpp>
  6. #include <boost/asio/this_coro.hpp>
  7. #include <boost/asio/use_awaitable.hpp>
  8. #include <spdlog/spdlog.h>
  9. #include <iostream>
  10. #define FILE_LINE_TRACE {\
  11. std::cout << fmt::format("F:{} L:{} T:{}", \
  12. __FILE_NAME__, __LINE__, sophiar::current_timestamp()) \
  13. << std::endl; }
  14. #define FILE_LINE_TRACE_WITH_THIS {\
  15. std::cout << fmt::format("F:{} L:{} T:{} TH:{}", \
  16. __FILE_NAME__, __LINE__, sophiar::current_timestamp(), (void *) this) \
  17. << std::endl; }
  18. #define PRINT_PTR(obj) {\
  19. std::cout << fmt::format("F:{} L:{} PTR: {}", __FILE_NAME__, __LINE__, \
  20. (void*)std::addressof(obj)) << std::endl; }
  21. #define ENSURE(func) \
  22. { \
  23. bool ok = (func); \
  24. if (!ok) return false; \
  25. }
  26. #define CO_ENSURE(func) \
  27. { \
  28. bool ok = co_await (func); \
  29. if (!ok) co_return false; \
  30. }
  31. namespace sophiar {
  32. using boost::asio::awaitable;
  33. using boost::asio::use_awaitable;
  34. template<typename DurationType>
  35. inline awaitable<void> coro_sleep(DurationType t) {
  36. boost::asio::high_resolution_timer timer(co_await boost::asio::this_coro::executor);
  37. timer.expires_from_now(t);
  38. co_await timer.async_wait(use_awaitable);
  39. co_return;
  40. }
  41. }
  42. #endif //SOPHIAR2_DEBUG_MACRO_H