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