mirror of
https://github.com/boostorg/system.git
synced 2025-07-29 20:17:13 +02:00
Move failed_impl into error_category.hpp
This commit is contained in:
@ -27,21 +27,30 @@ namespace boost
|
||||
namespace system
|
||||
{
|
||||
|
||||
class error_category;
|
||||
class error_code;
|
||||
class error_condition;
|
||||
|
||||
std::size_t hash_value( error_code const & ec );
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool failed_impl( int ev, error_category const & cat );
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#endif
|
||||
|
||||
std::size_t hash_value( error_code const & ec );
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE error_category
|
||||
{
|
||||
private:
|
||||
|
||||
friend std::size_t hash_value( error_code const & ec );
|
||||
friend BOOST_SYSTEM_CONSTEXPR bool detail::failed_impl( int ev, error_category const & cat );
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
public:
|
||||
@ -97,7 +106,10 @@ public:
|
||||
virtual std::string message( int ev ) const = 0;
|
||||
virtual char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT;
|
||||
|
||||
virtual bool failed( int ev ) const BOOST_NOEXCEPT;
|
||||
virtual bool failed( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return ev != 0;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator==( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||
{
|
||||
@ -140,6 +152,26 @@ public:
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
static const boost::ulong_long_type generic_category_id = ( boost::ulong_long_type( 0xB2AB117A ) << 32 ) + 0x257EDF0D;
|
||||
static const boost::ulong_long_type system_category_id = ( boost::ulong_long_type( 0x8FAFD21E ) << 32 ) + 0x25C5E09B;
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool failed_impl( int ev, error_category const & cat )
|
||||
{
|
||||
if( cat.id_ == system_category_id || cat.id_ == generic_category_id )
|
||||
{
|
||||
return ev != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cat.failed( ev );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
@ -36,10 +36,8 @@ class BOOST_SYMBOL_VISIBLE generic_error_category: public error_category
|
||||
{
|
||||
public:
|
||||
|
||||
// clang++ 3.8 and below: initialization of const object
|
||||
// requires a user-provided default constructor
|
||||
BOOST_SYSTEM_CONSTEXPR generic_error_category() BOOST_NOEXCEPT:
|
||||
error_category( ( boost::ulong_long_type( 0xB2AB117A ) << 32 ) + 0x257EDF0D )
|
||||
error_category( detail::generic_category_id )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ class BOOST_SYMBOL_VISIBLE system_error_category: public error_category
|
||||
public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR system_error_category() BOOST_NOEXCEPT:
|
||||
error_category( ( boost::ulong_long_type( 0x8FAFD21E ) << 32 ) + 0x25C5E09B )
|
||||
error_category( detail::system_category_id )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -109,36 +109,6 @@ static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED = system_catego
|
||||
|
||||
#endif
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// failed_impl
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
inline bool failed_impl( int ev, error_category const & cat )
|
||||
{
|
||||
return cat.failed( ev );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool failed_impl( int ev, error_category const & cat )
|
||||
{
|
||||
if( cat == system_category() || cat == generic_category() )
|
||||
{
|
||||
return ev != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cat.failed( ev );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// class error_condition
|
||||
|
||||
// error_conditions are portable, error_codes are system or library specific
|
||||
@ -602,11 +572,6 @@ inline char const * error_category::message( int ev, char * buffer, std::size_t
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool error_category::failed( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return ev != 0;
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
Reference in New Issue
Block a user