| 1 | #ifndef BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_HPP_INCLUDED |
| 2 | #define BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_HPP_INCLUDED |
| 3 | |
| 4 | // Copyright Beman Dawes 2006, 2007 |
| 5 | // Copyright Christoper Kohlhoff 2007 |
| 6 | // Copyright Peter Dimov 2017, 2018 |
| 7 | // |
| 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) |
| 10 | // |
| 11 | // See library home page at http://www.boost.org/libs/system |
| 12 | |
| 13 | #include <boost/system/detail/error_category.hpp> |
| 14 | #include <boost/system/detail/generic_category_message.hpp> |
| 15 | #include <boost/system/detail/config.hpp> |
| 16 | #include <boost/config.hpp> |
| 17 | |
| 18 | namespace boost |
| 19 | { |
| 20 | |
| 21 | namespace system |
| 22 | { |
| 23 | |
| 24 | namespace detail |
| 25 | { |
| 26 | |
| 27 | // generic_error_category |
| 28 | |
| 29 | #if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG ) |
| 30 | #pragma GCC diagnostic push |
| 31 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" |
| 32 | #endif |
| 33 | |
| 34 | class BOOST_SYMBOL_VISIBLE generic_error_category: public error_category |
| 35 | { |
| 36 | public: |
| 37 | |
| 38 | BOOST_SYSTEM_CONSTEXPR generic_error_category() noexcept: |
| 39 | error_category( detail::generic_category_id ) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | const char * name() const noexcept BOOST_OVERRIDE |
| 44 | { |
| 45 | return "generic" ; |
| 46 | } |
| 47 | |
| 48 | std::string message( int ev ) const BOOST_OVERRIDE; |
| 49 | char const * message( int ev, char * buffer, std::size_t len ) const noexcept BOOST_OVERRIDE; |
| 50 | }; |
| 51 | |
| 52 | #if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG ) |
| 53 | #pragma GCC diagnostic pop |
| 54 | #endif |
| 55 | |
| 56 | // generic_error_category::message |
| 57 | |
| 58 | inline char const * generic_error_category::message( int ev, char * buffer, std::size_t len ) const noexcept |
| 59 | { |
| 60 | return generic_error_category_message( ev, buffer, len ); |
| 61 | } |
| 62 | |
| 63 | inline std::string generic_error_category::message( int ev ) const |
| 64 | { |
| 65 | return generic_error_category_message( ev ); |
| 66 | } |
| 67 | |
| 68 | } // namespace detail |
| 69 | |
| 70 | // generic_category() |
| 71 | |
| 72 | #if defined(BOOST_SYSTEM_HAS_CONSTEXPR) |
| 73 | |
| 74 | namespace detail |
| 75 | { |
| 76 | |
| 77 | template<class T> struct BOOST_SYMBOL_VISIBLE generic_cat_holder |
| 78 | { |
| 79 | static constexpr generic_error_category instance{}; |
| 80 | }; |
| 81 | |
| 82 | // Before C++17 it was mandatory to redeclare all static constexpr |
| 83 | #if defined(BOOST_NO_CXX17_INLINE_VARIABLES) |
| 84 | template<class T> constexpr generic_error_category generic_cat_holder<T>::instance; |
| 85 | #endif |
| 86 | |
| 87 | } // namespace detail |
| 88 | |
| 89 | constexpr error_category const & generic_category() noexcept |
| 90 | { |
| 91 | return detail::generic_cat_holder<void>::instance; |
| 92 | } |
| 93 | |
| 94 | #else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR) |
| 95 | |
| 96 | #if !defined(__SUNPRO_CC) // trailing __global is not supported |
| 97 | inline error_category const & generic_category() noexcept BOOST_SYMBOL_VISIBLE; |
| 98 | #endif |
| 99 | |
| 100 | inline error_category const & generic_category() noexcept |
| 101 | { |
| 102 | static const detail::generic_error_category instance; |
| 103 | return instance; |
| 104 | } |
| 105 | |
| 106 | #endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR) |
| 107 | |
| 108 | // deprecated synonyms |
| 109 | |
| 110 | #ifdef BOOST_SYSTEM_ENABLE_DEPRECATED |
| 111 | |
| 112 | BOOST_SYSTEM_DEPRECATED("please use generic_category()" ) inline const error_category & get_generic_category() { return generic_category(); } |
| 113 | BOOST_SYSTEM_DEPRECATED("please use generic_category()" ) inline const error_category & get_posix_category() { return generic_category(); } |
| 114 | BOOST_SYSTEM_DEPRECATED("please use generic_category()" ) static const error_category & posix_category BOOST_ATTRIBUTE_UNUSED = generic_category(); |
| 115 | BOOST_SYSTEM_DEPRECATED("please use generic_category()" ) static const error_category & errno_ecat BOOST_ATTRIBUTE_UNUSED = generic_category(); |
| 116 | |
| 117 | #endif |
| 118 | |
| 119 | } // namespace system |
| 120 | |
| 121 | } // namespace boost |
| 122 | |
| 123 | #endif // #ifndef BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_HPP_INCLUDED |
| 124 | |