error.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
  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 <type_traits>
  12. namespace boost {
  13. namespace system {
  14. template<>
  15. struct is_error_code_enum< ::boost::json::error >
  16. {
  17. static bool const value = true;
  18. };
  19. template<>
  20. struct is_error_condition_enum< ::boost::json::condition >
  21. {
  22. static bool const value = true;
  23. };
  24. } // system
  25. } // boost
  26. namespace std {
  27. template<>
  28. struct is_error_code_enum< ::boost::json::error >
  29. {
  30. static bool const value = true;
  31. };
  32. template<>
  33. struct is_error_condition_enum< ::boost::json::condition >
  34. {
  35. static bool const value = true;
  36. };
  37. } // std
  38. namespace boost {
  39. namespace json {
  40. namespace detail {
  41. struct error_code_category_t
  42. : error_category
  43. {
  44. constexpr
  45. error_code_category_t()
  46. : error_category(0xB9A9B9922177C772)
  47. {}
  48. BOOST_JSON_DECL
  49. const char*
  50. name() const noexcept override;
  51. BOOST_JSON_DECL
  52. char const*
  53. message( int ev, char* buf, std::size_t len ) const noexcept override;
  54. BOOST_JSON_DECL
  55. std::string
  56. message( int ev ) const override;
  57. BOOST_JSON_DECL
  58. error_condition
  59. default_error_condition( int ev ) const noexcept override;
  60. };
  61. extern
  62. BOOST_JSON_DECL
  63. error_code_category_t error_code_category;
  64. struct error_condition_category_t
  65. : error_category
  66. {
  67. constexpr
  68. error_condition_category_t()
  69. : error_category(0x37CEF5A036D24FD1)
  70. {}
  71. BOOST_JSON_DECL
  72. const char*
  73. name() const noexcept override;
  74. BOOST_JSON_DECL
  75. char const*
  76. message( int ev, char*, std::size_t ) const noexcept override;
  77. BOOST_JSON_DECL
  78. std::string
  79. message( int cv ) const override;
  80. };
  81. extern
  82. BOOST_JSON_DECL
  83. error_condition_category_t error_condition_category;
  84. } // namespace detail
  85. inline
  86. BOOST_SYSTEM_CONSTEXPR
  87. error_code
  88. make_error_code(error e) noexcept
  89. {
  90. return error_code(
  91. static_cast<std::underlying_type<error>::type>(e),
  92. detail::error_code_category );
  93. }
  94. inline
  95. BOOST_SYSTEM_CONSTEXPR
  96. error_condition
  97. make_error_condition(condition c) noexcept
  98. {
  99. return error_condition(
  100. static_cast<std::underlying_type<condition>::type>(c),
  101. detail::error_condition_category );
  102. }
  103. } // namespace json
  104. } // namespace boost
  105. #endif