frame.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright Antony Polukhin, 2016-2024.
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_STACKTRACE_FRAME_HPP
  7. #define BOOST_STACKTRACE_FRAME_HPP
  8. #include <boost/config.hpp>
  9. #ifdef BOOST_HAS_PRAGMA_ONCE
  10. # pragma once
  11. #endif
  12. #include <iosfwd>
  13. #include <string>
  14. #include <boost/stacktrace/safe_dump_to.hpp> // boost::stacktrace::detail::native_frame_ptr_t
  15. #include <boost/stacktrace/detail/frame_decl.hpp>
  16. #include <boost/stacktrace/detail/push_options.h>
  17. namespace boost { namespace stacktrace {
  18. /// Comparison operators that provide platform dependant ordering and have O(1) complexity; are Async-Handler-Safe.
  19. constexpr inline bool operator< (const frame& lhs, const frame& rhs) noexcept { return lhs.address() < rhs.address(); }
  20. constexpr inline bool operator> (const frame& lhs, const frame& rhs) noexcept { return rhs < lhs; }
  21. constexpr inline bool operator<=(const frame& lhs, const frame& rhs) noexcept { return !(lhs > rhs); }
  22. constexpr inline bool operator>=(const frame& lhs, const frame& rhs) noexcept { return !(lhs < rhs); }
  23. constexpr inline bool operator==(const frame& lhs, const frame& rhs) noexcept { return lhs.address() == rhs.address(); }
  24. constexpr inline bool operator!=(const frame& lhs, const frame& rhs) noexcept { return !(lhs == rhs); }
  25. /// Fast hashing support, O(1) complexity; Async-Handler-Safe.
  26. inline std::size_t hash_value(const frame& f) noexcept {
  27. return reinterpret_cast<std::size_t>(f.address());
  28. }
  29. /// Outputs stacktrace::frame in a human readable format to string; unsafe to use in async handlers.
  30. BOOST_STACKTRACE_FUNCTION std::string to_string(const frame& f);
  31. /// Outputs stacktrace::frame in a human readable format to output stream; unsafe to use in async handlers.
  32. template <class CharT, class TraitsT>
  33. std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const frame& f) {
  34. return os << boost::stacktrace::to_string(f);
  35. }
  36. }} // namespace boost::stacktrace
  37. /// @cond
  38. #include <boost/stacktrace/detail/pop_options.h>
  39. #ifndef BOOST_STACKTRACE_LINK
  40. # if defined(BOOST_STACKTRACE_USE_NOOP)
  41. # include <boost/stacktrace/detail/frame_noop.ipp>
  42. # elif defined(BOOST_MSVC) || defined(BOOST_STACKTRACE_USE_WINDBG) || defined(BOOST_STACKTRACE_USE_WINDBG_CACHED)
  43. # include <boost/stacktrace/detail/frame_msvc.ipp>
  44. # else
  45. # include <boost/stacktrace/detail/frame_unwind.ipp>
  46. # endif
  47. #endif
  48. /// @endcond
  49. #endif // BOOST_STACKTRACE_FRAME_HPP