]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
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 | |
92f5a8d4 | 7 | // |
20effc67 TL |
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) | |
92f5a8d4 | 10 | // |
20effc67 | 11 | // See library home page at http://www.boost.org/libs/system |
92f5a8d4 | 12 | |
20effc67 TL |
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> | |
92f5a8d4 TL |
17 | |
18 | namespace boost | |
19 | { | |
20 | ||
21 | namespace system | |
22 | { | |
23 | ||
24 | namespace detail | |
25 | { | |
26 | ||
20effc67 | 27 | // generic_error_category |
92f5a8d4 | 28 | |
20effc67 TL |
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 | |
92f5a8d4 | 33 | |
20effc67 | 34 | class BOOST_SYMBOL_VISIBLE generic_error_category: public error_category |
92f5a8d4 | 35 | { |
20effc67 | 36 | public: |
92f5a8d4 | 37 | |
20effc67 TL |
38 | BOOST_SYSTEM_CONSTEXPR generic_error_category() BOOST_NOEXCEPT: |
39 | error_category( detail::generic_category_id ) | |
40 | { | |
41 | } | |
42 | ||
43 | const char * name() const BOOST_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 BOOST_NOEXCEPT BOOST_OVERRIDE; | |
50 | }; | |
51 | ||
52 | #if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG ) | |
53 | #pragma GCC diagnostic pop | |
54 | #endif | |
92f5a8d4 | 55 | |
20effc67 TL |
56 | // generic_error_category::message |
57 | ||
58 | inline char const * generic_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT | |
92f5a8d4 | 59 | { |
20effc67 | 60 | return generic_error_category_message( ev, buffer, len ); |
92f5a8d4 TL |
61 | } |
62 | ||
20effc67 | 63 | inline std::string generic_error_category::message( int ev ) const |
92f5a8d4 | 64 | { |
20effc67 | 65 | return generic_error_category_message( ev ); |
92f5a8d4 TL |
66 | } |
67 | ||
20effc67 | 68 | } // namespace detail |
92f5a8d4 | 69 | |
20effc67 | 70 | // generic_category() |
92f5a8d4 | 71 | |
20effc67 | 72 | #if defined(BOOST_SYSTEM_HAS_CONSTEXPR) |
92f5a8d4 | 73 | |
20effc67 | 74 | namespace detail |
92f5a8d4 | 75 | { |
92f5a8d4 | 76 | |
20effc67 | 77 | template<class T> struct BOOST_SYMBOL_VISIBLE generic_cat_holder |
92f5a8d4 | 78 | { |
20effc67 TL |
79 | static constexpr generic_error_category instance{}; |
80 | }; | |
92f5a8d4 | 81 | |
20effc67 TL |
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 | |
92f5a8d4 | 86 | |
20effc67 | 87 | } // namespace detail |
92f5a8d4 | 88 | |
20effc67 TL |
89 | constexpr error_category const & generic_category() BOOST_NOEXCEPT |
90 | { | |
91 | return detail::generic_cat_holder<void>::instance; | |
92 | } | |
92f5a8d4 | 93 | |
20effc67 | 94 | #else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR) |
92f5a8d4 | 95 | |
20effc67 TL |
96 | #if !defined(__SUNPRO_CC) // trailing __global is not supported |
97 | inline error_category const & generic_category() BOOST_NOEXCEPT BOOST_SYMBOL_VISIBLE; | |
98 | #endif | |
99 | ||
100 | inline error_category const & generic_category() BOOST_NOEXCEPT | |
101 | { | |
102 | static const detail::generic_error_category instance; | |
103 | return instance; | |
92f5a8d4 TL |
104 | } |
105 | ||
20effc67 | 106 | #endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR) |
92f5a8d4 | 107 | |
20effc67 | 108 | // deprecated synonyms |
92f5a8d4 | 109 | |
20effc67 TL |
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 | |
92f5a8d4 TL |
118 | |
119 | } // namespace system | |
120 | ||
121 | } // namespace boost | |
20effc67 TL |
122 | |
123 | #endif // #ifndef BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_HPP_INCLUDED |