/src/boost/boost/json/impl/error.hpp
Line | Count | Source |
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 | | |
10 | | #ifndef BOOST_JSON_IMPL_ERROR_HPP |
11 | | #define BOOST_JSON_IMPL_ERROR_HPP |
12 | | |
13 | | #include <boost/system/error_category.hpp> |
14 | | #include <type_traits> |
15 | | |
16 | | namespace boost { |
17 | | namespace system { |
18 | | template<> |
19 | | struct is_error_code_enum< ::boost::json::error > |
20 | | { |
21 | | static bool const value = true; |
22 | | }; |
23 | | template<> |
24 | | struct is_error_condition_enum< ::boost::json::condition > |
25 | | { |
26 | | static bool const value = true; |
27 | | }; |
28 | | } // system |
29 | | } // boost |
30 | | |
31 | | namespace std { |
32 | | template<> |
33 | | struct is_error_code_enum< ::boost::json::error > |
34 | | { |
35 | | static bool const value = true; |
36 | | }; |
37 | | template<> |
38 | | struct is_error_condition_enum< ::boost::json::condition > |
39 | | { |
40 | | static bool const value = true; |
41 | | }; |
42 | | } // std |
43 | | |
44 | | namespace boost { |
45 | | namespace json { |
46 | | namespace detail { |
47 | | |
48 | | struct error_code_category_t |
49 | | : system::error_category |
50 | | { |
51 | | constexpr |
52 | | error_code_category_t() |
53 | | : system::error_category(0xB9A9B9922177C772) |
54 | | {} |
55 | | |
56 | | BOOST_JSON_DECL |
57 | | const char* |
58 | | name() const noexcept override; |
59 | | |
60 | | BOOST_JSON_DECL |
61 | | char const* |
62 | | message( int ev, char* buf, std::size_t len ) const noexcept override; |
63 | | |
64 | | BOOST_JSON_DECL |
65 | | std::string |
66 | | message( int ev ) const override; |
67 | | |
68 | | BOOST_JSON_DECL |
69 | | system::error_condition |
70 | | default_error_condition( int ev ) const noexcept override; |
71 | | }; |
72 | | |
73 | | extern |
74 | | BOOST_JSON_DECL |
75 | | error_code_category_t error_code_category; |
76 | | |
77 | | struct error_condition_category_t |
78 | | : system::error_category |
79 | | { |
80 | | constexpr |
81 | | error_condition_category_t() |
82 | | : system::error_category(0x37CEF5A036D24FD1) |
83 | | {} |
84 | | |
85 | | BOOST_JSON_DECL |
86 | | const char* |
87 | | name() const noexcept override; |
88 | | |
89 | | BOOST_JSON_DECL |
90 | | char const* |
91 | | message( int ev, char*, std::size_t ) const noexcept override; |
92 | | |
93 | | BOOST_JSON_DECL |
94 | | std::string |
95 | | message( int cv ) const override; |
96 | | }; |
97 | | |
98 | | extern |
99 | | BOOST_JSON_DECL |
100 | | error_condition_category_t error_condition_category; |
101 | | |
102 | | } // namespace detail |
103 | | |
104 | | inline |
105 | | BOOST_SYSTEM_CONSTEXPR |
106 | | system::error_code |
107 | | make_error_code(error e) noexcept |
108 | 89.9k | { |
109 | | |
110 | 89.9k | return system::error_code( |
111 | 89.9k | static_cast<std::underlying_type<error>::type>(e), |
112 | 89.9k | detail::error_code_category ); |
113 | 89.9k | } |
114 | | |
115 | | inline |
116 | | BOOST_SYSTEM_CONSTEXPR |
117 | | system::error_condition |
118 | | make_error_condition(condition c) noexcept |
119 | 0 | { |
120 | 0 | return system::error_condition( |
121 | 0 | static_cast<std::underlying_type<condition>::type>(c), |
122 | 0 | detail::error_condition_category ); |
123 | 0 | } |
124 | | |
125 | | } // namespace json |
126 | | } // namespace boost |
127 | | |
128 | | #endif |