forked from boostorg/system
Move failed_impl into error_category.hpp
This commit is contained in:
@ -27,21 +27,30 @@ namespace boost
|
|||||||
namespace system
|
namespace system
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class error_category;
|
||||||
class error_code;
|
class error_code;
|
||||||
class error_condition;
|
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 )
|
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::size_t hash_value( error_code const & ec );
|
|
||||||
|
|
||||||
class BOOST_SYMBOL_VISIBLE error_category
|
class BOOST_SYMBOL_VISIBLE error_category
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend std::size_t hash_value( error_code const & ec );
|
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)
|
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||||
public:
|
public:
|
||||||
@ -97,7 +106,10 @@ public:
|
|||||||
virtual std::string message( int ev ) const = 0;
|
virtual std::string message( int ev ) const = 0;
|
||||||
virtual char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT;
|
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
|
BOOST_SYSTEM_CONSTEXPR bool operator==( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
@ -140,6 +152,26 @@ public:
|
|||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#endif
|
#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 system
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
@ -36,10 +36,8 @@ class BOOST_SYMBOL_VISIBLE generic_error_category: public error_category
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// clang++ 3.8 and below: initialization of const object
|
|
||||||
// requires a user-provided default constructor
|
|
||||||
BOOST_SYSTEM_CONSTEXPR generic_error_category() BOOST_NOEXCEPT:
|
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:
|
public:
|
||||||
|
|
||||||
BOOST_SYSTEM_CONSTEXPR system_error_category() BOOST_NOEXCEPT:
|
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
|
#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
|
// class error_condition
|
||||||
|
|
||||||
// error_conditions are portable, error_codes are system or library specific
|
// 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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool error_category::failed( int ev ) const BOOST_NOEXCEPT
|
|
||||||
{
|
|
||||||
return ev != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace system
|
} // namespace system
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
Reference in New Issue
Block a user