generic_category.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_HPP_INCLUDED
  2. #define BOOST_SYSTEM_DETAIL_GENERIC_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/generic_category_message.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. // generic_error_category
  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 generic_error_category: public error_category
  27. {
  28. public:
  29. BOOST_SYSTEM_CONSTEXPR generic_error_category() noexcept:
  30. error_category( detail::generic_category_id )
  31. {
  32. }
  33. const char * name() const noexcept BOOST_OVERRIDE
  34. {
  35. return "generic";
  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. // generic_error_category::message
  44. inline char const * generic_error_category::message( int ev, char * buffer, std::size_t len ) const noexcept
  45. {
  46. return generic_error_category_message( ev, buffer, len );
  47. }
  48. inline std::string generic_error_category::message( int ev ) const
  49. {
  50. return generic_error_category_message( ev );
  51. }
  52. } // namespace detail
  53. // generic_category()
  54. #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
  55. namespace detail
  56. {
  57. template<class T> struct BOOST_SYMBOL_VISIBLE generic_cat_holder
  58. {
  59. static constexpr generic_error_category instance{};
  60. };
  61. // Before C++17 it was mandatory to redeclare all static constexpr
  62. #if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
  63. template<class T> constexpr generic_error_category generic_cat_holder<T>::instance;
  64. #endif
  65. } // namespace detail
  66. constexpr error_category const & generic_category() noexcept
  67. {
  68. return detail::generic_cat_holder<void>::instance;
  69. }
  70. #else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
  71. #if !defined(__SUNPRO_CC) // trailing __global is not supported
  72. inline error_category const & generic_category() noexcept BOOST_SYMBOL_VISIBLE;
  73. #endif
  74. inline error_category const & generic_category() noexcept
  75. {
  76. static const detail::generic_error_category instance;
  77. return instance;
  78. }
  79. #endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
  80. // deprecated synonyms
  81. #ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
  82. BOOST_SYSTEM_DEPRECATED("please use generic_category()") inline const error_category & get_generic_category() { return generic_category(); }
  83. BOOST_SYSTEM_DEPRECATED("please use generic_category()") inline const error_category & get_posix_category() { return generic_category(); }
  84. BOOST_SYSTEM_DEPRECATED("please use generic_category()") static const error_category & posix_category BOOST_ATTRIBUTE_UNUSED = generic_category();
  85. BOOST_SYSTEM_DEPRECATED("please use generic_category()") static const error_category & errno_ecat BOOST_ATTRIBUTE_UNUSED = generic_category();
  86. #endif
  87. } // namespace system
  88. } // namespace boost
  89. #endif // #ifndef BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_HPP_INCLUDED