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