]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/system/detail/std_category.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / system / detail / std_category.hpp
1 #ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED
2 #define BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED
3
4 // Support for interoperability between Boost.System and <system_error>
5 //
6 // Copyright 2018, 2021 Peter Dimov
7 //
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 //
11 // See library home page at http://www.boost.org/libs/system
12
13 #include <boost/system/detail/error_category.hpp>
14 #include <boost/system/detail/error_condition.hpp>
15 #include <boost/system/detail/error_code.hpp>
16 #include <boost/system/detail/generic_category.hpp>
17 #include <system_error>
18
19 //
20
21 namespace boost
22 {
23
24 namespace system
25 {
26
27 namespace detail
28 {
29
30 class BOOST_SYMBOL_VISIBLE std_category: public std::error_category
31 {
32 private:
33
34 boost::system::error_category const * pc_;
35
36 public:
37
38 explicit std_category( boost::system::error_category const * pc, unsigned id ): pc_( pc )
39 {
40 if( id != 0 )
41 {
42 #if defined(_MSC_VER) && defined(_CPPLIB_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000
43
44 // Poking into the protected _Addr member of std::error_category
45 // is not a particularly good programming practice, but what can
46 // you do
47
48 _Addr = id;
49
50 #endif
51 }
52 }
53
54 const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
55 {
56 return pc_->name();
57 }
58
59 std::string message( int ev ) const BOOST_OVERRIDE
60 {
61 return pc_->message( ev );
62 }
63
64 std::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT BOOST_OVERRIDE
65 {
66 return pc_->default_error_condition( ev );
67 }
68
69 bool equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
70 bool equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
71 };
72
73 inline bool std_category::equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT
74 {
75 if( condition.category() == *this )
76 {
77 boost::system::error_condition bn( condition.value(), *pc_ );
78 return pc_->equivalent( code, bn );
79 }
80 else if( condition.category() == std::generic_category() || condition.category() == boost::system::generic_category() )
81 {
82 boost::system::error_condition bn( condition.value(), boost::system::generic_category() );
83 return pc_->equivalent( code, bn );
84 }
85
86 #ifndef BOOST_NO_RTTI
87
88 else if( std_category const* pc2 = dynamic_cast< std_category const* >( &condition.category() ) )
89 {
90 boost::system::error_condition bn( condition.value(), *pc2->pc_ );
91 return pc_->equivalent( code, bn );
92 }
93
94 #endif
95
96 else
97 {
98 return default_error_condition( code ) == condition;
99 }
100 }
101
102 inline bool std_category::equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT
103 {
104 if( code.category() == *this )
105 {
106 boost::system::error_code bc( code.value(), *pc_ );
107 return pc_->equivalent( bc, condition );
108 }
109 else if( code.category() == std::generic_category() || code.category() == boost::system::generic_category() )
110 {
111 boost::system::error_code bc( code.value(), boost::system::generic_category() );
112 return pc_->equivalent( bc, condition );
113 }
114
115 #ifndef BOOST_NO_RTTI
116
117 else if( std_category const* pc2 = dynamic_cast< std_category const* >( &code.category() ) )
118 {
119 boost::system::error_code bc( code.value(), *pc2->pc_ );
120 return pc_->equivalent( bc, condition );
121 }
122
123 #endif
124
125 else if( *pc_ == boost::system::generic_category() )
126 {
127 return std::generic_category().equivalent( code, condition );
128 }
129 else
130 {
131 return false;
132 }
133 }
134
135 } // namespace detail
136
137 } // namespace system
138
139 } // namespace boost
140
141 #endif // #ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED