| 1 | #ifndef BOOST_SYSTEM_DETAIL_INTEROP_CATEGORY_HPP_INCLUDED |
| 2 | #define BOOST_SYSTEM_DETAIL_INTEROP_CATEGORY_HPP_INCLUDED |
| 3 | |
| 4 | // Copyright Beman Dawes 2006, 2007 |
| 5 | // Copyright Christoper Kohlhoff 2007 |
| 6 | // Copyright Peter Dimov 2017, 2018, 2021 |
| 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/snprintf.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 | // interop_error_category, used for std::error_code |
| 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 interop_error_category: public error_category |
| 35 | { |
| 36 | public: |
| 37 | |
| 38 | BOOST_SYSTEM_CONSTEXPR interop_error_category() noexcept: |
| 39 | error_category( detail::interop_category_id ) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | const char * name() const noexcept BOOST_OVERRIDE |
| 44 | { |
| 45 | return "std:unknown" ; |
| 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 | inline char const * interop_error_category::message( int ev, char * buffer, std::size_t len ) const noexcept |
| 57 | { |
| 58 | detail::snprintf( s: buffer, maxlen: len, format: "Unknown interop error %d" , ev ); |
| 59 | return buffer; |
| 60 | } |
| 61 | |
| 62 | inline std::string interop_error_category::message( int ev ) const |
| 63 | { |
| 64 | char buffer[ 48 ]; |
| 65 | return message( ev, buffer, len: sizeof( buffer ) ); |
| 66 | } |
| 67 | |
| 68 | // interop_category() |
| 69 | |
| 70 | #if defined(BOOST_SYSTEM_HAS_CONSTEXPR) |
| 71 | |
| 72 | template<class T> struct BOOST_SYMBOL_VISIBLE interop_cat_holder |
| 73 | { |
| 74 | static constexpr interop_error_category instance{}; |
| 75 | }; |
| 76 | |
| 77 | // Before C++17 it was mandatory to redeclare all static constexpr |
| 78 | #if defined(BOOST_NO_CXX17_INLINE_VARIABLES) |
| 79 | template<class T> constexpr interop_error_category interop_cat_holder<T>::instance; |
| 80 | #endif |
| 81 | |
| 82 | constexpr error_category const & interop_category() noexcept |
| 83 | { |
| 84 | return interop_cat_holder<void>::instance; |
| 85 | } |
| 86 | |
| 87 | #else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR) |
| 88 | |
| 89 | #if !defined(__SUNPRO_CC) // trailing __global is not supported |
| 90 | inline error_category const & interop_category() noexcept BOOST_SYMBOL_VISIBLE; |
| 91 | #endif |
| 92 | |
| 93 | inline error_category const & interop_category() noexcept |
| 94 | { |
| 95 | static const detail::interop_error_category instance; |
| 96 | return instance; |
| 97 | } |
| 98 | |
| 99 | #endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR) |
| 100 | |
| 101 | } // namespace detail |
| 102 | |
| 103 | } // namespace system |
| 104 | |
| 105 | } // namespace boost |
| 106 | |
| 107 | #endif // #ifndef BOOST_SYSTEM_DETAIL_INTEROP_CATEGORY_HPP_INCLUDED |
| 108 | |