include/boost/url/grammar/impl/error.hpp
100.0% Lines (36/36)
100.0% Functions (11/11)
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 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 | |||
| 10 | #ifndef BOOST_URL_GRAMMAR_IMPL_ERROR_HPP | ||
| 11 | #define BOOST_URL_GRAMMAR_IMPL_ERROR_HPP | ||
| 12 | |||
| 13 | #include <type_traits> | ||
| 14 | |||
| 15 | namespace boost { | ||
| 16 | namespace system { | ||
| 17 | template<> | ||
| 18 | struct is_error_code_enum< | ||
| 19 | ::boost::urls::grammar::error> | ||
| 20 | { | ||
| 21 | static bool const value = true; | ||
| 22 | }; | ||
| 23 | template<> | ||
| 24 | struct is_error_condition_enum< | ||
| 25 | ::boost::urls::grammar::condition> | ||
| 26 | { | ||
| 27 | static bool const value = true; | ||
| 28 | }; | ||
| 29 | } // system | ||
| 30 | } // boost | ||
| 31 | |||
| 32 | namespace boost { | ||
| 33 | namespace urls { | ||
| 34 | namespace grammar { | ||
| 35 | |||
| 36 | namespace detail { | ||
| 37 | |||
| 38 | struct BOOST_SYMBOL_VISIBLE | ||
| 39 | error_cat_type | ||
| 40 | : system::error_category | ||
| 41 | { | ||
| 42 | BOOST_URL_CXX20_CONSTEXPR | ||
| 43 | 82 | const char* name( | |
| 44 | ) const noexcept override | ||
| 45 | { | ||
| 46 | 82 | return "boost.url.grammar"; | |
| 47 | } | ||
| 48 | |||
| 49 | 82 | std::string message( | |
| 50 | int code) const override | ||
| 51 | { | ||
| 52 | 164 | return message(code, nullptr, 0); | |
| 53 | } | ||
| 54 | |||
| 55 | BOOST_URL_CXX20_CONSTEXPR | ||
| 56 | 82 | char const* message( | |
| 57 | int code, | ||
| 58 | char*, | ||
| 59 | std::size_t) const noexcept override | ||
| 60 | { | ||
| 61 | 82 | switch(static_cast<error>(code)) | |
| 62 | { | ||
| 63 | 1 | default: | |
| 64 | 1 | case error::need_more: return "need more"; | |
| 65 | 14 | case error::mismatch: return "mismatch"; | |
| 66 | 13 | case error::invalid: return "invalid"; | |
| 67 | 1 | case error::end_of_range: return "end of range"; | |
| 68 | 52 | case error::leftover: return "leftover"; | |
| 69 | 1 | case error::out_of_range: return "out of range"; | |
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | BOOST_URL_CXX20_CONSTEXPR | ||
| 74 | system::error_condition | ||
| 75 | default_error_condition( | ||
| 76 | int ev) const noexcept override; | ||
| 77 | |||
| 78 | 75 | BOOST_SYSTEM_CONSTEXPR error_cat_type() noexcept | |
| 79 | 75 | : error_category(0x0536e50a30f9e9f2) | |
| 80 | { | ||
| 81 | 75 | } | |
| 82 | }; | ||
| 83 | |||
| 84 | struct BOOST_SYMBOL_VISIBLE | ||
| 85 | condition_cat_type | ||
| 86 | : system::error_category | ||
| 87 | { | ||
| 88 | BOOST_URL_CXX20_CONSTEXPR | ||
| 89 | 5 | const char* name( | |
| 90 | ) const noexcept override | ||
| 91 | { | ||
| 92 | 5 | return "boost.url.grammar"; | |
| 93 | } | ||
| 94 | |||
| 95 | 5 | std::string message( | |
| 96 | int code) const override | ||
| 97 | { | ||
| 98 | 10 | return message(code, nullptr, 0); | |
| 99 | } | ||
| 100 | |||
| 101 | BOOST_URL_CXX20_CONSTEXPR | ||
| 102 | 5 | char const* message( | |
| 103 | int code, | ||
| 104 | char*, | ||
| 105 | std::size_t) const noexcept override | ||
| 106 | { | ||
| 107 | switch(static_cast<condition>(code)) | ||
| 108 | { | ||
| 109 | default: | ||
| 110 | case condition::fatal: | ||
| 111 | 5 | return "fatal condition"; | |
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | 75 | BOOST_SYSTEM_CONSTEXPR condition_cat_type() | |
| 116 | 75 | : error_category(0x0536e50a30f9e9f2) | |
| 117 | { | ||
| 118 | 75 | } | |
| 119 | }; | ||
| 120 | |||
| 121 | #if defined(BOOST_URL_HAS_CXX20_CONSTEXPR) | ||
| 122 | inline constexpr error_cat_type error_cat{}; | ||
| 123 | inline constexpr condition_cat_type condition_cat{}; | ||
| 124 | #else | ||
| 125 | BOOST_URL_DECL extern error_cat_type error_cat; | ||
| 126 | BOOST_URL_DECL extern condition_cat_type condition_cat; | ||
| 127 | #endif | ||
| 128 | |||
| 129 | } // detail | ||
| 130 | |||
| 131 | inline | ||
| 132 | BOOST_SYSTEM_CONSTEXPR | ||
| 133 | system::error_code | ||
| 134 | 11005 | make_error_code( | |
| 135 | error ev) noexcept | ||
| 136 | { | ||
| 137 | return system::error_code{ | ||
| 138 | static_cast<std::underlying_type< | ||
| 139 | error>::type>(ev), | ||
| 140 | 11005 | detail::error_cat}; | |
| 141 | } | ||
| 142 | |||
| 143 | inline | ||
| 144 | BOOST_SYSTEM_CONSTEXPR | ||
| 145 | system::error_condition | ||
| 146 | 20 | make_error_condition( | |
| 147 | condition c) noexcept | ||
| 148 | { | ||
| 149 | 20 | return system::error_condition{ | |
| 150 | static_cast<std::underlying_type< | ||
| 151 | condition>::type>(c), | ||
| 152 | 20 | detail::condition_cat}; | |
| 153 | } | ||
| 154 | |||
| 155 | BOOST_URL_CXX20_CONSTEXPR_OR_INLINE | ||
| 156 | system::error_condition | ||
| 157 | 6 | detail::error_cat_type:: | |
| 158 | default_error_condition( | ||
| 159 | int ev) const noexcept | ||
| 160 | { | ||
| 161 | 6 | switch(static_cast<error>(ev)) | |
| 162 | { | ||
| 163 | 2 | case error::invalid: | |
| 164 | case error::out_of_range: | ||
| 165 | 2 | return condition::fatal; | |
| 166 | 4 | default: | |
| 167 | 4 | return {ev, *this}; | |
| 168 | } | ||
| 169 | } | ||
| 170 | |||
| 171 | } // grammar | ||
| 172 | } // urls | ||
| 173 | } // boost | ||
| 174 | |||
| 175 | #endif | ||
| 176 |