forked from boostorg/system
Make Boost.System header-only
This commit is contained in:
@ -1,42 +1,24 @@
|
||||
// boost/system/api_config.hpp -------------------------------------------------------//
|
||||
#ifndef BOOST_SYSTEM_API_CONFIG_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_API_CONFIG_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2003, 2006, 2010
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
// See http://www.boost.org/libs/system for documentation.
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
// Boost.System calls operating system API functions to implement system error category
|
||||
// functions. Usually there is no question as to which API is to be used.
|
||||
// Copyright Beman Dawes 2003, 2006, 2010
|
||||
// Copyright 2018 Peter Dimov
|
||||
//
|
||||
// In the case of MinGW or Cygwin/MinGW, however, both POSIX and Windows API's are
|
||||
// available. Chaos ensues if other code thinks one is in use when Boost.System was
|
||||
// actually built with the other. This header centralizes the API choice and prevents
|
||||
// user definition of API macros, thus elminating the possibility of mismatches and the
|
||||
// need to test configurations with little or no practical value.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://www.boost.org/libs/system for documentation.
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// This header is no longer used by Boost.System.
|
||||
// Its use is discouraged and it will be deprecated.
|
||||
|
||||
#ifndef BOOST_SYSTEM_API_CONFIG_HPP
|
||||
#define BOOST_SYSTEM_API_CONFIG_HPP
|
||||
// Definition of BOOST_*_API retained for compatibility.
|
||||
|
||||
# if defined(BOOST_POSIX_API) || defined(BOOST_WINDOWS_API)
|
||||
# error user defined BOOST_POSIX_API or BOOST_WINDOWS_API not supported
|
||||
# endif
|
||||
|
||||
// BOOST_POSIX_API or BOOST_WINDOWS_API specify which API to use
|
||||
// Cygwin/MinGW does not predefine _WIN32.
|
||||
// Standalone MinGW and all other known Windows compilers do predefine _WIN32
|
||||
// Compilers that predefine _WIN32 or __MINGW32__ do so for Windows 64-bit builds too.
|
||||
|
||||
# if defined(_WIN32) || defined(__CYGWIN__) // Windows default, including MinGW and Cygwin
|
||||
# define BOOST_WINDOWS_API
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
// Windows default, including MinGW and Cygwin
|
||||
# define BOOST_WINDOWS_API
|
||||
# else
|
||||
# define BOOST_POSIX_API
|
||||
# endif
|
||||
# define BOOST_POSIX_API
|
||||
#endif
|
||||
|
||||
#endif // BOOST_SYSTEM_API_CONFIG_HPP
|
||||
#endif // BOOST_SYSTEM_API_CONFIG_HPP_INCLUDED
|
||||
|
@ -1,40 +1,23 @@
|
||||
// boost/system/config.hpp -----------------------------------------------------------//
|
||||
#ifndef BOOST_SYSTEM_CONFIG_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_CONFIG_HPP_INCLUDED
|
||||
|
||||
// Copyright Beman Dawes 2003, 2006
|
||||
// Copyright Beman Dawes 2003, 2006
|
||||
// Copyright 2018 Peter Dimov
|
||||
//
|
||||
// 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 http://www.boost.org/libs/system for documentation.
|
||||
|
||||
// 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 http://www.boost.org/libs/system for documentation.
|
||||
|
||||
#ifndef BOOST_SYSTEM_CONFIG_HPP
|
||||
#define BOOST_SYSTEM_CONFIG_HPP
|
||||
// This header is no longer used by Boost.System.
|
||||
// Its use is discouraged and it will be deprecated.
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/predef/platform.h>
|
||||
#include <boost/system/api_config.hpp> // for BOOST_POSIX_API or BOOST_WINDOWS_API
|
||||
|
||||
// This header implements separate compilation features as described in
|
||||
// http://www.boost.org/more/separate_compilation.html
|
||||
// Included for compatibility. Not used.
|
||||
#include <boost/system/api_config.hpp>
|
||||
|
||||
// normalize macros ------------------------------------------------------------------//
|
||||
|
||||
#if !defined(BOOST_SYSTEM_DYN_LINK) && !defined(BOOST_SYSTEM_STATIC_LINK) \
|
||||
&& !defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_ALL_STATIC_LINK)
|
||||
# define BOOST_SYSTEM_STATIC_LINK
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_SYSTEM_DYN_LINK)
|
||||
# define BOOST_SYSTEM_DYN_LINK
|
||||
#elif defined(BOOST_ALL_STATIC_LINK) && !defined(BOOST_SYSTEM_STATIC_LINK)
|
||||
# define BOOST_SYSTEM_STATIC_LINK
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_SYSTEM_DYN_LINK) && defined(BOOST_SYSTEM_STATIC_LINK)
|
||||
# error Must not define both BOOST_SYSTEM_DYN_LINK and BOOST_SYSTEM_STATIC_LINK
|
||||
#endif
|
||||
|
||||
// enable dynamic or static linking as requested --------------------------------------//
|
||||
// Definition of BOOST_SYSTEM_DECL retained for compatibility.
|
||||
|
||||
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_SYSTEM_DYN_LINK)
|
||||
# if defined(BOOST_SYSTEM_SOURCE)
|
||||
@ -46,25 +29,4 @@
|
||||
# define BOOST_SYSTEM_DECL
|
||||
#endif
|
||||
|
||||
// enable automatic library variant selection ----------------------------------------//
|
||||
|
||||
#if !defined(BOOST_SYSTEM_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_SYSTEM_NO_LIB)
|
||||
//
|
||||
// Set the name of our library, this will get undef'ed by auto_link.hpp
|
||||
// once it's done with it:
|
||||
//
|
||||
#define BOOST_LIB_NAME boost_system
|
||||
//
|
||||
// If we're importing code from a dll, then tell auto_link.hpp about it:
|
||||
//
|
||||
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_SYSTEM_DYN_LINK)
|
||||
# define BOOST_DYN_LINK
|
||||
#endif
|
||||
//
|
||||
// And include the header that does the work:
|
||||
//
|
||||
#include <boost/config/auto_link.hpp>
|
||||
#endif // auto-linking disabled
|
||||
|
||||
#endif // BOOST_SYSTEM_CONFIG_HPP
|
||||
|
||||
#endif // BOOST_SYSTEM_CONFIG_HPP_INCLUDED
|
||||
|
74
include/boost/system/detail/config.hpp
Normal file
74
include/boost/system/detail/config.hpp
Normal file
@ -0,0 +1,74 @@
|
||||
#ifndef BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED
|
||||
|
||||
// Copyright 2018 Peter Dimov
|
||||
//
|
||||
// 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 http://www.boost.org/libs/system for documentation.
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
// BOOST_SYSTEM_HAS_SYSTEM_ERROR
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR)
|
||||
# define BOOST_SYSTEM_HAS_SYSTEM_ERROR
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1700
|
||||
// msvc-10.0 has no two-argument map::emplace
|
||||
# undef BOOST_SYSTEM_HAS_SYSTEM_ERROR
|
||||
#endif
|
||||
|
||||
// BOOST_SYSTEM_NOEXCEPT
|
||||
// Retained for backward compatibility only
|
||||
|
||||
#define BOOST_SYSTEM_NOEXCEPT BOOST_NOEXCEPT
|
||||
|
||||
// BOOST_SYSTEM_HAS_CONSTEXPR
|
||||
|
||||
#if !defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
# define BOOST_SYSTEM_HAS_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ == 7 && __GNUC_MINOR__ < 4) && __cplusplus >= 201700L
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83835
|
||||
# undef BOOST_SYSTEM_HAS_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) && defined(_MSC_VER) && defined(_CPPLIB_VER)
|
||||
// Clang on Windows with MSVC headers, the constructor of std::error_category
|
||||
// is not constexpr at least up to VS2017 15.7.x (_MSVC_STL_UPDATE 201803)
|
||||
# undef BOOST_SYSTEM_HAS_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) && defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 40900
|
||||
// The constructor of std::error_category is not constexpr in libstdc++ 4.8
|
||||
# undef BOOST_SYSTEM_HAS_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
# define BOOST_SYSTEM_CONSTEXPR constexpr
|
||||
#else
|
||||
# define BOOST_SYSTEM_CONSTEXPR
|
||||
#endif
|
||||
|
||||
// BOOST_SYSTEM_REQUIRE_CONST_INIT
|
||||
|
||||
#define BOOST_SYSTEM_REQUIRE_CONST_INIT
|
||||
|
||||
#if defined(__has_cpp_attribute)
|
||||
#if __has_cpp_attribute(clang::require_constant_initialization)
|
||||
# undef BOOST_SYSTEM_REQUIRE_CONST_INIT
|
||||
# define BOOST_SYSTEM_REQUIRE_CONST_INIT [[clang::require_constant_initialization]]
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// BOOST_SYSTEM_WIN32
|
||||
|
||||
#if defined( _WIN32 ) || defined( __CYGWIN__ )
|
||||
# define BOOST_SYSTEM_WIN32
|
||||
#endif
|
||||
|
||||
#endif // BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED
|
131
include/boost/system/detail/std_interoperability.hpp
Normal file
131
include/boost/system/detail/std_interoperability.hpp
Normal file
@ -0,0 +1,131 @@
|
||||
// Support for interoperability between Boost.System and <system_error>
|
||||
//
|
||||
// Copyright 2018 Peter Dimov
|
||||
//
|
||||
// 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 <system_error>
|
||||
#include <map>
|
||||
|
||||
//
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class std_category: public std::error_category
|
||||
{
|
||||
private:
|
||||
|
||||
boost::system::error_category const * pc_;
|
||||
|
||||
public:
|
||||
|
||||
std_category( boost::system::error_category const * pc ): pc_( pc )
|
||||
{
|
||||
}
|
||||
|
||||
virtual const char * name() const BOOST_NOEXCEPT
|
||||
{
|
||||
return pc_->name();
|
||||
}
|
||||
|
||||
virtual std::string message( int ev ) const
|
||||
{
|
||||
return pc_->message( ev );
|
||||
}
|
||||
|
||||
virtual std::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return pc_->default_error_condition( ev );
|
||||
}
|
||||
|
||||
virtual bool equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT;
|
||||
virtual bool equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT;
|
||||
};
|
||||
|
||||
inline std::error_category const & to_std_category( boost::system::error_category const & cat )
|
||||
{
|
||||
typedef std::map<boost::system::error_category const *, std_category> map_type;
|
||||
|
||||
static map_type map_;
|
||||
|
||||
std::pair<map_type::iterator, bool> p = map_.emplace( &cat, &cat );
|
||||
|
||||
return p.first->second;
|
||||
}
|
||||
|
||||
inline bool std_category::equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( condition.category() == *this )
|
||||
{
|
||||
boost::system::error_condition bn( condition.value(), *pc_ );
|
||||
return pc_->equivalent( code, bn );
|
||||
}
|
||||
else if( condition.category() == std::generic_category() || condition.category() == boost::system::generic_category() )
|
||||
{
|
||||
boost::system::error_condition bn( condition.value(), boost::system::generic_category() );
|
||||
return pc_->equivalent( code, bn );
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_RTTI
|
||||
|
||||
else if( std_category const* pc2 = dynamic_cast< std_category const* >( &condition.category() ) )
|
||||
{
|
||||
boost::system::error_condition bn( condition.value(), *pc2->pc_ );
|
||||
return pc_->equivalent( code, bn );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
else
|
||||
{
|
||||
return default_error_condition( code ) == condition;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool std_category::equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( code.category() == *this )
|
||||
{
|
||||
boost::system::error_code bc( code.value(), *pc_ );
|
||||
return pc_->equivalent( bc, condition );
|
||||
}
|
||||
else if( code.category() == std::generic_category() || code.category() == boost::system::generic_category() )
|
||||
{
|
||||
boost::system::error_code bc( code.value(), boost::system::generic_category() );
|
||||
return pc_->equivalent( bc, condition );
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_RTTI
|
||||
|
||||
else if( std_category const* pc2 = dynamic_cast< std_category const* >( &code.category() ) )
|
||||
{
|
||||
boost::system::error_code bc( code.value(), *pc2->pc_ );
|
||||
return pc_->equivalent( bc, condition );
|
||||
}
|
||||
#endif
|
||||
|
||||
else if( *pc_ == boost::system::generic_category() )
|
||||
{
|
||||
return std::generic_category().equivalent( code, condition );
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
204
include/boost/system/detail/system_category_win32.hpp
Normal file
204
include/boost/system/detail/system_category_win32.hpp
Normal file
@ -0,0 +1,204 @@
|
||||
// Windows implementation of system_error_category
|
||||
|
||||
// Copyright Beman Dawes 2002, 2006
|
||||
// Copyright (c) Microsoft Corporation 2014
|
||||
// Copyright 2018 Peter Dimov
|
||||
|
||||
// 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/winapi/error_codes.hpp>
|
||||
#include <boost/winapi/error_handling.hpp>
|
||||
#include <boost/winapi/character_code_conversion.hpp>
|
||||
#include <vector>
|
||||
|
||||
//
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline std::string system_category_message_win32( int ev )
|
||||
{
|
||||
using namespace boost::winapi;
|
||||
|
||||
std::wstring buf( 128, wchar_t() );
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
DWORD_ retval = boost::winapi::FormatMessageW(
|
||||
FORMAT_MESSAGE_FROM_SYSTEM_ | FORMAT_MESSAGE_IGNORE_INSERTS_,
|
||||
NULL,
|
||||
ev,
|
||||
MAKELANGID_( LANG_NEUTRAL_, SUBLANG_DEFAULT_ ), // Default language
|
||||
&buf[0],
|
||||
static_cast<DWORD_>( buf.size() ),
|
||||
NULL
|
||||
);
|
||||
|
||||
if( retval > 0 )
|
||||
{
|
||||
buf.resize(retval);
|
||||
break;
|
||||
}
|
||||
else if( boost::winapi::GetLastError() != ERROR_INSUFFICIENT_BUFFER_ )
|
||||
{
|
||||
return "Unknown error";
|
||||
}
|
||||
else
|
||||
{
|
||||
buf.resize( buf.size() + buf.size() / 2 );
|
||||
}
|
||||
}
|
||||
|
||||
int num_chars = static_cast<int>( buf.size() + 1 ) * 2;
|
||||
|
||||
boost::winapi::LPSTR_ narrow_buffer =
|
||||
#if defined(__GNUC__)
|
||||
(boost::winapi::LPSTR_)__builtin_alloca( num_chars );
|
||||
#else
|
||||
(boost::winapi::LPSTR_)_alloca( num_chars );
|
||||
#endif
|
||||
|
||||
if( boost::winapi::WideCharToMultiByte( CP_ACP_, 0, buf.c_str(), -1, narrow_buffer, num_chars, NULL, NULL ) == 0 )
|
||||
{
|
||||
return "Unknown error";
|
||||
}
|
||||
|
||||
std::string str( narrow_buffer );
|
||||
|
||||
while( !str.empty() && ( str[ str.size() - 1 ] == '\n' || str[ str.size() - 1 ] == '\r' ) )
|
||||
{
|
||||
str.erase( str.size() - 1 );
|
||||
}
|
||||
|
||||
if( str.size() && str[ str.size() - 1 ] == '.' )
|
||||
{
|
||||
str.erase( str.size() - 1 );
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
inline error_condition system_category_default_error_condition_win32( int ev ) BOOST_NOEXCEPT
|
||||
{
|
||||
// When using the Windows Runtime, most system errors are reported as HRESULTs.
|
||||
// We want to map the common Win32 errors to their equivalent error condition,
|
||||
// whether or not they are reported via an HRESULT.
|
||||
|
||||
#define BOOST_SYSTEM_FAILED(hr) ((hr) < 0)
|
||||
#define BOOST_SYSTEM_HRESULT_FACILITY(hr) (((hr) >> 16) & 0x1fff)
|
||||
#define BOOST_SYSTEM_HRESULT_CODE(hr) ((hr) & 0xFFFF)
|
||||
#define BOOST_SYSTEM_FACILITY_WIN32 7
|
||||
|
||||
if( BOOST_SYSTEM_FAILED( ev ) && BOOST_SYSTEM_HRESULT_FACILITY( ev ) == BOOST_SYSTEM_FACILITY_WIN32 )
|
||||
{
|
||||
ev = BOOST_SYSTEM_HRESULT_CODE( ev );
|
||||
}
|
||||
|
||||
#undef BOOST_SYSTEM_FAILED
|
||||
#undef BOOST_SYSTEM_HRESULT_FACILITY
|
||||
#undef BOOST_SYSTEM_HRESULT_CODE
|
||||
#undef BOOST_SYSTEM_FACILITY_WIN32
|
||||
|
||||
using namespace boost::winapi;
|
||||
using namespace errc;
|
||||
|
||||
// Windows system -> posix_errno decode table
|
||||
// see WinError.h comments for descriptions of errors
|
||||
|
||||
switch ( ev )
|
||||
{
|
||||
case 0: return make_error_condition( success );
|
||||
|
||||
case ERROR_ACCESS_DENIED_: return make_error_condition( permission_denied );
|
||||
case ERROR_ALREADY_EXISTS_: return make_error_condition( file_exists );
|
||||
case ERROR_BAD_UNIT_: return make_error_condition( no_such_device );
|
||||
case ERROR_BUFFER_OVERFLOW_: return make_error_condition( filename_too_long );
|
||||
case ERROR_BUSY_: return make_error_condition( device_or_resource_busy );
|
||||
case ERROR_BUSY_DRIVE_: return make_error_condition( device_or_resource_busy );
|
||||
case ERROR_CANNOT_MAKE_: return make_error_condition( permission_denied );
|
||||
case ERROR_CANTOPEN_: return make_error_condition( io_error );
|
||||
case ERROR_CANTREAD_: return make_error_condition( io_error );
|
||||
case ERROR_CANTWRITE_: return make_error_condition( io_error );
|
||||
case ERROR_CURRENT_DIRECTORY_: return make_error_condition( permission_denied );
|
||||
case ERROR_DEV_NOT_EXIST_: return make_error_condition( no_such_device );
|
||||
case ERROR_DEVICE_IN_USE_: return make_error_condition( device_or_resource_busy );
|
||||
case ERROR_DIR_NOT_EMPTY_: return make_error_condition( directory_not_empty );
|
||||
case ERROR_DIRECTORY_: return make_error_condition( invalid_argument ); // WinError.h: "The directory name is invalid"
|
||||
case ERROR_DISK_FULL_: return make_error_condition( no_space_on_device );
|
||||
case ERROR_FILE_EXISTS_: return make_error_condition( file_exists );
|
||||
case ERROR_FILE_NOT_FOUND_: return make_error_condition( no_such_file_or_directory );
|
||||
case ERROR_HANDLE_DISK_FULL_: return make_error_condition( no_space_on_device );
|
||||
case ERROR_INVALID_ACCESS_: return make_error_condition( permission_denied );
|
||||
case ERROR_INVALID_DRIVE_: return make_error_condition( no_such_device );
|
||||
case ERROR_INVALID_FUNCTION_: return make_error_condition( function_not_supported );
|
||||
case ERROR_INVALID_HANDLE_: return make_error_condition( invalid_argument );
|
||||
case ERROR_INVALID_NAME_: return make_error_condition( invalid_argument );
|
||||
case ERROR_LOCK_VIOLATION_: return make_error_condition( no_lock_available );
|
||||
case ERROR_LOCKED_: return make_error_condition( no_lock_available );
|
||||
case ERROR_NEGATIVE_SEEK_: return make_error_condition( invalid_argument );
|
||||
case ERROR_NOACCESS_: return make_error_condition( permission_denied );
|
||||
case ERROR_NOT_ENOUGH_MEMORY_: return make_error_condition( not_enough_memory );
|
||||
case ERROR_NOT_READY_: return make_error_condition( resource_unavailable_try_again );
|
||||
case ERROR_NOT_SAME_DEVICE_: return make_error_condition( cross_device_link );
|
||||
case ERROR_OPEN_FAILED_: return make_error_condition( io_error );
|
||||
case ERROR_OPEN_FILES_: return make_error_condition( device_or_resource_busy );
|
||||
case ERROR_OPERATION_ABORTED_: return make_error_condition( operation_canceled );
|
||||
case ERROR_OUTOFMEMORY_: return make_error_condition( not_enough_memory );
|
||||
case ERROR_PATH_NOT_FOUND_: return make_error_condition( no_such_file_or_directory );
|
||||
case ERROR_READ_FAULT_: return make_error_condition( io_error );
|
||||
case ERROR_RETRY_: return make_error_condition( resource_unavailable_try_again );
|
||||
case ERROR_SEEK_: return make_error_condition( io_error );
|
||||
case ERROR_SHARING_VIOLATION_: return make_error_condition( permission_denied );
|
||||
case ERROR_TOO_MANY_OPEN_FILES_: return make_error_condition( too_many_files_open );
|
||||
case ERROR_WRITE_FAULT_: return make_error_condition( io_error );
|
||||
case ERROR_WRITE_PROTECT_: return make_error_condition( permission_denied );
|
||||
case WSAEACCES_: return make_error_condition( permission_denied );
|
||||
case WSAEADDRINUSE_: return make_error_condition( address_in_use );
|
||||
case WSAEADDRNOTAVAIL_: return make_error_condition( address_not_available );
|
||||
case WSAEAFNOSUPPORT_: return make_error_condition( address_family_not_supported );
|
||||
case WSAEALREADY_: return make_error_condition( connection_already_in_progress );
|
||||
case WSAEBADF_: return make_error_condition( bad_file_descriptor );
|
||||
case WSAECONNABORTED_: return make_error_condition( connection_aborted );
|
||||
case WSAECONNREFUSED_: return make_error_condition( connection_refused );
|
||||
case WSAECONNRESET_: return make_error_condition( connection_reset );
|
||||
case WSAEDESTADDRREQ_: return make_error_condition( destination_address_required );
|
||||
case WSAEFAULT_: return make_error_condition( bad_address );
|
||||
case WSAEHOSTUNREACH_: return make_error_condition( host_unreachable );
|
||||
case WSAEINPROGRESS_: return make_error_condition( operation_in_progress );
|
||||
case WSAEINTR_: return make_error_condition( interrupted );
|
||||
case WSAEINVAL_: return make_error_condition( invalid_argument );
|
||||
case WSAEISCONN_: return make_error_condition( already_connected );
|
||||
case WSAEMFILE_: return make_error_condition( too_many_files_open );
|
||||
case WSAEMSGSIZE_: return make_error_condition( message_size );
|
||||
case WSAENAMETOOLONG_: return make_error_condition( filename_too_long );
|
||||
case WSAENETDOWN_: return make_error_condition( network_down );
|
||||
case WSAENETRESET_: return make_error_condition( network_reset );
|
||||
case WSAENETUNREACH_: return make_error_condition( network_unreachable );
|
||||
case WSAENOBUFS_: return make_error_condition( no_buffer_space );
|
||||
case WSAENOPROTOOPT_: return make_error_condition( no_protocol_option );
|
||||
case WSAENOTCONN_: return make_error_condition( not_connected );
|
||||
case WSAENOTSOCK_: return make_error_condition( not_a_socket );
|
||||
case WSAEOPNOTSUPP_: return make_error_condition( operation_not_supported );
|
||||
case WSAEPROTONOSUPPORT_: return make_error_condition( protocol_not_supported );
|
||||
case WSAEPROTOTYPE_: return make_error_condition( wrong_protocol_type );
|
||||
case WSAETIMEDOUT_: return make_error_condition( timed_out );
|
||||
case WSAEWOULDBLOCK_: return make_error_condition( operation_would_block );
|
||||
|
||||
default: return error_condition( ev, system_category() );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
@ -1,63 +1,29 @@
|
||||
// boost/system/error_code.hpp -------------------------------------------------------//
|
||||
#ifndef BOOST_SYSTEM_ERROR_CODE_HPP_INCLUDED
|
||||
#define BOOST_SYSTEM_ERROR_CODE_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
|
||||
|
||||
#ifndef BOOST_SYSTEM_ERROR_CODE_HPP
|
||||
#define BOOST_SYSTEM_ERROR_CODE_HPP
|
||||
|
||||
#include <boost/system/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/system/detail/config.hpp>
|
||||
#include <boost/type_traits/enable_if.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <functional>
|
||||
#include <cstring>
|
||||
|
||||
// TODO: undef these macros if not already defined
|
||||
#include <boost/cerrno.hpp>
|
||||
|
||||
#if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API)
|
||||
# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR
|
||||
#include <system_error>
|
||||
#endif
|
||||
|
||||
#include <boost/config/abi_prefix.hpp> // must be the last #include
|
||||
|
||||
#if !defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
# define BOOST_SYSTEM_HAS_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ == 7 && __GNUC_MINOR__ < 4) && __cplusplus >= 201700L
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83835
|
||||
# undef BOOST_SYSTEM_HAS_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) && defined(_MSC_VER) && defined(_CPPLIB_VER)
|
||||
// Clang on Windows with MSVC headers, the constructor of std::error_category
|
||||
// is not constexpr at least up to VS2017 15.7.x (_MSVC_STL_UPDATE 201803)
|
||||
# undef BOOST_SYSTEM_HAS_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) && defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 40900
|
||||
// The constructor of std::error_category is not constexpr in libstdc++ 4.8
|
||||
# undef BOOST_SYSTEM_HAS_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
# define BOOST_SYSTEM_CONSTEXPR constexpr
|
||||
#else
|
||||
# define BOOST_SYSTEM_CONSTEXPR
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
# include <system_error>
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
@ -70,7 +36,7 @@ class error_code; // values defined by the operating system
|
||||
class error_condition; // portable generic values defined below, but ultimately
|
||||
// based on the POSIX standard
|
||||
|
||||
// "Concept" helpers -------------------------------------------------------------//
|
||||
// "Concept" helpers
|
||||
|
||||
template<class T> struct is_error_code_enum
|
||||
{
|
||||
@ -82,7 +48,7 @@ template<class T> struct is_error_condition_enum
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
// generic error_conditions ------------------------------------------------------//
|
||||
// Generic error_conditions
|
||||
|
||||
namespace errc
|
||||
{
|
||||
@ -184,141 +150,55 @@ template<> struct is_error_condition_enum<errc::errc_t>
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------//
|
||||
|
||||
// Operating system specific interfaces ------------------------------------------//
|
||||
|
||||
|
||||
// The interface is divided into general and system-specific portions to
|
||||
// meet these requirements:
|
||||
//
|
||||
// * Code calling an operating system API can create an error_code with
|
||||
// a single category (system_category), even for POSIX-like operating
|
||||
// systems that return some POSIX errno values and some native errno
|
||||
// values. This code should not have to pay the cost of distinguishing
|
||||
// between categories, since it is not yet known if that is needed.
|
||||
//
|
||||
// * Users wishing to write system-specific code should be given enums for
|
||||
// at least the common error cases.
|
||||
//
|
||||
// * System specific code should fail at compile time if moved to another
|
||||
// operating system.
|
||||
|
||||
// The system specific portions of the interface are located in headers
|
||||
// with names reflecting the operating system. For example,
|
||||
//
|
||||
// <boost/system/cygwin_error.hpp>
|
||||
// <boost/system/linux_error.hpp>
|
||||
// <boost/system/windows_error.hpp>
|
||||
//
|
||||
// These headers are effectively empty for compiles on operating systems
|
||||
// where they are not applicable.
|
||||
|
||||
// --------------------------------------------------------------------------------//
|
||||
// class error_category
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning( push )
|
||||
// 'this' : used in base member initializer list
|
||||
#pragma warning(disable: 4355)
|
||||
#pragma warning( disable: 4355 )
|
||||
#endif
|
||||
|
||||
// class error_category ------------------------------------------------//
|
||||
|
||||
class error_category: public noncopyable
|
||||
class error_category
|
||||
{
|
||||
#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR
|
||||
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
public:
|
||||
|
||||
error_category( error_category const & ) = delete;
|
||||
error_category& operator=( error_category const & ) = delete;
|
||||
|
||||
#else
|
||||
private:
|
||||
|
||||
error_category( error_category const & );
|
||||
error_category& operator=( error_category const & );
|
||||
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
class std_category: public std::error_category
|
||||
{
|
||||
private:
|
||||
boost::ulong_long_type id_;
|
||||
|
||||
boost::system::error_category const * pc_;
|
||||
protected:
|
||||
|
||||
public:
|
||||
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && !defined(BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS)
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR explicit std_category( boost::system::error_category const * pc ): pc_( pc )
|
||||
{
|
||||
}
|
||||
|
||||
virtual const char * name() const BOOST_NOEXCEPT
|
||||
{
|
||||
return pc_->name();
|
||||
}
|
||||
|
||||
virtual std::string message( int ev ) const
|
||||
{
|
||||
return pc_->message( ev );
|
||||
}
|
||||
|
||||
virtual std::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT;
|
||||
|
||||
virtual bool equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT;
|
||||
virtual bool equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT;
|
||||
};
|
||||
|
||||
std_category std_cat_;
|
||||
|
||||
public:
|
||||
|
||||
operator std::error_category const & () const BOOST_NOEXCEPT
|
||||
{
|
||||
// do not map generic to std::generic on purpose; occasionally,
|
||||
// there are two std::generic categories in a program, which leads
|
||||
// to error codes/conditions mysteriously not being equal to themselves
|
||||
return std_cat_;
|
||||
}
|
||||
~error_category() = default;
|
||||
|
||||
#else
|
||||
|
||||
// to maintain ABI compatibility between 03 and 11,
|
||||
// define a class with the same layout
|
||||
|
||||
private:
|
||||
|
||||
class std_category
|
||||
{
|
||||
private:
|
||||
|
||||
boost::system::error_category const * pc_;
|
||||
|
||||
public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR explicit std_category( boost::system::error_category const * pc ): pc_( pc )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~std_category() {}
|
||||
|
||||
virtual const char * name() const BOOST_NOEXCEPT
|
||||
{
|
||||
return pc_->name();
|
||||
}
|
||||
|
||||
// we can't define message, because (1) it returns an std::string,
|
||||
// which can be different between 03 and 11, and (2) on mingw, there
|
||||
// are actually two `message` functions, not one, so it doesn't work
|
||||
// even if we do
|
||||
|
||||
// neither can we define default_error_condition or equivalent
|
||||
|
||||
// if these functions are called, it will crash, but that's still
|
||||
// better than the alternative of having the class layout change
|
||||
};
|
||||
|
||||
std_category std_cat_;
|
||||
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_NOEXCEPT: std_cat_( this )
|
||||
~error_category()
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~error_category()
|
||||
#endif
|
||||
|
||||
explicit BOOST_SYSTEM_CONSTEXPR error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id )
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_NOEXCEPT: id_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
@ -326,48 +206,63 @@ public:
|
||||
|
||||
virtual std::string message( int ev ) const = 0;
|
||||
|
||||
inline virtual error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT;
|
||||
inline virtual bool equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT;
|
||||
inline virtual bool equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT;
|
||||
virtual error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT;
|
||||
virtual bool equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT;
|
||||
virtual bool equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT;
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator==( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return rhs.id_ == 0? this == &rhs: id_ == rhs.id_;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!=( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return !( *this == rhs );
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator<( const error_category & rhs ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( id_ < rhs.id_ )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if( id_ > rhs.id_ )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( rhs.id_ != 0 )
|
||||
{
|
||||
return false; // equal
|
||||
}
|
||||
|
||||
return std::less<error_category const *>()( this, &rhs );
|
||||
}
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
operator std::error_category const & () const BOOST_NOEXCEPT;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool operator==( const error_category & lhs, const error_category & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return &lhs == &rhs;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_category & lhs, const error_category & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return &lhs != &rhs;
|
||||
}
|
||||
|
||||
inline bool operator<( const error_category & lhs, const error_category & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return std::less<const error_category*>()( &lhs, &rhs );
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
// predefined error categories ---------------------------------------------------//
|
||||
// predefined error categories
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#ifdef BOOST_ERROR_CODE_HEADER_ONLY
|
||||
# define BOOST_SYSTEM_DECL_
|
||||
#else
|
||||
# define BOOST_SYSTEM_DECL_ BOOST_SYSTEM_DECL
|
||||
#endif
|
||||
|
||||
class 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
|
||||
BOOST_SYSTEM_CONSTEXPR generic_error_category() BOOST_NOEXCEPT: error_category( 0xB2AB117A257EDF0Dull )
|
||||
{
|
||||
}
|
||||
|
||||
@ -376,14 +271,14 @@ public:
|
||||
return "generic";
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_DECL_ std::string message( int ev ) const;
|
||||
std::string message( int ev ) const;
|
||||
};
|
||||
|
||||
class system_error_category: public error_category
|
||||
{
|
||||
public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR system_error_category() BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR system_error_category() BOOST_NOEXCEPT: error_category( 0x8FAFD21E25C5E09Bull )
|
||||
{
|
||||
}
|
||||
|
||||
@ -392,120 +287,57 @@ public:
|
||||
return "system";
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_DECL_ std::string message( int ev ) const;
|
||||
BOOST_SYSTEM_DECL_ error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT;
|
||||
std::string message( int ev ) const;
|
||||
error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT;
|
||||
};
|
||||
|
||||
#undef BOOST_SYSTEM_DECL_
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#define BOOST_SYSTEM_REQUIRE_CONST_INIT
|
||||
// generic_category(), system_category()
|
||||
|
||||
#if defined(__has_cpp_attribute)
|
||||
#if __has_cpp_attribute(clang::require_constant_initialization)
|
||||
# undef BOOST_SYSTEM_REQUIRE_CONST_INIT
|
||||
# define BOOST_SYSTEM_REQUIRE_CONST_INIT [[clang::require_constant_initialization]]
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_ERROR_CODE_HEADER_ONLY)
|
||||
|
||||
# if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class T> struct cat_holder
|
||||
{
|
||||
static system_error_category system_category_instance;
|
||||
static generic_error_category generic_category_instance;
|
||||
BOOST_SYSTEM_REQUIRE_CONST_INIT static constexpr system_error_category system_category_instance{};
|
||||
BOOST_SYSTEM_REQUIRE_CONST_INIT static constexpr generic_error_category generic_category_instance{};
|
||||
};
|
||||
|
||||
template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT system_error_category cat_holder<T>::system_category_instance;
|
||||
template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT generic_error_category cat_holder<T>::generic_category_instance;
|
||||
template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT constexpr system_error_category cat_holder<T>::system_category_instance;
|
||||
template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT constexpr generic_error_category cat_holder<T>::generic_category_instance;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
constexpr const error_category & system_category() BOOST_NOEXCEPT
|
||||
constexpr error_category const & system_category() BOOST_NOEXCEPT
|
||||
{
|
||||
return detail::cat_holder<void>::system_category_instance;
|
||||
}
|
||||
|
||||
constexpr const error_category & generic_category() BOOST_NOEXCEPT
|
||||
constexpr error_category const & generic_category() BOOST_NOEXCEPT
|
||||
{
|
||||
return detail::cat_holder<void>::generic_category_instance;
|
||||
}
|
||||
|
||||
# else
|
||||
#else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
inline const error_category & system_category() BOOST_NOEXCEPT
|
||||
inline error_category const & system_category() BOOST_NOEXCEPT
|
||||
{
|
||||
static const detail::system_error_category system_category_instance;
|
||||
return system_category_instance;
|
||||
}
|
||||
|
||||
inline const error_category & generic_category() BOOST_NOEXCEPT
|
||||
inline error_category const & generic_category() BOOST_NOEXCEPT
|
||||
{
|
||||
static const detail::generic_error_category generic_category_instance;
|
||||
return generic_category_instance;
|
||||
}
|
||||
|
||||
# endif
|
||||
#endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
#elif defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if defined(BOOST_SYSTEM_SOURCE)
|
||||
|
||||
// clang++ requires a strictly matching declaration
|
||||
BOOST_SYSTEM_DECL extern system_error_category system_category_instance;
|
||||
BOOST_SYSTEM_DECL extern generic_error_category generic_category_instance;
|
||||
|
||||
#else
|
||||
|
||||
extern system_error_category system_category_instance;
|
||||
extern generic_error_category generic_category_instance;
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
constexpr const error_category & system_category() BOOST_NOEXCEPT
|
||||
{
|
||||
return detail::system_category_instance;
|
||||
}
|
||||
|
||||
constexpr const error_category & generic_category() BOOST_NOEXCEPT
|
||||
{
|
||||
return detail::generic_category_instance;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
BOOST_SYSTEM_DECL const error_category & system_category_ncx() BOOST_NOEXCEPT;
|
||||
BOOST_SYSTEM_DECL const error_category & generic_category_ncx() BOOST_NOEXCEPT;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
inline const error_category & system_category() BOOST_NOEXCEPT
|
||||
{
|
||||
return detail::system_category_ncx();
|
||||
}
|
||||
|
||||
inline const error_category & generic_category() BOOST_NOEXCEPT
|
||||
{
|
||||
return detail::generic_category_ncx();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// deprecated synonyms ------------------------------------------------------------//
|
||||
// deprecated synonyms
|
||||
|
||||
#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
|
||||
|
||||
@ -518,12 +350,17 @@ static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED = system_catego
|
||||
|
||||
#endif
|
||||
|
||||
// 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
|
||||
|
||||
class error_condition
|
||||
{
|
||||
private:
|
||||
|
||||
int m_val;
|
||||
error_category const * m_cat;
|
||||
|
||||
public:
|
||||
|
||||
// constructors:
|
||||
@ -536,8 +373,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
template<class ErrorConditionEnum> error_condition( ErrorConditionEnum e,
|
||||
typename boost::enable_if_<is_error_condition_enum<ErrorConditionEnum>::value>::type* = 0) BOOST_NOEXCEPT
|
||||
template<class ErrorConditionEnum> BOOST_SYSTEM_CONSTEXPR error_condition( ErrorConditionEnum e,
|
||||
typename boost::enable_if_<is_error_condition_enum<ErrorConditionEnum>::value>::type* = 0) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = make_error_condition( e );
|
||||
}
|
||||
@ -551,7 +388,7 @@ public:
|
||||
}
|
||||
|
||||
template<typename ErrorConditionEnum>
|
||||
typename boost::enable_if_<is_error_condition_enum<ErrorConditionEnum>::value, error_condition>::type &
|
||||
BOOST_SYSTEM_CONSTEXPR typename boost::enable_if_<is_error_condition_enum<ErrorConditionEnum>::value, error_condition>::type &
|
||||
operator=( ErrorConditionEnum val ) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = make_error_condition( val );
|
||||
@ -595,7 +432,7 @@ public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error
|
||||
{
|
||||
return m_val == 0 ? 0 : unspecified_bool_true;
|
||||
return m_val == 0? 0 : unspecified_bool_true;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error
|
||||
@ -611,15 +448,15 @@ public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return lhs.m_cat == rhs.m_cat && lhs.m_val == rhs.m_val;
|
||||
return lhs.m_val == rhs.m_val && *lhs.m_cat == *rhs.m_cat;
|
||||
}
|
||||
|
||||
inline friend bool operator<( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return lhs.m_cat < rhs.m_cat || ( lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val );
|
||||
return *lhs.m_cat < *rhs.m_cat || ( *lhs.m_cat == *rhs.m_cat && lhs.m_val < rhs.m_val );
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
operator std::error_condition () const BOOST_NOEXCEPT
|
||||
{
|
||||
@ -627,14 +464,9 @@ public:
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
int m_val;
|
||||
const error_category * m_cat;
|
||||
};
|
||||
|
||||
// class error_code --------------------------------------------------------------//
|
||||
// class error_code
|
||||
|
||||
// We want error_code to be a value type that can be copied without slicing
|
||||
// and without requiring heap allocation, but we also want it to have
|
||||
@ -645,6 +477,11 @@ private:
|
||||
|
||||
class error_code
|
||||
{
|
||||
private:
|
||||
|
||||
int m_val;
|
||||
const error_category * m_cat;
|
||||
|
||||
public:
|
||||
|
||||
// constructors:
|
||||
@ -657,7 +494,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
template <class ErrorCodeEnum> error_code( ErrorCodeEnum e,
|
||||
template <class ErrorCodeEnum> BOOST_SYSTEM_CONSTEXPR error_code( ErrorCodeEnum e,
|
||||
typename boost::enable_if_<is_error_code_enum<ErrorCodeEnum>::value>::type* = 0 ) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = make_error_code( e );
|
||||
@ -672,7 +509,7 @@ public:
|
||||
}
|
||||
|
||||
template<typename ErrorCodeEnum>
|
||||
typename boost::enable_if_<is_error_code_enum<ErrorCodeEnum>::value, error_code>::type &
|
||||
BOOST_SYSTEM_CONSTEXPR typename boost::enable_if_<is_error_code_enum<ErrorCodeEnum>::value, error_code>::type &
|
||||
operator=( ErrorCodeEnum val ) BOOST_NOEXCEPT
|
||||
{
|
||||
*this = make_error_code( val );
|
||||
@ -699,7 +536,7 @@ public:
|
||||
|
||||
error_condition default_error_condition() const BOOST_NOEXCEPT
|
||||
{
|
||||
return m_cat->default_error_condition(value());
|
||||
return m_cat->default_error_condition( value() );
|
||||
}
|
||||
|
||||
std::string message() const
|
||||
@ -721,7 +558,7 @@ public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error
|
||||
{
|
||||
return m_val == 0 ? 0 : unspecified_bool_true;
|
||||
return m_val == 0? 0 : unspecified_bool_true;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error
|
||||
@ -735,18 +572,18 @@ public:
|
||||
|
||||
// the more symmetrical non-member syntax allows enum
|
||||
// conversions work for both rhs and lhs.
|
||||
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return lhs.m_cat == rhs.m_cat && lhs.m_val == rhs.m_val;
|
||||
return lhs.m_val == rhs.m_val && *lhs.m_cat == *rhs.m_cat;
|
||||
}
|
||||
|
||||
inline friend bool operator<( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return lhs.m_cat < rhs.m_cat || ( lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val );
|
||||
return *lhs.m_cat < *rhs.m_cat || ( *lhs.m_cat == *rhs.m_cat && lhs.m_val < rhs.m_val );
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
operator std::error_code () const BOOST_NOEXCEPT
|
||||
{
|
||||
@ -754,27 +591,12 @@ public:
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
int m_val;
|
||||
const error_category * m_cat;
|
||||
};
|
||||
|
||||
// predefined error_code object used as "throw on error" tag
|
||||
|
||||
#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
|
||||
|
||||
BOOST_SYSTEM_DECL extern error_code throws;
|
||||
|
||||
#endif
|
||||
|
||||
// Moving from a "throws" object to a "throws" function without breaking
|
||||
// existing code is a bit of a problem. The workaround is to place the
|
||||
// "throws" function in namespace boost rather than namespace boost::system.
|
||||
|
||||
} // namespace system
|
||||
|
||||
|
||||
// boost::throws()
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
@ -807,11 +629,11 @@ inline system::error_code& throws()
|
||||
return *detail::throws();
|
||||
}
|
||||
|
||||
// non-member functions of error_code and error_condition
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
// non-member functions ------------------------------------------------//
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
|
||||
{
|
||||
return !( lhs == rhs );
|
||||
@ -852,123 +674,119 @@ template <class charT, class traits>
|
||||
|
||||
inline std::size_t hash_value( const error_code & ec )
|
||||
{
|
||||
// TODO use category id_, FNV combiner
|
||||
return static_cast<std::size_t>( ec.value() ) + reinterpret_cast<std::size_t>( &ec.category() );
|
||||
}
|
||||
|
||||
// make_* functions for errc::errc_t ---------------------------------------------//
|
||||
// make_* functions for errc::errc_t
|
||||
|
||||
namespace errc
|
||||
{
|
||||
|
||||
// explicit conversion:
|
||||
inline error_code make_error_code( errc_t e ) BOOST_NOEXCEPT
|
||||
// explicit conversion:
|
||||
BOOST_SYSTEM_CONSTEXPR inline error_code make_error_code( errc_t e ) BOOST_NOEXCEPT
|
||||
{
|
||||
return error_code( e, generic_category() );
|
||||
}
|
||||
|
||||
// implicit conversion:
|
||||
inline error_condition make_error_condition( errc_t e ) BOOST_NOEXCEPT
|
||||
// implicit conversion:
|
||||
BOOST_SYSTEM_CONSTEXPR inline error_condition make_error_condition( errc_t e ) BOOST_NOEXCEPT
|
||||
{
|
||||
return error_condition( e, generic_category() );
|
||||
}
|
||||
|
||||
} // namespace errc
|
||||
|
||||
// error_category default implementation -----------------------------------------//
|
||||
// error_category default implementation
|
||||
|
||||
error_condition error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
inline error_condition error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return error_condition( ev, *this );
|
||||
}
|
||||
|
||||
bool error_category::equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT
|
||||
inline bool error_category::equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return default_error_condition( code ) == condition;
|
||||
}
|
||||
|
||||
bool error_category::equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT
|
||||
inline bool error_category::equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return *this == code.category() && code.value() == condition;
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR
|
||||
// generic_error_category implementation
|
||||
|
||||
inline std::error_condition error_category::std_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
namespace detail
|
||||
{
|
||||
return pc_->default_error_condition( ev );
|
||||
}
|
||||
|
||||
inline bool error_category::std_category::equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT
|
||||
inline char const * generic_error_category_message( int ev )
|
||||
{
|
||||
if( condition.category() == *this )
|
||||
{
|
||||
boost::system::error_condition bn( condition.value(), *pc_ );
|
||||
return pc_->equivalent( code, bn );
|
||||
}
|
||||
else if( condition.category() == std::generic_category() || condition.category() == boost::system::generic_category() )
|
||||
{
|
||||
boost::system::error_condition bn( condition.value(), boost::system::generic_category() );
|
||||
return pc_->equivalent( code, bn );
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_RTTI
|
||||
|
||||
else if( std_category const* pc2 = dynamic_cast< std_category const* >( &condition.category() ) )
|
||||
{
|
||||
boost::system::error_condition bn( condition.value(), *pc2->pc_ );
|
||||
return pc_->equivalent( code, bn );
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable: 4996 )
|
||||
#endif
|
||||
|
||||
else
|
||||
{
|
||||
return default_error_condition( code ) == condition;
|
||||
}
|
||||
}
|
||||
char const * m = std::strerror( ev );
|
||||
|
||||
inline bool error_category::std_category::equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT
|
||||
{
|
||||
if( code.category() == *this )
|
||||
{
|
||||
boost::system::error_code bc( code.value(), *pc_ );
|
||||
return pc_->equivalent( bc, condition );
|
||||
}
|
||||
else if( code.category() == std::generic_category() || code.category() == boost::system::generic_category() )
|
||||
{
|
||||
boost::system::error_code bc( code.value(), boost::system::generic_category() );
|
||||
return pc_->equivalent( bc, condition );
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_RTTI
|
||||
|
||||
else if( std_category const* pc2 = dynamic_cast< std_category const* >( &code.category() ) )
|
||||
{
|
||||
boost::system::error_code bc( code.value(), *pc2->pc_ );
|
||||
return pc_->equivalent( bc, condition );
|
||||
}
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
else if( *pc_ == boost::system::generic_category() )
|
||||
{
|
||||
return std::generic_category().equivalent( code, condition );
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m? m: "Unknown error";
|
||||
}
|
||||
|
||||
#endif // #ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR
|
||||
inline std::string generic_error_category::message( int ev ) const
|
||||
{
|
||||
return generic_error_category_message( ev );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
|
||||
// system_error_category implementation
|
||||
|
||||
#ifdef BOOST_ERROR_CODE_HEADER_ONLY
|
||||
# include <boost/system/detail/error_code.ipp>
|
||||
#endif
|
||||
#if defined(BOOST_SYSTEM_WIN32)
|
||||
|
||||
#endif // BOOST_SYSTEM_ERROR_CODE_HPP
|
||||
#include <boost/system/detail/system_category_win32.hpp>
|
||||
|
||||
inline std::string boost::system::detail::system_error_category::message( int ev ) const
|
||||
{
|
||||
return system_category_message_win32( ev );
|
||||
}
|
||||
|
||||
inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return system_category_default_error_condition_win32( ev );
|
||||
}
|
||||
|
||||
#else // #if defined(BOOST_SYSTEM_WIN32)
|
||||
|
||||
inline std::string boost::system::detail::system_error_category::message( int ev ) const
|
||||
{
|
||||
return generic_error_category_message( ev );
|
||||
}
|
||||
|
||||
inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::system::error_condition( ev, generic_category() );
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_SYSTEM_WIN32)
|
||||
|
||||
// interoperability with std::error_code, std::error_condition
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
#include <boost/system/detail/std_interoperability.hpp>
|
||||
|
||||
inline boost::system::error_category::operator std::error_category const & () const BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::system::detail::to_std_category( *this );
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
#endif // BOOST_SYSTEM_ERROR_CODE_HPP_INCLUDED
|
||||
|
@ -1,6 +1,7 @@
|
||||
// error_code support implementation file ----------------------------------//
|
||||
// error_code stub implementation, for compatibility only
|
||||
|
||||
// Copyright Beman Dawes 2002, 2006
|
||||
// Copyright Peter Dimov 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)
|
||||
@ -9,12 +10,24 @@
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
// define BOOST_SYSTEM_SOURCE so that <boost/system/config.hpp> knows
|
||||
// the library is being built (possibly exporting rather than importing code)
|
||||
#define BOOST_SYSTEM_SOURCE
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
#ifndef BOOST_ERROR_CODE_HEADER_ONLY
|
||||
#include <boost/system/detail/error_code.ipp>
|
||||
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_SYSTEM_DYN_LINK)
|
||||
# define BOOST_SYSTEM_DECL BOOST_SYMBOL_EXPORT
|
||||
#else
|
||||
# define BOOST_SYSTEM_DECL
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
BOOST_SYSTEM_DECL void dummy_exported_function()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
@ -19,7 +19,7 @@
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
#include <boost/system/system_error.hpp>
|
||||
|
||||
#include <boost/system/config.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace boost
|
||||
@ -52,4 +52,4 @@ int main()
|
||||
|
||||
std::cout << " error: failed to catch boost::system::system_error\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -123,17 +123,7 @@ int main( int, char ** )
|
||||
BOOST_TEST( generic_category() != system_category() );
|
||||
BOOST_TEST( system_category() != generic_category() );
|
||||
|
||||
if ( std::less<const error_category*>()( &generic_category(), &system_category() ) )
|
||||
{
|
||||
BOOST_TEST( generic_category() < system_category() );
|
||||
BOOST_TEST( !(system_category() < generic_category()) );
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_TEST( system_category() < generic_category() );
|
||||
BOOST_TEST( !(generic_category() < system_category()) );
|
||||
}
|
||||
|
||||
BOOST_TEST_NE( generic_category() < system_category(), system_category() < generic_category() );
|
||||
|
||||
error_code ec;
|
||||
error_condition econd;
|
||||
|
@ -11,10 +11,14 @@
|
||||
// Avoid spurious VC++ warnings
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR)
|
||||
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -25,7 +29,6 @@ int main()
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <system_error>
|
||||
#include <cerrno>
|
||||
|
@ -11,10 +11,14 @@
|
||||
// Avoid spurious VC++ warnings
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR)
|
||||
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -25,7 +29,6 @@ int main()
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <system_error>
|
||||
#include <cerrno>
|
||||
|
@ -18,6 +18,7 @@
|
||||
#define BOOST_SYSTEM_SOURCE
|
||||
|
||||
#include <boost/system/system_error.hpp>
|
||||
#include <boost/system/config.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
Reference in New Issue
Block a user