interop_category.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef BOOST_SYSTEM_DETAIL_INTEROP_CATEGORY_HPP_INCLUDED
  2. #define BOOST_SYSTEM_DETAIL_INTEROP_CATEGORY_HPP_INCLUDED
  3. // Copyright Beman Dawes 2006, 2007
  4. // Copyright Christoper Kohlhoff 2007
  5. // Copyright Peter Dimov 2017, 2018, 2021
  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/error_category.hpp>
  12. #include <boost/system/detail/snprintf.hpp>
  13. #include <boost/system/detail/config.hpp>
  14. #include <boost/config.hpp>
  15. namespace boost
  16. {
  17. namespace system
  18. {
  19. namespace detail
  20. {
  21. // interop_error_category, used for std::error_code
  22. #if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
  23. #pragma GCC diagnostic push
  24. #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
  25. #endif
  26. class BOOST_SYMBOL_VISIBLE interop_error_category: public error_category
  27. {
  28. public:
  29. BOOST_SYSTEM_CONSTEXPR interop_error_category() noexcept:
  30. error_category( detail::interop_category_id )
  31. {
  32. }
  33. const char * name() const noexcept BOOST_OVERRIDE
  34. {
  35. return "std:unknown";
  36. }
  37. std::string message( int ev ) const BOOST_OVERRIDE;
  38. char const * message( int ev, char * buffer, std::size_t len ) const noexcept BOOST_OVERRIDE;
  39. };
  40. #if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
  41. #pragma GCC diagnostic pop
  42. #endif
  43. inline char const * interop_error_category::message( int ev, char * buffer, std::size_t len ) const noexcept
  44. {
  45. detail::snprintf( buffer, len, "Unknown interop error %d", ev );
  46. return buffer;
  47. }
  48. inline std::string interop_error_category::message( int ev ) const
  49. {
  50. char buffer[ 48 ];
  51. return message( ev, buffer, sizeof( buffer ) );
  52. }
  53. // interop_category()
  54. #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
  55. template<class T> struct BOOST_SYMBOL_VISIBLE interop_cat_holder
  56. {
  57. static constexpr interop_error_category instance{};
  58. };
  59. // Before C++17 it was mandatory to redeclare all static constexpr
  60. #if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
  61. template<class T> constexpr interop_error_category interop_cat_holder<T>::instance;
  62. #endif
  63. constexpr error_category const & interop_category() noexcept
  64. {
  65. return interop_cat_holder<void>::instance;
  66. }
  67. #else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
  68. #if !defined(__SUNPRO_CC) // trailing __global is not supported
  69. inline error_category const & interop_category() noexcept BOOST_SYMBOL_VISIBLE;
  70. #endif
  71. inline error_category const & interop_category() noexcept
  72. {
  73. static const detail::interop_error_category instance;
  74. return instance;
  75. }
  76. #endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
  77. } // namespace detail
  78. } // namespace system
  79. } // namespace boost
  80. #endif // #ifndef BOOST_SYSTEM_DETAIL_INTEROP_CATEGORY_HPP_INCLUDED