error.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/url
  8. //
  9. #ifndef BOOST_URL_GRAMMAR_IMPL_ERROR_HPP
  10. #define BOOST_URL_GRAMMAR_IMPL_ERROR_HPP
  11. #include <type_traits>
  12. namespace boost {
  13. namespace system {
  14. template<>
  15. struct is_error_code_enum<
  16. ::boost::urls::grammar::error>
  17. {
  18. static bool const value = true;
  19. };
  20. template<>
  21. struct is_error_condition_enum<
  22. ::boost::urls::grammar::condition>
  23. {
  24. static bool const value = true;
  25. };
  26. } // system
  27. } // boost
  28. namespace boost {
  29. namespace urls {
  30. namespace grammar {
  31. namespace detail {
  32. struct BOOST_SYMBOL_VISIBLE
  33. error_cat_type
  34. : system::error_category
  35. {
  36. BOOST_URL_DECL
  37. const char* name(
  38. ) const noexcept override;
  39. BOOST_URL_DECL
  40. std::string message(
  41. int) const override;
  42. BOOST_URL_DECL
  43. char const* message(
  44. int, char*, std::size_t
  45. ) const noexcept override;
  46. BOOST_URL_DECL
  47. system::error_condition
  48. default_error_condition(
  49. int code) const noexcept override;
  50. BOOST_SYSTEM_CONSTEXPR error_cat_type() noexcept
  51. : error_category(0x0536e50a30f9e9f2)
  52. {
  53. }
  54. };
  55. struct BOOST_SYMBOL_VISIBLE
  56. condition_cat_type
  57. : system::error_category
  58. {
  59. BOOST_URL_DECL
  60. const char* name(
  61. ) const noexcept override;
  62. BOOST_URL_DECL
  63. std::string message(
  64. int) const override;
  65. BOOST_URL_DECL
  66. char const* message(
  67. int, char*, std::size_t
  68. ) const noexcept override;
  69. BOOST_SYSTEM_CONSTEXPR condition_cat_type()
  70. : error_category(0x0536e50a30f9e9f2)
  71. {
  72. }
  73. };
  74. BOOST_URL_DECL extern
  75. error_cat_type error_cat;
  76. BOOST_URL_DECL extern
  77. condition_cat_type condition_cat;
  78. } // detail
  79. inline
  80. system::error_code
  81. make_error_code(
  82. error ev) noexcept
  83. {
  84. return system::error_code{
  85. static_cast<std::underlying_type<
  86. error>::type>(ev),
  87. detail::error_cat};
  88. }
  89. inline
  90. system::error_condition
  91. make_error_condition(
  92. condition c) noexcept
  93. {
  94. return system::error_condition{
  95. static_cast<std::underlying_type<
  96. condition>::type>(c),
  97. detail::condition_cat};
  98. }
  99. } // grammar
  100. } // urls
  101. } // boost
  102. #endif