Bring into compliance with N2066, TR2 Diagnostics Enhancements. Tests passing on Win32, Linux, on most modern compilers.

[SVN r35823]
This commit is contained in:
Beman Dawes
2006-11-03 16:57:30 +00:00
commit f3c8c74656
11 changed files with 1445 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
// boost/system/config.hpp -------------------------------------------------//
// 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.
#ifndef BOOST_SYSTEM_CONFIG_HPP
#define BOOST_SYSTEM_CONFIG_HPP
#include <boost/config.hpp>
// BOOST_POSIX_API or BOOST_WINDOWS_API specify which API to use.
// If not specified, a sensible default will be applied.
# if defined( BOOST_WINDOWS_API ) && defined( BOOST_POSIX_API )
# error both BOOST_WINDOWS_API and BOOST_POSIX_API are defined
# elif !defined( BOOST_WINDOWS_API ) && !defined( BOOST_POSIX_API )
# if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__)
# define BOOST_WINDOWS_API
# else
# define BOOST_POSIX_API
# endif
# endif
// enable dynamic linking on Windows ---------------------------------------//
//# if (defined(BOOST_ALL_DYN_LINK) || defined(BOOST_SYSTEM_DYN_LINK)) && defined(__BORLANDC__) && defined(__WIN32__)
//# error Dynamic linking Boost.Filesystem does not work for Borland; use static linking instead
//# endif
#ifdef BOOST_HAS_DECLSPEC // defined in config system
// we need to import/export our code only if the user has specifically
// asked for it by defining either BOOST_ALL_DYN_LINK if they want all boost
// libraries to be dynamically linked, or BOOST_SYSTEM_DYN_LINK
// if they want just this one to be dynamically liked:
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_SYSTEM_DYN_LINK)
// export if this is our own source, otherwise import:
#ifdef BOOST_SYSTEM_SOURCE
# define BOOST_SYSTEM_DECL __declspec(dllexport)
#else
# define BOOST_SYSTEM_DECL __declspec(dllimport)
#endif // BOOST_SYSTEM_SOURCE
#endif // DYN_LINK
#endif // BOOST_HAS_DECLSPEC
//
// if BOOST_SYSTEM_DECL isn't defined yet define it now:
#ifndef BOOST_SYSTEM_DECL
#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

View File

