mirror of
https://github.com/boostorg/system.git
synced 2025-07-29 20:17:13 +02:00
Extract error_category implementation into its own header
This commit is contained in:
95
include/boost/system/detail/error_category_impl.hpp
Normal file
95
include/boost/system/detail/error_category_impl.hpp
Normal file
@ -0,0 +1,95 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_IMPL_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_IMPL_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2006, 2007
|
||||
// Copyright Christoper Kohlhoff 2007
|
||||
// Copyright Peter Dimov 2017, 2018
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See library home page at http://www.boost.org/libs/system
|
||||
|
||||
#include <boost/system/detail/error_category.hpp>
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/detail/error_code.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
// error_category default implementation
|
||||
|
||||
inline error_condition error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return error_condition( ev, *this );
|
||||
}
|
||||
|
||||
inline bool error_category::equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return default_error_condition( code ) == condition;
|
||||
}
|
||||
|
||||
inline bool error_category::equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return *this == code.category() && code.value() == condition;
|
||||
}
|
||||
|
||||
inline char const * error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( len == 0 )
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
if( len == 1 )
|
||||
{
|
||||
buffer[0] = 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
try
|
||||
#endif
|
||||
{
|
||||
std::string m = this->message( ev );
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable: 4996 )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic push
|
||||
# if __has_warning("-Wdeprecated-declarations")
|
||||
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
# endif
|
||||
# endif
|
||||
|
||||
std::strncpy( buffer, m.c_str(), len - 1 );
|
||||
buffer[ len-1 ] = 0;
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( pop )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic pop
|
||||
# endif
|
||||
|
||||
return buffer;
|
||||
}
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
catch( ... )
|
||||
{
|
||||
return "Message text unavailable";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_IMPL_HPP_INCLUDED
|
@ -20,6 +20,7 @@
|
||||
#include <boost/system/detail/error_condition.hpp>
|
||||
#include <boost/system/detail/error_code.hpp>
|
||||
#include <boost/system/detail/throws.hpp>
|
||||
#include <boost/system/detail/error_category_impl.hpp>
|
||||
#include <boost/system/api_config.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
@ -93,71 +94,6 @@ BOOST_SYSTEM_CONSTEXPR inline error_condition make_error_condition( errc_t e ) B
|
||||
|
||||
} // namespace errc
|
||||
|
||||
// error_category default implementation
|
||||
|
||||
inline error_condition error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return error_condition( ev, *this );
|
||||
}
|
||||
|
||||
inline bool error_category::equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return default_error_condition( code ) == condition;
|
||||
}
|
||||
|
||||
inline bool error_category::equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return *this == code.category() && code.value() == condition;
|
||||
}
|
||||
|
||||
inline char const * error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( len == 0 )
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
if( len == 1 )
|
||||
{
|
||||
buffer[0] = 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
try
|
||||
#endif
|
||||
{
|
||||
std::string m = this->message( ev );
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable: 4996 )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic push
|
||||
# if __has_warning("-Wdeprecated-declarations")
|
||||
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
# endif
|
||||
# endif
|
||||
|
||||
std::strncpy( buffer, m.c_str(), len - 1 );
|
||||
buffer[ len-1 ] = 0;
|
||||
|
||||
# if defined( BOOST_MSVC )
|
||||
# pragma warning( pop )
|
||||
# elif defined(__clang__) && defined(__has_warning)
|
||||
# pragma clang diagnostic pop
|
||||
# endif
|
||||
|
||||
return buffer;
|
||||
}
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
catch( ... )
|
||||
{
|
||||
return "Message text unavailable";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
Reference in New Issue
Block a user