Skip to content

Commit

Permalink
Make Boost.System header-only
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Sep 16, 2018
1 parent 0539726 commit 2fa0a00
Show file tree
Hide file tree
Showing 12 changed files with 660 additions and 479 deletions.
50 changes: 16 additions & 34 deletions include/boost/system/api_config.hpp
Original file line number Diff line number Diff line change
@@ -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.

//--------------------------------------------------------------------------------------//

#ifndef BOOST_SYSTEM_API_CONFIG_HPP
#define BOOST_SYSTEM_API_CONFIG_HPP

# if defined(BOOST_POSIX_API) || defined(BOOST_WINDOWS_API)
# error user defined BOOST_POSIX_API or BOOST_WINDOWS_API not supported
# endif
// This header is no longer used by Boost.System.
// Its use is discouraged and it will be deprecated.

// 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.
// Definition of BOOST_*_API retained for compatibility.

# 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
68 changes: 15 additions & 53 deletions include/boost/system/config.hpp
Original file line number Diff line number Diff line change
@@ -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

// 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.
// 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.

#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

// 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
// Included for compatibility. Not used.
#include <boost/system/api_config.hpp>

// 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)
Expand All @@ -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 changes: 74 additions & 0 deletions include/boost/system/detail/config.hpp
Original file line number Diff line number Diff line change
@@ -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 changes: 131 additions & 0 deletions include/boost/system/detail/std_interoperability.hpp
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 2fa0a00

Please sign in to comment.