frame.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright Antony Polukhin, 2016-2019.
  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/core/explicit_operator_bool.hpp>
  15. #include <boost/stacktrace/safe_dump_to.hpp> // boost::stacktrace::detail::native_frame_ptr_t
  16. #include <boost/stacktrace/detail/frame_decl.hpp>
  17. #include <boost/stacktrace/detail/push_options.h>
  18. namespace boost { namespace stacktrace {
  19. /// Comparison operators that provide platform dependant ordering and have O(1) complexity; are Async-Handler-Safe.
  20. BOOST_CONSTEXPR inline bool operator< (const frame& lhs, const frame& rhs) BOOST_NOEXCEPT { return lhs.address() < rhs.address(); }
  21. BOOST_CONSTEXPR inline bool operator> (const frame& lhs, const frame& rhs) BOOST_NOEXCEPT { return rhs < lhs; }
  22. BOOST_CONSTEXPR inline bool operator<=(const frame& lhs, const frame& rhs) BOOST_NOEXCEPT { return !(lhs > rhs); }
  23. BOOST_CONSTEXPR inline bool operator>=(const frame& lhs, const frame& rhs) BOOST_NOEXCEPT { return !(lhs < rhs); }
  24. BOOST_CONSTEXPR inline bool operator==(const frame& lhs, const frame& rhs) BOOST_NOEXCEPT { return lhs.address() == rhs.address(); }
  25. BOOST_CONSTEXPR inline bool operator!=(const frame& lhs, const frame& rhs) BOOST_NOEXCEPT { return !(lhs == rhs); }
  26. /// Fast hashing support, O(1) complexity; Async-Handler-Safe.
  27. inline std::size_t hash_value(const frame& f) BOOST_NOEXCEPT {
  28. return reinterpret_cast<std::size_t>(f.address());
  29. }
  30. /// Outputs stacktrace::frame in a human readable format to string; unsafe to use in async handlers.
  31. BOOST_STACKTRACE_FUNCTION std::string to_string(const frame& f);
  32. /// Outputs stacktrace::frame in a human readable format to output stream; unsafe to use in async handlers.
  33. template <class CharT, class TraitsT>
  34. std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const frame& f) {
  35. return os << boost::stacktrace::to_string(f);
  36. }
  37. }} // namespace boost::stacktrace
  38. /// @cond
  39. #include <boost/stacktrace/detail/pop_options.h>
  40. #ifndef BOOST_STACKTRACE_LINK
  41. # if defined(BOOST_STACKTRACE_USE_NOOP)
  42. # include <boost/stacktrace/detail/frame_noop.ipp>
  43. # elif defined(BOOST_MSVC) || defined(BOOST_STACKTRACE_USE_WINDBG) || defined(BOOST_STACKTRACE_USE_WINDBG_CACHED)
  44. # include <boost/stacktrace/detail/frame_msvc.ipp>
  45. # else
  46. # include <boost/stacktrace/detail/frame_unwind.ipp>
  47. # endif
  48. #endif
  49. /// @endcond
  50. #endif // BOOST_STACKTRACE_FRAME_HPP