1 #ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED
2 #define BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED
4 // Support for interoperability between Boost.System and <system_error>
6 // Copyright 2018, 2021 Peter Dimov
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)
11 // See library home page at http://www.boost.org/libs/system
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>
30 class BOOST_SYMBOL_VISIBLE std_category: public std::error_category
34 boost::system::error_category const * pc_;
38 explicit std_category( boost::system::error_category const * pc, unsigned id ): pc_( pc )
42 #if defined(_MSC_VER) && defined(_CPPLIB_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000
44 // Poking into the protected _Addr member of std::error_category
45 // is not a particularly good programming practice, but what can
54 const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
59 std::string message( int ev ) const BOOST_OVERRIDE
61 return pc_->message( ev );
64 std::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT BOOST_OVERRIDE
66 return pc_->default_error_condition( ev );
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;
73 inline bool std_category::equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT
75 if( condition.category() == *this )
77 boost::system::error_condition bn( condition.value(), *pc_ );
78 return pc_->equivalent( code, bn );
80 else if( condition.category() == std::generic_category() || condition.category() == boost::system::generic_category() )
82 boost::system::error_condition bn( condition.value(), boost::system::generic_category() );
83 return pc_->equivalent( code, bn );
88 else if( std_category const* pc2 = dynamic_cast< std_category const* >( &condition.category() ) )
90 boost::system::error_condition bn( condition.value(), *pc2->pc_ );
91 return pc_->equivalent( code, bn );
98 return default_error_condition( code ) == condition;
102 inline bool std_category::equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT
104 if( code.category() == *this )
106 boost::system::error_code bc( code.value(), *pc_ );
107 return pc_->equivalent( bc, condition );
109 else if( code.category() == std::generic_category() || code.category() == boost::system::generic_category() )
111 boost::system::error_code bc( code.value(), boost::system::generic_category() );
112 return pc_->equivalent( bc, condition );
115 #ifndef BOOST_NO_RTTI
117 else if( std_category const* pc2 = dynamic_cast< std_category const* >( &code.category() ) )
119 boost::system::error_code bc( code.value(), *pc2->pc_ );
120 return pc_->equivalent( bc, condition );
125 else if( *pc_ == boost::system::generic_category() )
127 return std::generic_category().equivalent( code, condition );
135 } // namespace detail
137 } // namespace system
141 #endif // #ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED