std_category_impl.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_IMPL_HPP_INCLUDED
  2. #define BOOST_SYSTEM_DETAIL_STD_CATEGORY_IMPL_HPP_INCLUDED
  3. // Support for interoperability between Boost.System and <system_error>
  4. //
  5. // Copyright 2018, 2021 Peter Dimov
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See library home page at http://www.boost.org/libs/system
  11. #include <boost/system/detail/std_category.hpp>
  12. #include <boost/system/detail/error_condition.hpp>
  13. #include <boost/system/detail/error_code.hpp>
  14. #include <boost/system/detail/generic_category.hpp>
  15. //
  16. namespace boost
  17. {
  18. namespace system
  19. {
  20. namespace detail
  21. {
  22. inline bool std_category::equivalent( int code, const std::error_condition & condition ) const noexcept
  23. {
  24. if( condition.category() == *this )
  25. {
  26. boost::system::error_condition bn( condition.value(), *pc_ );
  27. return pc_->equivalent( code, bn );
  28. }
  29. else if( condition.category() == std::generic_category() || condition.category() == boost::system::generic_category() )
  30. {
  31. boost::system::error_condition bn( condition.value(), boost::system::generic_category() );
  32. return pc_->equivalent( code, bn );
  33. }
  34. #ifndef BOOST_NO_RTTI
  35. else if( std_category const* pc2 = dynamic_cast< std_category const* >( &condition.category() ) )
  36. {
  37. boost::system::error_condition bn( condition.value(), *pc2->pc_ );
  38. return pc_->equivalent( code, bn );
  39. }
  40. #endif
  41. else
  42. {
  43. return default_error_condition( code ) == condition;
  44. }
  45. }
  46. inline bool std_category::equivalent( const std::error_code & code, int condition ) const noexcept
  47. {
  48. if( code.category() == *this )
  49. {
  50. boost::system::error_code bc( code.value(), *pc_ );
  51. return pc_->equivalent( bc, condition );
  52. }
  53. else if( code.category() == std::generic_category() || code.category() == boost::system::generic_category() )
  54. {
  55. boost::system::error_code bc( code.value(), boost::system::generic_category() );
  56. return pc_->equivalent( bc, condition );
  57. }
  58. #ifndef BOOST_NO_RTTI
  59. else if( std_category const* pc2 = dynamic_cast< std_category const* >( &code.category() ) )
  60. {
  61. boost::system::error_code bc( code.value(), *pc2->pc_ );
  62. return pc_->equivalent( bc, condition );
  63. }
  64. #endif
  65. else if( *pc_ == boost::system::generic_category() )
  66. {
  67. return std::generic_category().equivalent( code, condition );
  68. }
  69. else
  70. {
  71. return false;
  72. }
  73. }
  74. } // namespace detail
  75. } // namespace system
  76. } // namespace boost
  77. #endif // #ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_IMPL_HPP_INCLUDED