@@ -0,0 +1,147 @@
// boost/system/error_code.hpp ---------------------------------------------//
// Copyright Beman Dawes 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 library home page at http://www.boost.org/libs/filesystem
#ifndef BOOST_SYSTEM_ERROR_CODE_HPP
#define BOOST_SYSTEM_ERROR_CODE_HPP
#include <boost/system/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/assert.hpp>
#include <boost/operators.hpp>
#include <boost/detail/identifier.hpp>
#include <string>
#include <stdexcept>
#include <boost/config/abi_prefix.hpp> // must be the last #include
namespace boost
{
namespace system
{
# ifndef BOOST_NO_STD_WSTRING // workaround Cygwin's lack of wstring_t
typedef std::wstring wstring_t;
# else
typedef std::basic_string<wchar_t> wstring_t;
# endif
class error_code;
// typedefs for registering additional decoders -------------------------//
typedef int (*errno_decoder)( const error_code & );
typedef std::string (*message_decoder)( const error_code & );
typedef wstring_t (*wmessage_decoder)( const error_code & );
// class error_category ------------------------------------------------//
class BOOST_SYSTEM_DECL error_category : public identifier< uint_least32_t, error_category >
{
public:
error_category()
: boost::identifier< uint_least32_t, error_category >(0){}
explicit error_category( value_type v )
: boost::identifier< uint_least32_t, error_category >(v){}
};
// predefined error categories -----------------------------------------//
const error_category errno_ecat(0); // unspecified value
# ifdef BOOST_WINDOWS_API
const error_category native_ecat(1); // unspecified value
# else
const error_category native_ecat(0); // unspecified value
# endif
// class error_code ----------------------------------------------------//
class BOOST_SYSTEM_DECL error_code
{
public:
typedef boost::int_least32_t value_type;
// constructors:
error_code()
: m_value(0), m_category(errno_ecat) {}
error_code( value_type val, error_category cat )
: m_value(val), m_category(cat) {}
// observers:
value_type value() const { return m_value; }
error_category category() const { return m_category; }
int to_errno() const; // name chosen to limit surprises
// see Kohlhoff Jun 28 '06
std::string message() const;
wstring_t wmessage() const;
void assign( value_type val, const error_category & cat )
{
m_value = val;
m_category = cat;
}
// relationals:
bool operator==( const error_code & rhs ) const
{
return value() == rhs.value() && category() == rhs.category();
}
bool operator!=( const error_code & rhs ) const
{
return !(*this == rhs);
}
bool operator<( const error_code & rhs ) const
{
return category() < rhs.category()
|| ( category() == rhs.category() && value() < rhs.value() );
}
bool operator<=( const error_code & rhs ) const { return *this == rhs || *this < rhs; }
bool operator> ( const error_code & rhs ) const { return !(*this <= rhs); }
bool operator>=( const error_code & rhs ) const { return !(*this < rhs); }
typedef void (*unspecified_bool_type)();
static void unspecified_bool_true() {}
operator unspecified_bool_type() const // true if error
{
return m_value == value_type() ? 0 : unspecified_bool_true;
}
bool operator!() const // true if no error
{
return m_value == value_type();
}
// statics:
static error_category new_category( errno_decoder ed = 0,
message_decoder md = 0, wmessage_decoder wmd = 0 );
static bool get_decoders( error_category cat, errno_decoder & ed,
message_decoder & md, wmessage_decoder & wmd );
private:
value_type m_value;
error_category m_category;
};
// non-member functions ------------------------------------------------//
inline std::size_t hash_value( const error_code & ec )
{
return static_cast<std::size_t>(ec.value())
+ (static_cast<std::size_t>(ec.category().value()) << 16 );
}
} // namespace system
} // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_SYSTEM_ERROR_CODE_HPP

View File

@@ -0,0 +1,78 @@
// Boost system_error.hpp --------------------------------------------------//
// Copyright Beman Dawes 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)
#ifndef BOOST_SYSTEM_ERROR_HPP
#define BOOST_SYSTEM_ERROR_HPP
#include <string>
#include <stdexcept>
#include <cassert>
#include <boost/system/error_code.hpp>
namespace boost
{
namespace system
{
enum message_action { append_message, no_message };
// class system_error --------------------------------------------------//
class system_error : public std::runtime_error
{
public:
explicit system_error( error_code ec )
: std::runtime_error(std::string()), m_error_code(ec),
m_append_message(true) {}
system_error( error_code ec, const std::string & what_arg,
message_action ma = append_message )
: std::runtime_error(what_arg), m_error_code(ec),
m_append_message(ma==append_message) {}
system_error( error_code::value_type ev, error_category ecat )
: std::runtime_error(std::string()), m_error_code(ev,ecat),
m_append_message(true) {}
system_error( error_code::value_type ev, error_category ecat,
const std::string & what_arg, message_action ma = append_message )
: std::runtime_error(what_arg), m_error_code(ev,ecat),
m_append_message(ma==append_message) {}
virtual ~system_error() throw() {}
const error_code & code() const throw() { return m_error_code; }
const char * what() const throw()
// see http://www.boost.org/more/error_handling.html for lazy build rationale
{
if ( !m_error_code || !m_append_message ) return runtime_error::what();
if ( m_what.empty() )
{
try
{
m_what = runtime_error::what();
if ( !m_what.empty() ) m_what += ": ";
m_what += m_error_code.message();
}
catch (...) { return runtime_error::what(); }
}
return m_what.c_str();
}
private:
error_code m_error_code;
mutable std::string m_what;
bool m_append_message;
};
} // namespace system
} // namespace boost
#endif // BOOST_SYSTEM_ERROR_HPP