system_category.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_HPP_INCLUDED
  2. #define BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_HPP_INCLUDED
  3. // Copyright Beman Dawes 2006, 2007
  4. // Copyright Christoper Kohlhoff 2007
  5. // Copyright Peter Dimov 2017, 2018
  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/config.hpp>
  13. #include <boost/config.hpp>
  14. namespace boost
  15. {
  16. namespace system
  17. {
  18. namespace detail
  19. {
  20. // system_error_category
  21. #if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
  22. #pragma GCC diagnostic push
  23. #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
  24. #endif
  25. class BOOST_SYMBOL_VISIBLE system_error_category: public error_category
  26. {
  27. public:
  28. BOOST_SYSTEM_CONSTEXPR system_error_category() noexcept:
  29. error_category( detail::system_category_id )
  30. {
  31. }
  32. const char * name() const noexcept BOOST_OVERRIDE
  33. {
  34. return "system";
  35. }
  36. error_condition default_error_condition( int ev ) const noexcept BOOST_OVERRIDE;
  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. } // namespace detail
  44. // system_category()
  45. #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
  46. namespace detail
  47. {
  48. template<class T> struct BOOST_SYMBOL_VISIBLE system_cat_holder
  49. {
  50. static constexpr system_error_category instance{};
  51. };
  52. // Before C++17 it was mandatory to redeclare all static constexpr
  53. #if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
  54. template<class T> constexpr system_error_category system_cat_holder<T>::instance;
  55. #endif
  56. } // namespace detail
  57. constexpr error_category const & system_category() noexcept
  58. {
  59. return detail::system_cat_holder<void>::instance;
  60. }
  61. #else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
  62. #if !defined(__SUNPRO_CC) // trailing __global is not supported
  63. inline error_category const & system_category() noexcept BOOST_SYMBOL_VISIBLE;
  64. #endif
  65. inline error_category const & system_category() noexcept
  66. {
  67. static const detail::system_error_category instance;
  68. return instance;
  69. }
  70. #endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
  71. // deprecated synonyms
  72. #ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
  73. BOOST_SYSTEM_DEPRECATED("please use system_category()") inline const error_category & get_system_category() { return system_category(); }
  74. BOOST_SYSTEM_DEPRECATED("please use system_category()") static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED = system_category();
  75. #endif
  76. } // namespace system
  77. } // namespace boost
  78. #endif // #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_HPP_INCLUDED