error.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // Copyright (c) 2019 Vinnie Falco ([email protected])
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/json
  8. //
  9. #ifndef BOOST_JSON_IMPL_ERROR_HPP
  10. #define BOOST_JSON_IMPL_ERROR_HPP
  11. #include <boost/system/error_category.hpp>
  12. #include <type_traits>
  13. namespace boost {
  14. namespace system {
  15. template<>
  16. struct is_error_code_enum< ::boost::json::error >
  17. {
  18. static bool const value = true;
  19. };
  20. template<>
  21. struct is_error_condition_enum< ::boost::json::condition >
  22. {
  23. static bool const value = true;
  24. };
  25. } // system
  26. } // boost
  27. namespace std {
  28. template<>
  29. struct is_error_code_enum< ::boost::json::error >
  30. {
  31. static bool const value = true;
  32. };
  33. template<>
  34. struct is_error_condition_enum< ::boost::json::condition >
  35. {
  36. static bool const value = true;
  37. };
  38. } // std
  39. namespace boost {
  40. namespace json {
  41. namespace detail {
  42. struct error_code_category_t
  43. : system::error_category
  44. {
  45. constexpr
  46. error_code_category_t()
  47. : system::error_category(0xB9A9B9922177C772)
  48. {}
  49. BOOST_JSON_DECL
  50. const char*
  51. name() const noexcept override;
  52. BOOST_JSON_DECL
  53. char const*
  54. message( int ev, char* buf, std::size_t len ) const noexcept override;
  55. BOOST_JSON_DECL
  56. std::string
  57. message( int ev ) const override;
  58. BOOST_JSON_DECL
  59. system::error_condition
  60. default_error_condition( int ev ) const noexcept override;
  61. };
  62. extern
  63. BOOST_JSON_DECL
  64. error_code_category_t error_code_category;
  65. struct error_condition_category_t
  66. : system::error_category
  67. {
  68. constexpr
  69. error_condition_category_t()
  70. : system::error_category(0x37CEF5A036D24FD1)
  71. {}
  72. BOOST_JSON_DECL
  73. const char*
  74. name() const noexcept override;
  75. BOOST_JSON_DECL
  76. char const*
  77. message( int ev, char*, std::size_t ) const noexcept override;
  78. BOOST_JSON_DECL
  79. std::string
  80. message( int cv ) const override;
  81. };
  82. extern
  83. BOOST_JSON_DECL
  84. error_condition_category_t error_condition_category;
  85. } // namespace detail
  86. inline
  87. BOOST_SYSTEM_CONSTEXPR
  88. system::error_code
  89. make_error_code(error e) noexcept
  90. {
  91. return system::error_code(
  92. static_cast<std::underlying_type<error>::type>(e),
  93. detail::error_code_category );
  94. }
  95. inline
  96. BOOST_SYSTEM_CONSTEXPR
  97. system::error_condition
  98. make_error_condition(condition c) noexcept
  99. {
  100. return system::error_condition(
  101. static_cast<std::underlying_type<condition>::type>(c),
  102. detail::error_condition_category );
  103. }
  104. } // namespace json
  105. } // namespace boost
  106. #endif