Compare commits

...

40 Commits

Author SHA1 Message Date
Beman Dawes
51e4669a0b Release 1.45.0 beta 1
[SVN r66473]
2010-11-09 18:22:33 +00:00
Beman Dawes
7ffc036bc2 Merge trunk, including changes to come into closer conformance with C++0x FCD
[SVN r63685]
2010-07-06 10:47:30 +00:00
Hartmut Kaiser
6888c0c7b8 Spirit: merging from trunk upto rev. 61489
[SVN r63640]
2010-07-04 22:38:38 +00:00
Douglas Gregor
eeb5844852 Merge standards-conformance fix for Boost.System
[SVN r61862]
2010-05-09 00:33:44 +00:00
Beman Dawes
f8ddc693ae System: merge trunk
[SVN r57634]
2009-11-13 14:37:32 +00:00
Troy D. Straszheim
cf8fbe855f rm cmake from the release branch before it goes out broken. Policy dictates that you never commit to release, you commit to trunk and merge to release.
[SVN r56941]
2009-10-17 01:10:45 +00:00
Beman Dawes
691fb5522c system: merge trunk
[SVN r56777]
2009-10-13 13:44:42 +00:00
Beman Dawes
e8e4f47902 Merge from trunk
[SVN r55489]
2009-08-09 17:34:58 +00:00
Troy D. Straszheim
078a1f23c4 Copyrights on CMakeLists.txt to keep them from clogging up the inspect
reports.  This is essentially the same commit as r55095 on the release
branch.



[SVN r55159]
2009-07-26 00:49:56 +00:00
Troy D. Straszheim
accf4f8414 Add basic copyright/license to keep cmake out of the inspection report
[SVN r55095]
2009-07-22 21:51:01 +00:00
Beman Dawes
3f26239374 System: fix #3113
[SVN r53460]
2009-05-30 15:13:39 +00:00
Beman Dawes
fd0605bd7e System, Filesystem: remove boost/detail/test_framework.hpp; use boost/detail/lightweight_test.hpp instead (Thanks to Peter Dimov for pointing this out)
[SVN r51966]
2009-03-25 12:11:47 +00:00
Beman Dawes
83db702d99 System: removed dependency on Boost.Test
[SVN r51960]
2009-03-24 15:38:10 +00:00
Troy D. Straszheim
e6f66bfc95 merge of cmake build files from trunk per beman
[SVN r50756]
2009-01-24 18:57:20 +00:00
Beman Dawes
f1cdde273a System: move throws function to namespace boost to allow peaceful coexistence with throws object.
[SVN r50727]
2009-01-22 14:47:50 +00:00
Beman Dawes
5bc362e4f3 System: provide optional throws function rather than throws object
[SVN r50705]
2009-01-21 18:01:14 +00:00
Beman Dawes
40612c12db System: merge from trunk
[SVN r50700]
2009-01-21 14:08:54 +00:00
Beman Dawes
a6728e5fb9 System: add deprecated get_posix_category() to fix ticket #2461
[SVN r49717]
2008-11-13 16:05:49 +00:00
Beman Dawes
99ee7ddaab System: rename msvc_system -> system->msvc so VC++ start page recent solutions list is easier to use
[SVN r49716]
2008-11-13 15:57:04 +00:00
Michael A. Jackson
3e8a2633f4 Continuing merge of CMake build system files into trunk with the encouragement of Doug Gregor
[SVN r49510]
2008-11-01 13:15:41 +00:00
Beman Dawes
888786e838 System: apply patch from ticket #2175
[SVN r49293]
2008-10-12 14:07:22 +00:00
Beman Dawes
726478b372 System: merge accumulated changes from trunk
[SVN r49292]
2008-10-12 13:51:47 +00:00
Beman Dawes
dca57ac132 System: Upgrade docs to reflect N2798 (and thus CD1), fix ticket #2125, and provide a table of deprecated names and their replacements.
[SVN r49291]
2008-10-12 13:27:59 +00:00
Beman Dawes
d19e139e11 Change names to ErrorCodeEnum and ErrorConditionEnum to conform to N2798
[SVN r49290]
2008-10-12 13:07:11 +00:00
Beman Dawes
4dc986ca03 System: Only supply case EALREADY if EALREADY != EBUSY, to close a portion of ticket #2288
[SVN r49220]
2008-10-09 19:01:57 +00:00
Beman Dawes
214ed40b22 System: refine docs for semantics of throws object
[SVN r49177]
2008-10-08 14:16:05 +00:00
Beman Dawes
b4cc289238 System: fix typo that is apparent cause of Mac OS X compile failures
[SVN r49157]
2008-10-07 01:57:24 +00:00
Beman Dawes
a753ffd26f System: add throws object specification, including semantics
[SVN r49138]
2008-10-05 13:02:01 +00:00
Beman Dawes
ee16863a40 system: add #ifndef as requested by #2098
[SVN r49094]
2008-10-01 19:08:08 +00:00
Beman Dawes
463cefcf94 system: reduce chance of message() throwing in response to ticket #2098
[SVN r49093]
2008-10-01 18:57:48 +00:00
Beman Dawes
84ff2d0f04 Initial commit: system/test/msvc_system
[SVN r49090]
2008-10-01 18:24:20 +00:00
Beman Dawes
b7cd247b64 Remove redundant Jamfile <define>s
[SVN r49080]
2008-10-01 14:14:58 +00:00
Beman Dawes
d6446d1cfb Add error_code throws
[SVN r48577]
2008-09-04 17:36:56 +00:00
Beman Dawes
6fdac34196 Merge accumulated changes from trunk
[SVN r47300]
2008-07-11 01:25:09 +00:00
Beman Dawes
a97517585c Add const char* constructors to system_error, rationalize test coverage
[SVN r46678]
2008-06-25 14:16:59 +00:00
Beman Dawes
2953464e99 Apply LWG issue 805, using a namespace to emulate scoped enums.
[SVN r46645]
2008-06-24 14:59:10 +00:00
Beman Dawes
69d2a2234c Fix Ticket #1768 by including <boost/config/warning_disable.hpp>
[SVN r45894]
2008-05-29 01:34:53 +00:00
Beman Dawes
98a757dbf7 Fix ticket #1609
[SVN r45830]
2008-05-27 20:01:15 +00:00
Beman Dawes
51e9c56427 Give the 1st and 2nd level index.html files a common look-and-feel.
[SVN r43402]
2008-02-23 14:04:02 +00:00
Beman Dawes
fcdecd4c96 Remove extraneous defines since they are inherited from library build Jamfile
[SVN r42873]
2008-01-20 02:01:35 +00:00
22 changed files with 1127 additions and 529 deletions

View File

@@ -6,15 +6,15 @@
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Boost System Library</title>
<link rel="stylesheet" type="text/css" href="../../../doc/html/minimal.css">
<link rel="stylesheet" type="text/css" href="../../../doc/src/minimal.css">
</head>
<body>
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="637">
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td width="277">
<a href="../../../index.htm">
<a href="../../../index.html">
<img src="../../../boost.png" alt="boost.png (6897 bytes)" align="middle" width="277" height="86" border="0"></a></td>
<td width="337" align="middle">
<font size="7">System Library</font>
@@ -93,6 +93,18 @@ supports both error reporting by exception and by error code.</p>
error_code.hpp</code> header, system-specific headers support the Cygwin, Linux,
and Windows platforms. These headers are effectively no-ops if included for
platforms other than their intended target.</p>
<table border="1" cellpadding="10" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td>The Boost System Library will become part of the C++0x Standard Library.
A number of changes, particularly to names, were made by the C++ committee
during standardization. The Boost implementation is tracking those changes.
See <a href="reference.html#Deprecated-names">Deprecated names</a> for
synonyms provided to prevent breakage of existing user code. See
<a href="reference.html#Breaking-changes">Breaking changes</a> for changes
that unavoidably break existing user code. All breaking changes are noisy
and will cause compile-time errors.</td>
</tr>
</table>
<h2><a name="Design_Rationale">Design Rationale</a></h2>
<p>Class <code>error_code</code>&nbsp; and <code>error_condition</code> are designed as a value types so
they can be copied
@@ -132,14 +144,16 @@ Oleg Abrosimov. Christopher Kohlhoff suggested several improvements to the N2066
paper. Johan Nilsson's comments led to several of the refinements in N2066 .</p>
<hr>
<p>© Copyright Beman Dawes, 1999<br>
Distributed under the Boost Software License, Version 1.0. See
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->November 12, 2007<!--webbot bot="Timestamp" endspan i-checksum="39581" --> </font>
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->May 28, 2010<!--webbot bot="Timestamp" endspan i-checksum="11241" --> </font>
</p>
<p>© Copyright Beman Dawes, 1999</p>
<p>Distributed under the Boost Software License, Version 1.0.
(See file <a href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
or&nbsp; <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>) </p>
</body>
</html>

View File

@@ -6,7 +6,7 @@
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>System Library Reference</title>
<link rel="stylesheet" type="text/css" href="../../../doc/html/minimal.css">
<link rel="stylesheet" type="text/css" href="../../../doc/src/minimal.css">
</head>
<body>
@@ -39,6 +39,8 @@
<td width="100%" bgcolor="#E8F5FF">
<a href="#Introduction">Introduction</a><br>
<a href="#Macros">Macros</a><br>
<a href="#Deprecated-names">Deprecated names</a><br>
<a href="#Breaking-changes">Breaking changes</a><br>
<a href="#Header-error_code">Header &lt;boost/system/error_code.hpp&gt;</a><br>
<a href="#Class-error_category">Class <code>error_category</code></a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_category-synopsis">Class <code>error_category</code> synopsis</a><br>
@@ -52,11 +54,13 @@
&nbsp;&nbsp;&nbsp;<a href="#Class-error_code-constructors">Class <code>error_code</code> constructors</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_code-modifiers">Class <code>error_code</code> modifiers</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_code-observers">Class <code>error_code</code> observers</a><br>
<a href="#Class-error_condition</code>">Class <code>error_condition</code></a><br>
<a href="#Class-error_condition">Class <code>error_condition</code></a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_condition-synopsis">Class <code>error_condition</code> synopsis</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_condition-constructors">Class <code>error_condition</code> constructors</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_condition-modifiers">Class <code>error_condition</code> modifiers</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_condition-observers">Class <code>error_condition</code> observers</a><br>
<a href="#throws-object"><code>throws</code> object</a><br>
<a href="#Semantics-of-throws">Semantics of <code>throws</code> object</a><br>
<a href="#Non-member-functions">Non-member functions</a><br>
<a href="#Header-system_error">Header &lt;boost/system/system_error.hpp&gt;</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-system_error">Class <code>system_error</code></a><br>
@@ -74,46 +78,98 @@ errno</code>.</p>
<h2><a name="Macros">Macros</a></h2>
<p>Users may defined the following macros if desired. Sensible defaults are
provided, so users may ignore these macros if they prefer.</p>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" height="368">
<tr>
<td><b><i>Macro Name</i></b></td>
<td><b><i>Default</i></b></td>
<td><b><i>Effect if defined</i></b></td>
<td height="16"><b><i>Macro Name</i></b></td>
<td height="16"><b><i>Default</i></b></td>
<td height="16"><b><i>Effect if defined</i></b></td>
</tr>
<tr>
<td valign="top"><code>BOOST_WINDOWS_API</code></td>
<td valign="top">Defined if Windows is detected by Boost.System's automatic configuration
code, otherwise not defined.</td>
<td valign="top">Implementation uses the Microsoft Windows native
application program interface (API).</td>
</tr>
<tr>
<td valign="top"><code>BOOST_POSIX_API</code></td>
<td valign="top">Defined if Windows is not detected by Boost.System's automatic configuration
code.</td>
<td valign="top">Implementation uses the POSIX native
application program interface (API).</td>
</tr>
<tr>
<td valign="top"><code>BOOST_SYSTEM_DYN_LINK</code></td>
<td valign="top">Defined if <code>BOOST_ALL_DYN_LINK</code> is defined,
<td valign="top" height="64"><code>BOOST_SYSTEM_DYN_LINK</code></td>
<td valign="top" height="64">Defined if <code>BOOST_ALL_DYN_LINK</code> is defined,
otherwise not defined.</td>
<td valign="top">Boost.System library is dynamically linked. If not defined,
<td valign="top" height="64">Boost.System library is dynamically linked. If not defined,
static linking is assumed.</td>
</tr>
<tr>
<td valign="top"><code>BOOST_SYSTEM_NO_LIB</code></td>
<td valign="top">Defined if <code>BOOST_ALL_NO_LIB</code> is defined,
<td valign="top" height="47"><code>BOOST_SYSTEM_NO_LIB</code></td>
<td valign="top" height="47">Defined if <code>BOOST_ALL_NO_LIB</code> is defined,
otherwise not defined.</td>
<td valign="top">Boost.System library does not use the Boost auto-link
<td valign="top" height="47">Boost.System library does not use the Boost auto-link
facility.</td>
</tr>
<tr>
<td valign="top"><code>BOOST_SYSTEM_NO_DEPRECATED</code></td>
<td valign="top">Not defined.</td>
<td valign="top">Deprecated features are excluded.</td>
<td valign="top" height="32"><code>BOOST_SYSTEM_NO_DEPRECATED</code></td>
<td valign="top" height="32">Not defined.</td>
<td valign="top" height="32">Deprecated features are excluded.</td>
</tr>
</table>
<h2><a name="Deprecated-names">Deprecated names</a></h2>
<p>In the process of adding Boost.System to C++0x standard library, the C++
committee changed some
names. To ease transition, Boost.System deprecates the old
names, but continues to provide them unless macro <code>BOOST_SYSTEM_NO_DEPRECATED</code>
is defined.</p>
<table border="1" cellpadding="5" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td><b><i>Old usage, now deprecated</i></b></td>
<td><b><i>Replacement</i></b></td>
</tr>
<tr>
<td><code>get_generic_category()</code></td>
<td><code>generic_category()</code></td>
</tr>
<tr>
<td><code>get_system_category()</code></td>
<td><code>system_category()</code></td>
</tr>
<tr>
<td><code>namespace posix</code></td>
<td><code>namespace errc</code></td>
</tr>
<tr>
<td><code>namespace posix_error</code></td>
<td><code>namespace errc</code></td>
</tr>
<tr>
<td><code>enum posix_errno</code></td>
<td><code>enum errc_t</code></td>
</tr>
<tr>
<td><code>get_posix_category()</code></td>
<td><code>generic_category()</code></td>
</tr>
<tr>
<td><code>posix_category</code></td>
<td><code>generic_category()</code></td>
</tr>
<tr>
<td><code>errno_ecat</code></td>
<td><code>generic_category()</code></td>
</tr>
<tr>
<td><code>native_ecat</code></td>
<td><code>system_category()</code></td>
</tr>
</table>
<h2><a name="Breaking-changes">Breaking changes</a></h2>
<p>Two static consts are replaced by functions. These are breaking changes best
fixed by globally adding () to these names to turn them into function calls.</p>
<table border="1" cellpadding="5" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td><b><i>Old usage, now broken</i></b></td>
<td><b><i>Replacement</i></b></td>
</tr>
<tr>
<td><code>generic_category</code></td>
<td><code>generic_category()</code></td>
</tr>
<tr>
<td><code>system_category</code></td>
<td><code>system_category()</code></td>
</tr>
</table>
<p>User-defined BOOST_POSIX_API and BOOST_WINDOWS_API macros are no longer supported.</p>
<h2><a name="Header-error_code">Header &lt;boost/system/error_code.hpp&gt;</a></h2>
<h3>&lt;boost/system/error_code.hpp&gt; synopsis</h3>
<blockquote>
@@ -132,10 +188,10 @@ provided, so users may ignore these macros if they prefer.</p>
template< class T="" >
struct is_error_condition_enum { static const bool value = false; };
// portable error_conditions
namespace posix_error
// generic error_conditions
namespace errc
{
enum posix_errno
enum errc_t
{
success = 0,
address_family_not_supported, //EAFNOSUPPORT
@@ -218,11 +274,13 @@ provided, so users may ignore these macros if they prefer.</p>
wrong_protocol_type //EPROTOTYPE
};
} // namespace posix_error
} // namespace errc
template<> struct is_error_condition_enum<posix::posix_errno>&lt;posix_error::posix_errno&gt;
template<> struct is_error_condition_enum<posix::posix_errno>&lt;errc::errc_t&gt;
{ static const bool value = true; };
// <a href="#Non-member-functions">non-member functions</a>
bool operator==( const error_code &amp; lhs, const error_code &amp; rhs );
bool operator==( const error_code &amp; code, const error_condition &amp; condition );
bool operator==( const error_condition &amp; condition, const error_code &amp; code );
@@ -236,8 +294,8 @@ provided, so users may ignore these macros if they prefer.</p>
bool operator&lt;( const error_code &amp; lhs, const error_code &amp; rhs );
bool operator&lt;( const error_condition &amp; lhs, const error_condition &amp; rhs );
error_code make_error_code( posix_error::posix_errno e );
error_condition make_error_condition( posix_error::posix_errno e );
error_code make_error_code( errc::errc_t e );
error_condition make_error_condition( errc::errc_t e );
template &lt;class charT, class traits&gt;
std::basic_ostream&lt;charT,traits&gt;&amp;
@@ -247,7 +305,7 @@ provided, so users may ignore these macros if they prefer.</p>
}
}</pre>
</blockquote>
<p>The value of each<code> posix_errno</code> constant shall be the same as the
<p>The value of each<code> errc_t</code> constant shall be the same as the
value of the <code>&lt;cerrno&gt;</code> macro shown in the above synopsis.</p>
<p>Users may specialize <code>is_error_code_enum</code> and <code>
is_error_condition_enum</code> templates to indicate that a type is eligible for
@@ -279,7 +337,7 @@ types should create a single object of each such type. <i>
virtual ~error_category();
virtual const char * name() const = 0;
virtual string message( error_code::value_type ev ) const = 0;
virtual string message( int ev ) const = 0;
virtual error_condition default_error_condition( int ev ) const;
virtual bool equivalent( int code, const error_condition &amp; condition ) const;
virtual bool equivalent( const error_code &amp; code, int condition ) const;
@@ -289,11 +347,8 @@ types should create a single object of each such type. <i>
bool operator&lt; ( const error_category &amp; rhs ) const;
};
const error_category &amp; get_system_category();
const error_category &amp; get_posix_category();
static const error_category &amp; system_category = get_system_category();
static const error_category &amp; posix_category = get_posix_category();
const error_category &amp; system_category();
const error_category &amp; generic_category();
}
}</pre>
</blockquote>
@@ -305,7 +360,7 @@ this subclause.</p>
<p><i>Returns: </i>a string naming the error category.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>virtual string message( error_code::value_type ev ) const=0;</pre>
<pre>virtual string message( int ev ) const=0;</pre>
<blockquote>
<p><i>Returns:</i> A string that describes the error denoted by
<code>ev</code>.</p>
@@ -315,8 +370,8 @@ this subclause.</p>
<blockquote>
<p><i>Returns:</i>&nbsp; <code>error_condition( ev, *this )</code>.</p>
<blockquote>
<p>&nbsp;[<i>--Note:</i> Derived classes will typically convert <code>ev</code>
to some portable <code>error_category</code>, such as <code>posix_category</code>,
<p dir="ltr">&nbsp;[<i>--Note:</i> Derived classes will typically convert <code>ev</code>
to some portable <code>error_category</code>, such as <code>generic_category()</code>,
and return it as an <code>error_condition</code> for that category. <i>--end
note</i>]</p>
</blockquote>
@@ -355,22 +410,18 @@ const;</code></p>
</blockquote>
<h3><a name="Class-error_category-non-member-functions">Class <code>error_category</code>
non-member functions</a></h3>
<pre>const error_category &amp; get_system_category();</pre>
<pre>const error_category &amp; system_category();</pre>
<blockquote>
<p><i>Returns:</i> A reference to a <code>error_category</code> object
identifying errors originating from the operating system.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>const error_category &amp; get_posix_category();</pre>
<pre>const error_category &amp; generic_category();</pre>
<blockquote>
<p><i>Returns:</i> A reference to a <code>error_category</code> object
identifying portable error conditions.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<h3><a name="Class-error_category-predefined-objects">Class <code>error_category</code>
predefined objects</a></h3>
<p>Predefined objects <code>system_category</code>
and <code>posix_category</code> identify operating system error codes and portable error conditions, respectively.</p>
<h2><a name="Class-error_code">Class <code>
error_code</code></a></h2>
<p>The class <code>error_code</code> describes an object used to hold error code
@@ -392,14 +443,12 @@ error_code</code> synopsis</a></h3>
error_code();
error_code( val, const error_category &amp; cat );
template &lt;class <code>ErrorCodeEnum</code>&gt;
error_code(<code> errorCodeEnum</code> e,
typename enable_if&lt;is_error_code_enum&lt;<code>ErrorCodeEnum</code>&gt; &gt;::type* = 0);
error_code(<code> ErrorCodeEnum</code> e );
// modifiers:
void assign( int val, const error_category &amp; cat );
template&lt;typename <code>ErrorCodeEnum</code>&gt;
typename enable_if&lt;is_error_code_enum&lt;<code>ErrorCodeEnum</code>&gt;, error_code&gt;::type &amp;
operator=( <code>ErrorCodeEnum</code> val );;
error_code &amp; operator=( <code>ErrorCodeEnum</code> val );;
void clear();
// observers:
@@ -411,7 +460,7 @@ error_code</code> synopsis</a></h3>
private:
int val_; // <i>exposition only</i>
const error_category &amp; cat_; // <i>exposition only</i>
const error_category * cat_; // <i>exposition only</i>
};
}
}</pre>
@@ -421,7 +470,7 @@ error_code</code> constructors</a></h3>
<pre>error_code();</pre>
<blockquote>
<p><i>Effects: </i>Constructs an object of type <code>error_code</code>.</p>
<p><i>Postconditions:</i> <code>val_ == 0 &amp;&amp; cat_ == &amp;system_category</code>.</p>
<p><i>Postconditions:</i> <code>val_ == 0 &amp;&amp; cat_ == &amp;system_category()</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>error_code( int val, const error_category &amp; cat );</pre>
@@ -431,30 +480,34 @@ error_code</code> constructors</a></h3>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>template &lt;class <code>ErrorCodeEnum</code>&gt;
error_code(<code> errorCodeEnum</code> val,
typename enable_if&lt;is_error_code_enum&lt;<code>ErrorCodeEnum</code>&gt; &gt;::type* = 0);</pre>
error_code(<code> ErrorCodeEnum</code> val );</pre>
<blockquote>
<p><i>Effects: </i>Constructs an object of type <code>error_code</code>.</p>
<p><i>Postconditions:</i> <code>*this == make_error_code( val )</code>.</p>
<p><i>Throws:</i> Nothing.</p>
<p><i>Remarks:</i> This constructor shall not participate in overload
resolution unless <code>is_error_code_enum&lt;ErrorCodeEnum&gt;::value</code> is
<code>true</code>.</p>
</blockquote>
<h3><a name="Class-error_code-modifiers">Class <code>
error_code</code> modifiers</a></h3>
<pre>void assign( int val, const error_category &amp; cat );</pre>
<blockquote>
<p><i>Postconditions:</i> <code>val_ == val &amp;&amp; cat_ == cat</code>.</p>
<p><i>Postconditions:</i> <code>val_ == val &amp;&amp; cat_ == &amp;cat</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>template&lt;typename <code>ErrorCodeEnum</code>&gt;
typename enable_if&lt;is_error_code_enum&lt;<code>ErrorCodeEnum</code>&gt;, error_code&gt;::type &amp;
operator=( <code>ErrorCodeEnum</code> val );</pre>
error_code &amp; operator=( <code>ErrorCodeEnum</code> val );</pre>
<blockquote>
<p><i>Postconditions:</i> <code>*this == make_error_code( val )</code>.</p>
<p><i>Throws:</i> Nothing.</p>
<p><i>Remarks:</i> This operator shall not participate in overload resolution
unless <code>is_error_code_enum&lt;ErrorCodeEnum&gt;::value</code> is <code>true</code>.</p>
</blockquote>
<p><code>void clear();</code></p>
<blockquote>
<p><i>postcondition:</i> <code>value() == 0 &amp;&amp; category() == posix_category</code></p>
<p><i>postcondition:</i> <code>value() == 0 &amp;&amp; category() ==
system_category()</code></p>
</blockquote>
<h3><a name="Class-error_code-observers">Class <code>
error_code</code> observers</a></h3>
@@ -463,9 +516,9 @@ error_code</code> observers</a></h3>
<p><i>Returns:</i> <code>val_</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<p><code>error_category category() const;</code></p>
<p><code>const error_category &amp; category() const;</code></p>
<blockquote>
<p><i>Returns:</i> <code>cat_</code>.</p>
<p><i>Returns:</i> <code>*cat_</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>error_condition default_error_condition() const;</pre>
@@ -480,7 +533,7 @@ error_code</code> observers</a></h3>
</blockquote>
<p><code>operator <i>unspecified-bool-type</i>() const;</code></p>
<blockquote>
<p><i>Returns:</i> if <code>value() != value_type()</code>, returns a value that will evaluate
<p><i>Returns:</i> if <code>value() != 0</code>, returns a value that will evaluate
<code>true</code> in a boolean context; otherwise, returns a value that will
evaluate <code>false</code> in a boolean context. The value type returned shall
not be convertible to <code>int</code>.</p>
@@ -510,14 +563,12 @@ implementation specific. <i>--end note ]</i></p>
error_condition();
error_condition( int val, const error_category &amp; cat );
template &lt;class ErrorConditionEnum&gt;
error_condition( errorConditionEnum val,
typename enable_if&lt;is_error_condition_enum&lt;ErrorConditionEnum&gt; &gt;::type* = 0 );
error_condition( errorConditionEnum val );
// modifiers:
void assign( int val, const error_category &amp; cat );
template&lt;typename ErrorConditionEnum&gt;
typename enable_if&lt;is_error_condition_enum&lt;ErrorConditionEnum&gt;, error_code&gt;::type &amp;
operator=( ErrorConditionEnum val );
error_condition &amp; operator=( ErrorConditionEnum val );
void clear();
// observers:
@@ -527,8 +578,8 @@ implementation specific. <i>--end note ]</i></p>
operator unspecified-bool-type () const;
private:
int val_; // <i>exposition only</i>
const error_category &amp; cat_; // <i>exposition only</i>
int val_; // <i>exposition only</i>
const error_category * cat_; // <i>exposition only</i>
};
}
}</pre>
@@ -538,51 +589,56 @@ constructors</a></h3>
<pre>error_condition(); </pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of type <code>error_condition</code>.</p>
<p><i>Postconditions:</i> <code>val_ == 0 and cat_ == posix_category</code>.</p>
<p><i>Postconditions:</i> <code>val_ == 0 and cat_ == &amp;generic_category()</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>error_condition( value_type val, const error_category &amp; cat );</pre>
<pre>error_condition( int val, const error_category &amp; cat );</pre>
<blockquote>
<p><i>Effects: </i>Constructs an object of type error_condition.</p>
<p><i>Postconditions:</i> <code>val_ == val and cat_ == cat</code>.</p>
<p><i>Postconditions:</i> <code>val_ == val and cat_ == &amp;cat</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>template &lt;class ErrorConditionEnum&gt;
error_condition( errorConditionEnum val,
typename enable_if&lt;is_error_condition_enum&lt;ErrorConditionEnum&gt; &gt;::type* = 0 );</pre>
error_condition( ErrorConditionEnum e );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of type <code>error_condition</code>.</p>
<p><i>Postconditions:</i> <code>*this == make_error_condition( val )</code>.</p>
<p><i>Postconditions:</i> <code>*this == make_error_condition(e)</code>.</p>
<p><i>Throws:</i> Nothing.</p>
<p><i>Remarks:</i> This constructor shall not participate in overload
resolution unless <code>is_error_condition_enum&lt;ErrorConditionEnum&gt;::value</code>
is <code>true</code>.</p>
</blockquote>
<h3><a name="Class-error_condition-modifiers">Class <code>error_condition</code>
modifiers</a></h3>
<pre>void assign( value_type val, const error_category &amp; cat ); </pre>
<pre>void assign( int val, const error_category &amp; cat ); </pre>
<blockquote>
<p><i>Postconditions:</i> <code>val_ == val and cat_ == cat</code>. </p>
<p><i>Postconditions:</i> <code>val_ == val and cat_ == &amp;cat</code>. </p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>template&lt;typename ErrorConditionEnum&gt;
typename enable_if&lt;is_error_condition_enum&lt;ErrorConditionEnum&gt;, error_code&gt;::type &amp;
operator=( ErrorConditionEnum val );</pre>
error_condition &amp; operator=( ErrorConditionEnum e );</pre>
<blockquote>
<p><i>Postconditions:</i> <code>*this == make_error_condition( val )</code>.</p>
<p><i>Postconditions:</i> <code>*this == make_error_condition( e )</code>.</p>
<p><i>Returns:</i> <code>*this</code>.</p>
<p><i>Throws:</i> Nothing.</p>
<p><i>Remarks:</i> This operator shall not participate in overload resolution
unless <code>is_error_condition_enum&lt;ErrorConditionEnum&gt;::value</code> is
<code>true</code>.</p>
</blockquote>
<p><code>void clear();</code></p>
<blockquote>
<p><i>postcondition:</i> <code>value() == 0 &amp;&amp; category() == posix_category</code></p>
<p><i>postcondition:</i> <code>value() == 0 &amp;&amp; category() == generic_category()</code></p>
</blockquote>
<h3><a name="Class-error_condition-observers">Class <code>error_condition</code>
observers</a></h3>
<pre>value_type value() const;</pre>
<pre>int value() const;</pre>
<blockquote>
<p><i>Returns:</i> <code>val_</code>.</p>
<p><i>Throws:</i> Nothing</p>
</blockquote>
<pre>const error_category &amp; category() const;</pre>
<blockquote>
<p><i>Returns:</i> <code>cat_</code>.</p>
<p><i>Returns:</i> <code>*cat_</code>.</p>
<p>Throws: Nothing.</p>
</blockquote>
<pre>string message() const;</pre>
@@ -603,7 +659,37 @@ observers</a></h3>
eliminating some sources of user error. One possible implementation choice for
this type is pointer to member. <i>--end note</i> <i>]</i></p>
</blockquote>
<h2><a name="Non-member-functions">Non-member functions</a></h2>
<h2><a name="throws-object"><code>throws</code> object</a></h2>
<pre>extern error_code throws;</pre>
<p>The predefined <code>error_code</code> object <code>throws</code> is supplied
for use as a &quot;throw on error&quot; tag.</p>
<h2><a name="Semantics-of-throws">Semantics of <code>throws</code></a> object</h2>
<p>Functions that specify an argument in the form <code>error_code&amp; ec=throws</code>,
with appropriate namespace qualifiers, have the following error handling
semantics:</p>
<blockquote>
<p><i>Postconditions:</i></p>
<blockquote>
<p>If <code>&amp;ec != &amp;throws</code> and an error occurred:</p>
<ul>
<li> <code>ec.value()</code> returns the implementation specific error
number for the particular error that occurred.</li>
<li><code>ec.category()</code> returns the <code>
<a href="#Class-error_category">error_category</a></code> for <code>ec.value()</code>.</li>
</ul>
<p>if <code>&amp;ec != &amp;throws</code> and an error did not occur, <code>ec.clear()</code>.</p>
</blockquote>
<p><i>Throws:</i></p>
<blockquote>
<p>If an error occurs and <code>&amp;ec == &amp;throws</code>, throws an exception of type
<code><a href="#Class-system_error">system_error</a></code> or of a type
derived from <code><a href="#Class-system_error">system_error</a></code>. The
exception's <code>code()</code> member function returns a reference to an
<code>error_code</code> object with the behavior specified in <i>
Postconditions</i>.</p>
</blockquote>
</blockquote>
<h2><a name="Non-member-functions">Non-member functions</a></h2>
<pre>bool operator==( const error_code &amp; lhs, const error_code &amp; rhs );</pre>
<blockquote>
<p><i>Returns:</i> <code>lhs.category() == rhs.category() &amp;&amp; lhs.value() ==
@@ -651,13 +737,13 @@ bool operator!=( const error_condition &amp; condition, const error_code &amp; c
&nbsp; || (lhs.category() == rhs.category() &amp;&amp; lhs.value() &lt; rhs.value())</code>.</p>
<p><i>Throws: </i>Nothing.</p>
</blockquote>
<pre>error_code make_error_code( posix_error::posix_errno e );</pre>
<pre>error_code make_error_code( errc::errc_t e );</pre>
<blockquote>
<p><i>Returns:</i> <code>error_code( e, posix_category)</code>.</p>
<p><i>Returns:</i> <code>error_code( e, generic_category())</code>.</p>
</blockquote>
<pre>error_condition make_error_condition( posix_error::posix_errno e );</pre>
<pre>error_condition make_error_condition( errc::errc_t e );</pre>
<blockquote>
<p><i>Returns:</i> <code>error_condition( e, posix_category)</code>.</p>
<p><i>Returns:</i> <code>error_condition( static_cast&lt;int&gt;( e ), generic_category())</code>.</p>
</blockquote>
<pre>template &lt;class charT, class traits&gt;
@@ -677,8 +763,7 @@ bool operator!=( const error_condition &amp; condition, const error_code &amp; c
<h3><a name="Class-system_error">Class <code>
system_error</code></a></h3>
<p>The class <code>system_error</code> describes an exception object used to
report error conditions that have an associated error code. Such error
conditions typically originate from the operating system or other low-level
report errors that have an associated <code><a href="#Class-error_code">error_code</a></code>. Such errors typically originate from operating system or other low-level
application program interfaces.</p>
<blockquote>
<pre>namespace boost
@@ -689,10 +774,13 @@ application program interfaces.</p>
{
public:
system_error( error_code ec );
system_error( error_code ec, const char * what_arg );
system_error( error_code ec, const std::string &amp; what_arg );
system_error( error_code::value_type ev, const error_category &amp; ecat,
system_error( int ev, const error_category &amp; ecat,
const char * what_arg );
system_error( int ev, const error_category &amp; ecat,
const std::string &amp; what_arg );
system_error( error_code::value_type ev, const error_category &amp; ecat);
system_error( int ev, const error_category &amp; ecat);
const error_code &amp; code() const throw();
const char * what() const throw();
@@ -706,20 +794,33 @@ application program interfaces.</p>
<p><i>Postcondition:</i> <code>code() == ec <br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), &quot;&quot; ) == 0</code></p>
</blockquote>
<pre>system_error( error_code ec, const char * what_arg );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == ec <br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), what_arg ) == 0</code></p>
</blockquote>
<pre>system_error( error_code ec, const std::string &amp; what_arg );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == ec <br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), what_arg.c_str() ) == 0</code></p>
</blockquote>
<pre>system_error( error_code::value_type ev, const error_category &amp; ecat,
<pre>system_error( int ev, const error_category &amp; ecat,
const char * what_arg );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == error_code( ev, ecat )<br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), what_arg ) == 0</code></p>
</blockquote>
<pre>system_error( int ev, const error_category &amp; ecat,
const std::string &amp; what_arg );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == error_code( ev, ecat )<br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), what_arg.c_str() ) == 0</code></p>
</blockquote>
<pre>system_error( error_code::value_type ev, const error_category &amp; ecat );</pre>
<pre>system_error( int ev, const error_category &amp; ecat );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == error_code( ev, ecat )<br>
@@ -738,14 +839,15 @@ application program interfaces.</p>
</blockquote>
<hr>
<p>© Copyright Beman Dawes, 2006, 2007<br>
Distributed under the Boost Software License, Version 1.0. See
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->November 12, 2007<!--webbot bot="Timestamp" endspan i-checksum="39581" --> </font>
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->June 29, 2010<!--webbot bot="Timestamp" endspan i-checksum="14432" --> </font>
</p>
<p>© Copyright Beman Dawes, 2006, 2007, 2008</p>
<p>Distributed under the Boost Software License, Version 1.0. See
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
</body>
</html>

View File

@@ -0,0 +1,42 @@
// boost/system/api_config.hpp -------------------------------------------------------//
// 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.
//
// 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.
//
//--------------------------------------------------------------------------------------//
#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
// 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
# else
# define BOOST_POSIX_API
# endif
#endif // BOOST_SYSTEM_API_CONFIG_HPP

View File

@@ -1,4 +1,4 @@
// boost/system/config.hpp -------------------------------------------------//
// boost/system/config.hpp -----------------------------------------------------------//
// Copyright Beman Dawes 2003, 2006
@@ -11,47 +11,24 @@
#define BOOST_SYSTEM_CONFIG_HPP
#include <boost/config.hpp>
#include <boost/system/api_config.hpp> // for BOOST_POSIX_API or BOOST_WINDOWS_API
// BOOST_POSIX_API or BOOST_WINDOWS_API specify which API to use.
// If not specified, a sensible default will be applied.
// This header implements separate compilation features as described in
// http://www.boost.org/more/separate_compilation.html
# 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 or static linking as requested --------------------------------------//
// enable dynamic linking on Windows ---------------------------------------//
//# if (defined(BOOST_ALL_DYN_LINK) || defined(BOOST_SYSTEM_DYN_LINK)) && defined(__BORLANDC__) && defined(__WIN32__)
//# error Dynamic linking Boost.System 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)
# if defined(BOOST_SYSTEM_SOURCE)
# define BOOST_SYSTEM_DECL BOOST_SYMBOL_EXPORT
# else
# define BOOST_SYSTEM_DECL BOOST_SYMBOL_IMPORT
# endif
#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
# define BOOST_SYSTEM_DECL
#endif
// enable automatic library variant selection ------------------------------//
// enable automatic library variant selection ----------------------------------------//
#if !defined(BOOST_SYSTEM_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_SYSTEM_NO_LIB)
//

View File

@@ -23,7 +23,7 @@ namespace boost
{
// To construct an error_code after a API error:
//
// error_code( errno, system_category )
// error_code( errno, system_category() )
// User code should use the portable "posix" enums for POSIX errors; this
// allows such code to be portable to non-POSIX systems. For the non-POSIX
@@ -46,7 +46,7 @@ namespace boost
namespace cygwin_error
{
inline error_code make_error_code( cygwin_errno e )
{ return error_code( e, get_system_category() ); }
{ return error_code( e, system_category() ); }
}
}
}

View File

@@ -47,11 +47,11 @@ namespace boost
template< class T >
struct is_error_condition_enum { static const bool value = false; };
// portable error_conditions -------------------------------------------//
// generic error_conditions --------------------------------------------//
namespace posix_error
namespace errc
{
enum posix_errno
enum errc_t
{
success = 0,
address_family_not_supported = EAFNOSUPPORT,
@@ -129,18 +129,19 @@ namespace boost
too_many_files_open_in_system = ENFILE,
too_many_files_open = EMFILE,
too_many_links = EMLINK,
too_many_synbolic_link_levels = ELOOP,
too_many_symbolic_link_levels = ELOOP,
value_too_large = EOVERFLOW,
wrong_protocol_type = EPROTOTYPE
};
} // namespace posix_error
} // namespace errc
# ifndef BOOST_SYSTEM_NO_DEPRECATED
namespace posix = posix_error;
namespace posix = errc;
namespace posix_error = errc;
# endif
template<> struct is_error_condition_enum<posix_error::posix_errno>
template<> struct is_error_condition_enum<errc::errc_t>
{ static const bool value = true; };
@@ -182,11 +183,14 @@ namespace boost
{
public:
virtual ~error_category(){}
virtual inline const char * name() const; // see implementation note below
virtual inline std::string message( int ev ) const; // see implementation note below
virtual inline error_condition default_error_condition( int ev ) const;
virtual inline bool equivalent( int code, const error_condition & condition ) const;
virtual inline bool equivalent( const error_code & code, int condition ) const;
virtual const char * name() const = 0;
virtual std::string message( int ev ) const = 0;
virtual error_condition default_error_condition( int ev ) const;
virtual bool equivalent( int code,
const error_condition & condition ) const;
virtual bool equivalent( const error_code & code,
int condition ) const;
bool operator==(const error_category & rhs) const { return this == &rhs; }
bool operator!=(const error_category & rhs) const { return this != &rhs; }
@@ -198,33 +202,35 @@ namespace boost
// predefined error categories -----------------------------------------//
BOOST_SYSTEM_DECL const error_category & get_system_category();
BOOST_SYSTEM_DECL const error_category & get_posix_category();
BOOST_SYSTEM_DECL const error_category & system_category();
BOOST_SYSTEM_DECL const error_category & generic_category();
// deprecated synonyms --------------------------------------------------//
static const error_category & system_category = get_system_category();
static const error_category & posix_category = get_posix_category();
# ifndef BOOST_SYSTEM_NO_DEPRECATED
// deprecated synonyms
static const error_category & errno_ecat = get_posix_category();
static const error_category & native_ecat = get_system_category();
inline const error_category & get_system_category() { return system_category(); }
inline const error_category & get_generic_category() { return generic_category(); }
inline const error_category & get_posix_category() { return generic_category(); }
static const error_category & posix_category = generic_category();
static const error_category & errno_ecat = generic_category();
static const error_category & native_ecat = system_category();
# endif
// class error_condition -----------------------------------------------//
// error_conditions are portable, error_codes are system or lib specific
// error_conditions are portable, error_codes are system or library specific
class error_condition
{
public:
// constructors:
error_condition() : m_val(0), m_cat(&get_posix_category()) {}
error_condition() : m_val(0), m_cat(&generic_category()) {}
error_condition( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {}
template <class ConditionEnum>
error_condition(ConditionEnum e,
typename boost::enable_if<is_error_condition_enum<ConditionEnum> >::type* = 0)
template <class ErrorConditionEnum>
error_condition(ErrorConditionEnum e,
typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum> >::type* = 0)
{
*this = make_error_condition(e);
}
@@ -237,9 +243,9 @@ namespace boost
m_cat = &cat;
}
template<typename ConditionEnum>
typename boost::enable_if<is_error_condition_enum<ConditionEnum>, error_condition>::type &
operator=( ConditionEnum val )
template<typename ErrorConditionEnum>
typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum>, error_condition>::type &
operator=( ErrorConditionEnum val )
{
*this = make_error_condition(val);
return *this;
@@ -248,7 +254,7 @@ namespace boost
void clear()
{
m_val = 0;
m_cat = &get_posix_category();
m_cat = &generic_category();
}
// observers:
@@ -306,12 +312,12 @@ namespace boost
public:
// constructors:
error_code() : m_val(0), m_cat(&get_system_category()) {}
error_code() : m_val(0), m_cat(&system_category()) {}
error_code( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {}
template <class CodeEnum>
error_code(CodeEnum e,
typename boost::enable_if<is_error_code_enum<CodeEnum> >::type* = 0)
template <class ErrorCodeEnum>
error_code(ErrorCodeEnum e,
typename boost::enable_if<is_error_code_enum<ErrorCodeEnum> >::type* = 0)
{
*this = make_error_code(e);
}
@@ -323,9 +329,9 @@ namespace boost
m_cat = &cat;
}
template<typename CodeEnum>
typename boost::enable_if<is_error_code_enum<CodeEnum>, error_code>::type &
operator=( CodeEnum val )
template<typename ErrorCodeEnum>
typename boost::enable_if<is_error_code_enum<ErrorCodeEnum>, error_code>::type &
operator=( ErrorCodeEnum val )
{
*this = make_error_code(val);
return *this;
@@ -334,7 +340,7 @@ namespace boost
void clear()
{
m_val = 0;
m_cat = &get_system_category();
m_cat = &system_category();
}
// observers:
@@ -380,6 +386,31 @@ namespace boost
};
// predefined error_code object used as "throw on error" tag
# ifndef BOOST_SYSTEM_NO_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
namespace detail { inline system::error_code * throws() { return 0; } }
// Misuse of the error_code object is turned into a noisy failure by
// poisoning the reference. This particular implementation doesn't
// produce warnings or errors from popular compilers, is very efficient
// (as determined by inspecting generated code), and does not suffer
// from order of initialization problems. In practice, it also seems
// cause user function error handling implementation errors to be detected
// very early in the development cycle.
inline system::error_code & throws()
{ return *detail::throws(); }
namespace system
{
// non-member functions ------------------------------------------------//
inline bool operator!=( const error_code & lhs,
@@ -436,17 +467,17 @@ namespace boost
+ reinterpret_cast<std::size_t>(&ec.category());
}
// make_* functions for posix_error::posix_errno -----------------------------//
// make_* functions for errc::errc_t -----------------------------//
namespace posix_error
namespace errc
{
// explicit conversion:
inline error_code make_error_code( posix_errno e )
{ return error_code( e, get_posix_category() ); }
inline error_code make_error_code( errc_t e )
{ return error_code( e, generic_category() ); }
// implicit conversion:
inline error_condition make_error_condition( posix_errno e )
{ return error_condition( e, get_posix_category() ); }
inline error_condition make_error_condition( errc_t e )
{ return error_condition( e, generic_category() ); }
}
// error_category default implementation -------------------------------//
@@ -468,19 +499,6 @@ namespace boost
return *this == code.category() && code.value() == condition;
}
// error_category implementation note: VC++ 8.0 objects to name() and
// message() being pure virtual functions. Thus these implementations.
inline const char * error_category::name() const
{
return "error: should never be called";
}
inline std::string error_category::message( int ) const
{
static std::string s("error: should never be called");
return s;
}
} // namespace system
} // namespace boost

View File

@@ -23,7 +23,7 @@ namespace boost
{
// To construct an error_code after a API error:
//
// error_code( errno, system_category )
// error_code( errno, system_category() )
// User code should use the portable "posix" enums for POSIX errors; this
// allows such code to be portable to non-POSIX systems. For the non-POSIX
@@ -99,7 +99,7 @@ namespace boost
namespace linux_error
{
inline error_code make_error_code( linux_errno e )
{ return error_code( e, get_system_category() ); }
{ return error_code( e, system_category() ); }
}
} // namespace system

View File

@@ -17,20 +17,32 @@ namespace boost
{
namespace system
{
// class system_error --------------------------------------------------//
// class system_error ------------------------------------------------------------//
class system_error : public std::runtime_error
class BOOST_SYMBOL_VISIBLE system_error : public std::runtime_error
// BOOST_SYMBOL_VISIBLE is needed by GCC to ensure system_error thrown from a shared
// library can be caught. See svn.boost.org/trac/boost/ticket/3697
{
public:
system_error( error_code ec )
: std::runtime_error(""), m_error_code(ec) {}
system_error( error_code ec, const std::string & what_arg )
: std::runtime_error(what_arg), m_error_code(ec) {}
system_error( error_code ec, const char* what_arg )
: std::runtime_error(what_arg), m_error_code(ec) {}
system_error( int ev, const error_category & ecat )
: std::runtime_error(""), m_error_code(ev,ecat) {}
system_error( int ev, const error_category & ecat,
const std::string & what_arg )
: std::runtime_error(what_arg), m_error_code(ev,ecat) {}
system_error( int ev, const error_category & ecat )
: std::runtime_error(""), m_error_code(ev,ecat) {}
system_error( int ev, const error_category & ecat,
const char * what_arg )
: std::runtime_error(what_arg), m_error_code(ev,ecat) {}
virtual ~system_error() throw() {}
@@ -52,11 +64,8 @@ namespace boost
try
{
m_what = this->std::runtime_error::what();
if ( m_error_code )
{
if ( !m_what.empty() ) m_what += ": ";
m_what += m_error_code.message();
}
if ( !m_what.empty() ) m_what += ": ";
m_what += m_error_code.message();
}
catch (...) { return std::runtime_error::what(); }
}

View File

@@ -29,7 +29,7 @@ namespace boost
// To construct an error_code after a API error:
//
// error_code( ::GetLastError(), system_category )
// error_code( ::GetLastError(), system_category() )
namespace windows_error
{
@@ -107,7 +107,7 @@ namespace boost
namespace windows_error
{
inline error_code make_error_code( windows_error_code e )
{ return error_code( e, get_system_category() ); }
{ return error_code( e, system_category() ); }
}
} // namespace system

View File

@@ -9,14 +9,7 @@
//----------------------------------------------------------------------------//
// VC++ 8.0 warns on usage of certain Standard Library and API functions that
// can be cause buffer overruns or other possible security issues if misused.
// See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
// But the wording of the warning is misleading and unsettling, there are no
// portable alternative functions, and VC++ 8.0's own libraries use the
// functions in question. So turn off the warnings.
#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_DEPRECATE
#include <boost/config/warning_disable.hpp>
// define BOOST_SYSTEM_SOURCE so that <boost/system/config.hpp> knows
// the library is being built (possibly exporting rather than importing code)
@@ -30,14 +23,15 @@
#include <cassert>
using namespace boost::system;
using namespace boost::system::posix_error;
using namespace boost::system::errc;
#include <cstring> // for strerror/strerror_r
# if defined( BOOST_WINDOWS_API )
# include <windows.h>
# include "local_free_on_destruction.hpp"
# ifndef ERROR_INCORRECT_SIZE
# define ERROR_INCORRECT_SIZE ERROR_BAD_ARGUMENTS
# define ERROR_INCORRECT_SIZE ERROR_BAD_ARGUMENTS
# endif
# endif
@@ -45,12 +39,12 @@ using namespace boost::system::posix_error;
namespace
{
// standard error categories -------------------------------------------//
// standard error categories ---------------------------------------------//
class posix_error_category : public error_category
class generic_error_category : public error_category
{
public:
posix_error_category(){}
generic_error_category(){}
const char * name() const;
std::string message( int ev ) const;
};
@@ -64,15 +58,16 @@ namespace
error_condition default_error_condition( int ev ) const;
};
// posix_error_category implementation ---------------------------------//
// generic_error_category implementation ---------------------------------//
const char * posix_error_category::name() const
const char * generic_error_category::name() const
{
return "POSIX";
return "generic";
}
std::string posix_error_category::message( int ev ) const
std::string generic_error_category::message( int ev ) const
{
static std::string unknown_err( "Unknown error" );
// strerror_r is preferred because it is always thread safe,
// however, we fallback to strerror in certain cases because:
// -- Windows doesn't provide strerror_r.
@@ -86,17 +81,22 @@ namespace
# if defined(BOOST_WINDOWS_API) || defined(__hpux) || defined(__sun)\
|| (defined(__linux) && (!defined(__USE_XOPEN2K) || defined(BOOST_SYSTEM_USE_STRERROR)))\
|| (defined(__osf__) && !defined(_REENTRANT))\
|| (defined(__vms))
|| (defined(__vms))\
|| (defined(__QNXNTO__))
const char * c_str = std::strerror( ev );
return std::string( c_str ? c_str : "Unknown error" );
# else
return c_str
? std::string( c_str )
: unknown_err;
# else // use strerror_r
char buf[64];
char * bp = buf;
std::size_t sz = sizeof(buf);
# if defined(__CYGWIN__) || defined(__USE_GNU)
// Oddball version of strerror_r
const char * c_str = strerror_r( ev, bp, sz );
return std::string( c_str ? c_str : "Unknown error" );
return c_str
? std::string( c_str )
: unknown_err;
# else
// POSIX version of strerror_r
int result;
@@ -107,7 +107,9 @@ namespace
# if defined (__sgi)
const char * c_str = strerror( ev );
result = 0;
return std::string( c_str ? c_str : "Unknown error" );
return c_str
? std::string( c_str )
: unknown_err;
# else
result = strerror_r( ev, bp, sz );
# endif
@@ -120,26 +122,31 @@ namespace
result = errno;
# endif
if ( result != ERANGE ) break;
if ( sz > sizeof(buf) ) std::free( bp );
sz *= 2;
if ( (bp = static_cast<char*>(std::malloc( sz ))) == 0 )
return std::string( "ENOMEM" );
if ( sz > sizeof(buf) ) std::free( bp );
sz *= 2;
if ( (bp = static_cast<char*>(std::malloc( sz ))) == 0 )
return std::string( "ENOMEM" );
}
}
std::string msg;
try
{
std::string msg( ( result == invalid_argument ) ? "Unknown error" : bp );
if ( sz > sizeof(buf) ) std::free( bp );
sz = 0;
return msg;
msg = ( ( result == invalid_argument ) ? "Unknown error" : bp );
}
# ifndef BOOST_NO_EXCEPTIONS
// See ticket #2098
catch(...)
{
if ( sz > sizeof(buf) ) std::free( bp );
throw;
// just eat the exception
}
# endif
# endif
# endif
if ( sz > sizeof(buf) ) std::free( bp );
sz = 0;
return msg;
# endif // else POSIX version of strerror_r
# endif // else use strerror_r
}
// system_error_category implementation --------------------------------//
@@ -153,7 +160,7 @@ namespace
switch ( ev )
{
case 0: return make_error_condition( success );
# if defined(BOOST_POSIX_API)
# if defined(BOOST_POSIX_API)
// POSIX-like O/S -> posix_errno decode table ---------------------------//
case E2BIG: return make_error_condition( argument_list_too_long );
case EACCES: return make_error_condition( permission_denied );
@@ -161,7 +168,9 @@ namespace
case EADDRNOTAVAIL: return make_error_condition( address_not_available );
case EAFNOSUPPORT: return make_error_condition( address_family_not_supported );
case EAGAIN: return make_error_condition( resource_unavailable_try_again );
# if EALREADY != EBUSY // EALREADY and EBUSY are the same on QNX Neutrino
case EALREADY: return make_error_condition( connection_already_in_progress );
# endif
case EBADF: return make_error_condition( bad_file_descriptor );
case EBADMSG: return make_error_condition( bad_message );
case EBUSY: return make_error_condition( device_or_resource_busy );
@@ -185,7 +194,7 @@ namespace
case EIO: return make_error_condition( io_error );
case EISCONN: return make_error_condition( already_connected );
case EISDIR: return make_error_condition( is_a_directory );
case ELOOP: return make_error_condition( too_many_synbolic_link_levels );
case ELOOP: return make_error_condition( too_many_symbolic_link_levels );
case EMFILE: return make_error_condition( too_many_files_open );
case EMLINK: return make_error_condition( too_many_links );
case EMSGSIZE: return make_error_condition( message_size );
@@ -213,7 +222,9 @@ namespace
# if ENOTEMPTY != EEXIST // AIX treats ENOTEMPTY and EEXIST as the same value
case ENOTEMPTY: return make_error_condition( directory_not_empty );
# endif // ENOTEMPTY != EEXIST
case ENOTRECOVERABLE: return make_error_condition( state_not_recoverable );
# if ENOTRECOVERABLE != ECONNRESET // the same on some Broadcom chips
case ENOTRECOVERABLE: return make_error_condition( state_not_recoverable );
# endif // ENOTRECOVERABLE != ECONNRESET
case ENOTSOCK: return make_error_condition( not_a_socket );
case ENOTSUP: return make_error_condition( not_supported );
case ENOTTY: return make_error_condition( inappropriate_io_control_operation );
@@ -222,7 +233,9 @@ namespace
case EOPNOTSUPP: return make_error_condition( operation_not_supported );
# endif // EOPNOTSUPP != ENOTSUP
case EOVERFLOW: return make_error_condition( value_too_large );
case EOWNERDEAD: return make_error_condition( owner_dead );
# if EOWNERDEAD != ECONNABORTED // the same on some Broadcom chips
case EOWNERDEAD: return make_error_condition( owner_dead );
# endif // EOWNERDEAD != ECONNABORTED
case EPERM: return make_error_condition( operation_not_permitted );
case EPIPE: return make_error_condition( broken_pipe );
case EPROTO: return make_error_condition( protocol_error );
@@ -317,7 +330,7 @@ namespace
case WSAETIMEDOUT: return make_error_condition( timed_out );
case WSAEWOULDBLOCK: return make_error_condition( operation_would_block );
#endif
default: return error_condition( ev, system_category );
default: return error_condition( ev, system_category() );
}
}
@@ -325,28 +338,14 @@ namespace
std::string system_error_category::message( int ev ) const
{
return posix_category.message( ev );
return generic_category().message( ev );
}
# else
// TODO:
//Some quick notes on the implementation (sorry for the noise if
//someone has already mentioned them):
//
//- The ::LocalFree() usage isn't exception safe.
//
//See:
//
//<http://boost.cvs.sourceforge.net/boost/boost/boost/asio/system_exception.hpp?revision=1.1&view=markup>
//
//in the implementation of what() for an example.
//
//Cheers,
//Chris
std::string system_error_category::message( int ev ) const
{
# ifndef BOOST_NO_ANSI_APIS
LPVOID lpMsgBuf;
LPVOID lpMsgBuf = 0;
DWORD retval = ::FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
@@ -358,13 +357,13 @@ namespace
0,
NULL
);
detail::local_free_on_destruction lfod(lpMsgBuf);
if (retval == 0)
return std::string("Unknown error");
std::string str( static_cast<LPCSTR>(lpMsgBuf) );
::LocalFree( lpMsgBuf ); // free the buffer
# else // WinCE workaround
LPVOID lpMsgBuf;
LPVOID lpMsgBuf = 0;
DWORD retval = ::FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
@@ -376,6 +375,7 @@ namespace
0,
NULL
);
detail::local_free_on_destruction lfod(lpMsgBuf);
if (retval == 0)
return std::string("Unknown error");
@@ -385,7 +385,6 @@ namespace
return std::string("Unknown error");
std::string str( narrow_buffer );
::LocalFree( lpMsgBuf ); // free the buffer
# endif
while ( str.size()
&& (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') )
@@ -403,16 +402,24 @@ namespace boost
namespace system
{
BOOST_SYSTEM_DECL const error_category & get_system_category()
# ifndef BOOST_SYSTEM_NO_DEPRECATED
BOOST_SYSTEM_DECL error_code throws; // "throw on error" special error_code;
// note that it doesn't matter if this
// isn't initialized before use since
// the only use is to take its
// address for comparison purposes
# endif
BOOST_SYSTEM_DECL const error_category & system_category()
{
static const system_error_category system_category_const;
return system_category_const;
}
BOOST_SYSTEM_DECL const error_category & get_posix_category()
BOOST_SYSTEM_DECL const error_category & generic_category()
{
static const posix_error_category posix_category_const;
return posix_category_const;
static const generic_error_category generic_category_const;
return generic_category_const;
}
} // namespace system

View File

@@ -0,0 +1,40 @@
// local_free_on_exit.hpp ------------------------------------------------------------//
// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2010 Beman Dawes
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// This is derived from boost/asio/detail/local_free_on_block_exit.hpp to avoid
// a dependency on asio. Thanks to Chris Kohlhoff for pointing it out.
#ifndef BOOST_SYSTEM_LOCAL_FREE_ON_EXIT_HPP
#define BOOST_SYSTEM_LOCAL_FREE_ON_EXIT_HPP
namespace boost {
namespace system {
namespace detail {
class local_free_on_destruction
{
public:
explicit local_free_on_destruction(void* p)
: p_(p) {}
~local_free_on_destruction()
{
::LocalFree(p_);
}
private:
void* p_;
local_free_on_destruction(const local_free_on_destruction&); // = deleted
local_free_on_destruction& operator=(const local_free_on_destruction&); // = deleted
};
} // namespace detail
} // namespace system
} // namespace boost
#endif // BOOST_SYSTEM_LOCAL_FREE_ON_EXIT_HPP

View File

@@ -10,40 +10,42 @@
project
: requirements
<library>/boost/system//boost_system
<define>BOOST_ALL_NO_LIB
<toolset>msvc:<asynch-exceptions>on
;
lib throw_test
: throw_test.cpp
: <link>shared:<define>BOOST_SYSTEM_DYN_LINK=1
;
test-suite "system"
: [ run error_code_test.cpp
: # command line
: # input files
: # requirements
<define>BOOST_SYSTEM_STATIC_LINK
<link>static
]
[ run error_code_test.cpp
: : : <define>BOOST_SYSTEM_DYN_LINK
: error_code_test_dll
: : : <link>shared : error_code_test_shared
]
[ run error_code_user_test.cpp
: : : <define>BOOST_SYSTEM_STATIC_LINK
<link>static
: : : <link>static
]
[ run error_code_user_test.cpp
: : : <define>BOOST_SYSTEM_DYN_LINK
: error_code_user_test_dll
: : : <link>shared : error_code_user_test_shared
]
[ run system_error_test.cpp
: : : <define>BOOST_SYSTEM_STATIC_LINK
<link>static
: : : <link>static
]
[ run system_error_test.cpp
: : : <define>BOOST_SYSTEM_DYN_LINK
: system_error_test_dll
: : : <link>shared : system_error_test_shared
]
[ run dynamic_link_test.cpp throw_test
: : : <link>shared : throw_test_shared
]
[ run initialization_test.cpp
: : : <define>BOOST_SYSTEM_DYN_LINK
: : : <link>shared : initialization_test_shared
]
[ run header_only_test.cpp
: : : <link>static

View File

@@ -0,0 +1,55 @@
// dynamic_link_test.cpp -------------------------------------------------------------//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// See www.boost.org/LICENSE_1_0.txt
// Library home page is www.boost.org/libs/system
//--------------------------------------------------------------------------------------//
// Dynamic link libraries (DLL's), also know as dynamic shared objects (DSO's),
// can cause symbol visability problems unless carefully configured. One of the
// manifestations, particularly with GCC, is that a system_error exception thrown from
// a DLL or DSO is not caught.
//
// The purpose of this program is to test for that error.
//--------------------------------------------------------------------------------------//
#include <boost/system/system_error.hpp>
#include <iostream>
namespace boost
{
namespace system
{
BOOST_SYSTEM_DECL void throw_test();
}
}
int main()
{
try
{
boost::system::throw_test();
}
catch (const boost::system::system_error& ex)
{
std::cout << " caught boost::system::system_error as expected\n";
std::cout << " what() reports " << ex.what() << '\n';
return 0;
}
catch (const std::runtime_error& ex)
{
std::cout << " error: caught std::runtime_error instead of boost::system::system_error\n";
std::cout << " what() reports " << ex.what() << '\n';
return 1;
}
std::cout << " error: failed to catch boost::system::system_error\n";
return 1;
}

View File

@@ -7,18 +7,14 @@
// See library home page at http://www.boost.org/libs/system
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
// VC++ 8.0 warns on usage of certain Standard Library and API functions that
// can cause buffer overruns or other possible security issues if misused.
// See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
// But the wording of the warning is misleading and unsettling, there are no
// portable alternative functions, and VC++ 8.0's own libraries use the
// functions in question. So turn off the warnings.
#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_DEPRECATE
// test without deprecated features
#define BOOST_SYSTEM_NO_DEPRECATED
#include <boost/test/minimal.hpp>
#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/cygwin_error.hpp>
#include <boost/system/linux_error.hpp>
@@ -52,221 +48,232 @@ namespace
ss << ec;
ss >> s;
BOOST_CHECK( s == expected );
BOOST_TEST( s == expected );
}
}
// test_main ---------------------------------------------------------------//
// main ------------------------------------------------------------------------------//
// TODO: add hash_value tests
int test_main( int, char ** )
int main( int, char ** )
{
std::cout << "Conversion use cases...\n";
error_condition x1( errc::file_exists );
//error_code x2( errc::file_exists ); // should fail to compile
make_error_code(errc::file_exists);
make_error_condition(errc::file_exists);
std::cout << "General tests...\n";
// unit tests:
BOOST_CHECK( posix_category == posix_category );
BOOST_CHECK( system_category == system_category );
BOOST_CHECK( posix_category != system_category );
BOOST_CHECK( system_category != posix_category );
BOOST_TEST( generic_category() == generic_category() );
BOOST_TEST( system_category() == system_category() );
BOOST_TEST( generic_category() != system_category() );
BOOST_TEST( system_category() != generic_category() );
if ( std::less<const error_category*>()( &posix_category, &system_category ) )
if ( std::less<const error_category*>()( &generic_category(), &system_category() ) )
{
BOOST_CHECK( posix_category < system_category );
BOOST_CHECK( !(system_category < posix_category) );
BOOST_TEST( generic_category() < system_category() );
BOOST_TEST( !(system_category() < generic_category()) );
}
else
{
BOOST_CHECK( system_category < posix_category );
BOOST_CHECK( !(posix_category < system_category) );
BOOST_TEST( system_category() < generic_category() );
BOOST_TEST( !(generic_category() < system_category()) );
}
error_code ec;
error_condition dec;
BOOST_CHECK( !ec );
BOOST_CHECK( ec.value() == 0 );
dec = ec.default_error_condition();
BOOST_CHECK( dec.value() == 0 );
BOOST_CHECK( dec.category() == posix_category );
BOOST_CHECK( ec == posix::success );
BOOST_CHECK( ec.category() == system_category );
BOOST_CHECK( std::strcmp( ec.category().name(), "system") == 0 );
BOOST_CHECK( !(ec < error_code( 0, system_category )) );
BOOST_CHECK( !(error_code( 0, system_category ) < ec) );
BOOST_CHECK( ec < error_code( 1, system_category ) );
BOOST_CHECK( !(error_code( 1, system_category ) < ec) );
error_condition econd;
BOOST_TEST( !ec );
BOOST_TEST( ec.value() == 0 );
econd = ec.default_error_condition();
BOOST_TEST( econd.value() == 0 );
BOOST_TEST( econd.category() == generic_category() );
BOOST_TEST( ec == errc::success );
BOOST_TEST( ec.category() == system_category() );
BOOST_TEST( std::strcmp( ec.category().name(), "system") == 0 );
BOOST_TEST( !(ec < error_code( 0, system_category() )) );
BOOST_TEST( !(error_code( 0, system_category() ) < ec) );
BOOST_TEST( ec < error_code( 1, system_category() ) );
BOOST_TEST( !(error_code( 1, system_category() ) < ec) );
error_code ec_0_system( 0, system_category );
BOOST_CHECK( !ec_0_system );
BOOST_CHECK( ec_0_system.value() == 0 );
dec = ec_0_system.default_error_condition();
BOOST_CHECK( dec.value() == 0 );
BOOST_CHECK( dec.category() == posix_category );
BOOST_CHECK( ec_0_system == posix::success );
BOOST_CHECK( ec_0_system.category() == system_category );
BOOST_CHECK( std::strcmp( ec_0_system.category().name(), "system") == 0 );
error_code ec_0_system( 0, system_category() );
BOOST_TEST( !ec_0_system );
BOOST_TEST( ec_0_system.value() == 0 );
econd = ec_0_system.default_error_condition();
BOOST_TEST( econd.value() == 0 );
BOOST_TEST( econd.category() == generic_category() );
BOOST_TEST( ec_0_system == errc::success );
BOOST_TEST( ec_0_system.category() == system_category() );
BOOST_TEST( std::strcmp( ec_0_system.category().name(), "system") == 0 );
check_ostream( ec_0_system, "system:0" );
BOOST_CHECK( ec_0_system == ec );
BOOST_TEST( ec_0_system == ec );
error_code ec_1_system( 1, system_category );
BOOST_CHECK( ec_1_system );
BOOST_CHECK( ec_1_system.value() == 1 );
BOOST_CHECK( ec_1_system.value() != 0 );
BOOST_CHECK( ec != ec_1_system );
BOOST_CHECK( ec_0_system != ec_1_system );
error_code ec_1_system( 1, system_category() );
BOOST_TEST( ec_1_system );
BOOST_TEST( ec_1_system.value() == 1 );
BOOST_TEST( ec_1_system.value() != 0 );
BOOST_TEST( ec != ec_1_system );
BOOST_TEST( ec_0_system != ec_1_system );
check_ostream( ec_1_system, "system:1" );
ec = error_code( BOOST_ACCESS_ERROR_MACRO, system_category );
BOOST_CHECK( ec );
BOOST_CHECK( ec.value() == BOOST_ACCESS_ERROR_MACRO );
dec = ec.default_error_condition();
BOOST_CHECK( dec.value() == static_cast<int>(posix::permission_denied) );
BOOST_CHECK( dec.category() == posix_category );
BOOST_CHECK( dec == error_condition( posix::permission_denied, posix_category ) );
BOOST_CHECK( dec == posix::permission_denied );
BOOST_CHECK( posix::permission_denied == dec );
BOOST_CHECK( ec == posix::permission_denied );
BOOST_CHECK( ec.category() == system_category );
BOOST_CHECK( std::strcmp( ec.category().name(), "system") == 0 );
ec = error_code( BOOST_ACCESS_ERROR_MACRO, system_category() );
BOOST_TEST( ec );
BOOST_TEST( ec.value() == BOOST_ACCESS_ERROR_MACRO );
econd = ec.default_error_condition();
BOOST_TEST( econd.value() == static_cast<int>(errc::permission_denied) );
BOOST_TEST( econd.category() == generic_category() );
BOOST_TEST( econd == error_condition( errc::permission_denied, generic_category() ) );
BOOST_TEST( econd == errc::permission_denied );
BOOST_TEST( errc::permission_denied == econd );
BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( ec.category() == system_category() );
BOOST_TEST( std::strcmp( ec.category().name(), "system") == 0 );
// test the explicit make_error_code conversion for posix
ec = make_error_code( posix::bad_message );
BOOST_CHECK( ec );
BOOST_CHECK( ec == posix::bad_message );
BOOST_CHECK( posix::bad_message == ec );
BOOST_CHECK( ec != posix::permission_denied );
BOOST_CHECK( posix::permission_denied != ec );
BOOST_CHECK( ec.category() == posix_category );
// test the explicit make_error_code conversion for errc
ec = make_error_code( errc::bad_message );
BOOST_TEST( ec );
BOOST_TEST( ec == errc::bad_message );
BOOST_TEST( errc::bad_message == ec );
BOOST_TEST( ec != errc::permission_denied );
BOOST_TEST( errc::permission_denied != ec );
BOOST_TEST( ec.category() == generic_category() );
// test the deprecated predefined error_category synonyms
BOOST_CHECK( &system_category == &native_ecat );
BOOST_CHECK( &posix_category == &errno_ecat );
BOOST_CHECK( system_category == native_ecat );
BOOST_CHECK( posix_category == errno_ecat );
//// test the deprecated predefined error_category synonyms
//BOOST_TEST( &system_category() == &native_ecat );
//BOOST_TEST( &generic_category() == &errno_ecat );
//BOOST_TEST( system_category() == native_ecat );
//BOOST_TEST( generic_category() == errno_ecat );
// test error_code and error_condition message();
// see Boost.Filesystem operations_test for code specific message() tests
ec = error_code( -1, system_category );
ec = error_code( -1, system_category() );
std::cout << "error_code message for -1 is \"" << ec.message() << "\"\n";
std::cout << "error_code message for 0 is \"" << ec_0_system.message() << "\"\n";
#if defined(BOOST_WINDOWS_API)
// Borland appends newline, so just check text
BOOST_CHECK( ec.message().substr(0,13) == "Unknown error" );
BOOST_TEST( ec.message().substr(0,13) == "Unknown error" );
BOOST_TEST( ec_0_system.message().substr(0,36) == "The operation completed successfully" );
#elif defined(linux) || defined(__linux) || defined(__linux__)
// Linux appends value to message as unsigned, so it varies with # of bits
BOOST_CHECK( ec.message().substr(0,13) == "Unknown error" );
BOOST_TEST( ec.message().substr(0,13) == "Unknown error" );
#elif defined(__hpux)
BOOST_CHECK( ec.message() == "" );
BOOST_TEST( ec.message() == "" );
#elif defined(__osf__)
BOOST_CHECK( ec.message() == "Error -1 occurred." );
BOOST_TEST( ec.message() == "Error -1 occurred." );
#elif defined(__vms)
BOOST_CHECK( ec.message() == "error -1" );
BOOST_TEST( ec.message() == "error -1" );
#endif
ec = error_code( BOOST_ACCESS_ERROR_MACRO, system_category );
BOOST_CHECK( ec.message() != "" );
BOOST_CHECK( ec.message().substr( 0, 13) != "Unknown error" );
ec = error_code( BOOST_ACCESS_ERROR_MACRO, system_category() );
BOOST_TEST( ec.message() != "" );
BOOST_TEST( ec.message().substr( 0, 13) != "Unknown error" );
dec = error_condition( -1, posix_category );
std::cout << "error_condition message for -1 is \"" << dec.message() << "\"\n";
econd = error_condition( -1, generic_category() );
error_condition econd_ok;
std::cout << "error_condition message for -1 is \"" << econd.message() << "\"\n";
std::cout << "error_condition message for 0 is \"" << econd_ok.message() << "\"\n";
#if defined(BOOST_WINDOWS_API)
// Borland appends newline, so just check text
BOOST_CHECK( dec.message().substr(0,13) == "Unknown error" );
BOOST_TEST( econd.message().substr(0,13) == "Unknown error" );
BOOST_TEST( econd_ok.message().substr(0,8) == "No error" );
#elif defined(linux) || defined(__linux) || defined(__linux__)
// Linux appends value to message as unsigned, so it varies with # of bits
BOOST_CHECK( dec.message().substr(0,13) == "Unknown error" );
BOOST_TEST( econd.message().substr(0,13) == "Unknown error" );
#elif defined(__hpux)
BOOST_CHECK( dec.message() == "" );
BOOST_TEST( econd.message() == "" );
#elif defined(__osf__)
BOOST_CHECK( dec.message() == "Error -1 occurred." );
BOOST_TEST( econd.message() == "Error -1 occurred." );
#elif defined(__vms)
BOOST_CHECK( dec.message() == "error -1" );
BOOST_TEST( econd.message() == "error -1" );
#endif
dec = error_condition( BOOST_ACCESS_ERROR_MACRO, posix_category );
BOOST_CHECK( dec.message() != "" );
BOOST_CHECK( dec.message().substr( 0, 13) != "Unknown error" );
econd = error_condition( BOOST_ACCESS_ERROR_MACRO, generic_category() );
BOOST_TEST( econd.message() != "" );
BOOST_TEST( econd.message().substr( 0, 13) != "Unknown error" );
#ifdef BOOST_WINDOWS_API
std::cout << "Windows tests...\n";
// these tests probe the Windows posix decoder
// these tests probe the Windows errc decoder
// test the first entry in the decoder table:
ec = error_code( ERROR_ACCESS_DENIED, system_category );
BOOST_CHECK( ec.value() == ERROR_ACCESS_DENIED );
BOOST_CHECK( ec == posix::permission_denied );
BOOST_CHECK( ec.default_error_condition().value() == posix::permission_denied );
BOOST_CHECK( ec.default_error_condition().category() == posix_category );
ec = error_code( ERROR_ACCESS_DENIED, system_category() );
BOOST_TEST( ec.value() == ERROR_ACCESS_DENIED );
BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().value() == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test the second entry in the decoder table:
ec = error_code( ERROR_ALREADY_EXISTS, system_category );
BOOST_CHECK( ec.value() == ERROR_ALREADY_EXISTS );
BOOST_CHECK( ec == posix::file_exists );
BOOST_CHECK( ec.default_error_condition().value() == posix::file_exists );
BOOST_CHECK( ec.default_error_condition().category() == posix_category );
ec = error_code( ERROR_ALREADY_EXISTS, system_category() );
BOOST_TEST( ec.value() == ERROR_ALREADY_EXISTS );
BOOST_TEST( ec == errc::file_exists );
BOOST_TEST( ec.default_error_condition().value() == errc::file_exists );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test the third entry in the decoder table:
ec = error_code( ERROR_BAD_UNIT, system_category );
BOOST_CHECK( ec.value() == ERROR_BAD_UNIT );
BOOST_CHECK( ec == posix::no_such_device );
BOOST_CHECK( ec.default_error_condition().value() == posix::no_such_device );
BOOST_CHECK( ec.default_error_condition().category() == posix_category );
ec = error_code( ERROR_BAD_UNIT, system_category() );
BOOST_TEST( ec.value() == ERROR_BAD_UNIT );
BOOST_TEST( ec == errc::no_such_device );
BOOST_TEST( ec.default_error_condition().value() == errc::no_such_device );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test the last non-Winsock entry in the decoder table:
ec = error_code( ERROR_WRITE_PROTECT, system_category );
BOOST_CHECK( ec.value() == ERROR_WRITE_PROTECT );
BOOST_CHECK( ec == posix::permission_denied );
BOOST_CHECK( ec.default_error_condition().value() == posix::permission_denied );
BOOST_CHECK( ec.default_error_condition().category() == posix_category );
ec = error_code( ERROR_WRITE_PROTECT, system_category() );
BOOST_TEST( ec.value() == ERROR_WRITE_PROTECT );
BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().value() == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test the last Winsock entry in the decoder table:
ec = error_code( WSAEWOULDBLOCK, system_category );
BOOST_CHECK( ec.value() == WSAEWOULDBLOCK );
BOOST_CHECK( ec == posix::operation_would_block );
BOOST_CHECK( ec.default_error_condition().value() == posix::operation_would_block );
BOOST_CHECK( ec.default_error_condition().category() == posix_category );
ec = error_code( WSAEWOULDBLOCK, system_category() );
BOOST_TEST( ec.value() == WSAEWOULDBLOCK );
BOOST_TEST( ec == errc::operation_would_block );
BOOST_TEST( ec.default_error_condition().value() == errc::operation_would_block );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test not-in-table condition:
ec = error_code( 1234567890, system_category );
BOOST_CHECK( ec.value() == 1234567890 );
BOOST_CHECK( ec.default_error_condition().value() == 1234567890 );
BOOST_CHECK( ec.default_error_condition().category() == system_category );
ec = error_code( 1234567890, system_category() );
BOOST_TEST( ec.value() == 1234567890 );
BOOST_TEST( ec.default_error_condition().value() == 1234567890 );
BOOST_TEST( ec.default_error_condition().category() == system_category() );
#else // POSIX
std::cout << "POSIX tests...\n";
ec = error_code( EACCES, system_category );
BOOST_CHECK( ec == error_code( posix::permission_denied, system_category ) );
BOOST_CHECK( error_code( posix::permission_denied, system_category ) == ec );
BOOST_CHECK( ec == posix::permission_denied );
BOOST_CHECK( posix::permission_denied == ec );
BOOST_CHECK( ec.default_error_condition().value() == posix::permission_denied );
BOOST_CHECK( ec.default_error_condition().category() == posix_category );
ec = error_code( EACCES, system_category() );
BOOST_TEST( ec == error_code( errc::permission_denied, system_category() ) );
BOOST_TEST( error_code( errc::permission_denied, system_category() ) == ec );
BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( errc::permission_denied == ec );
BOOST_TEST( ec.default_error_condition().value() == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
# ifdef __CYGWIN__
std::cout << "Cygwin tests...\n";
ec = cygwin_error::no_package;
BOOST_CHECK( ec == cygwin_error::no_package );
BOOST_CHECK( ec == error_code( ENOPKG, system_category ) );
BOOST_CHECK( ec == error_code( cygwin_error::no_package, system_category ) );
BOOST_CHECK( ec.default_error_condition().category() == system_category );
BOOST_TEST( ec == cygwin_error::no_package );
BOOST_TEST( ec == error_code( ENOPKG, system_category() ) );
BOOST_TEST( ec == error_code( cygwin_error::no_package, system_category() ) );
BOOST_TEST( ec.default_error_condition().category() == system_category() );
# elif defined(linux) || defined(__linux) || defined(__linux__)
std::cout << "Linux tests...\n";
ec = linux_error::dot_dot_error;
BOOST_CHECK( ec == linux_error::dot_dot_error );
BOOST_CHECK( ec == error_code( EDOTDOT, system_category ) );
BOOST_CHECK( ec == error_code( linux_error::dot_dot_error, system_category ) );
BOOST_CHECK( ec.default_error_condition().category() == system_category );
BOOST_TEST( ec == linux_error::dot_dot_error );
BOOST_TEST( ec == error_code( EDOTDOT, system_category() ) );
BOOST_TEST( ec == error_code( linux_error::dot_dot_error, system_category() ) );
BOOST_TEST( ec.default_error_condition().category() == system_category() );
# endif
#endif
return 0;
return ::boost::report_errors();
}

View File

@@ -14,11 +14,13 @@
// Motivation was a Boost posting by Christopher Kohlhoff on June 28, 2006.
#define BOOST_SYSTEM_NO_DEPRECATED
#include <boost/system/error_code.hpp>
#include <boost/cerrno.hpp>
#include <string>
#include <cstdio>
#include <boost/test/minimal.hpp>
#include <boost/detail/lightweight_test.hpp>
#ifdef BOOST_POSIX_API
# include <sys/stat.h>
@@ -40,7 +42,7 @@ boost::system::error_code my_mkdir( const std::string & path )
# else
::CreateDirectoryA( path.c_str(), 0 ) != 0 ? 0 : ::GetLastError(),
# endif
boost::system::system_category );
boost::system::system_category() );
}
// ------------------------------------------------------------------------ //
@@ -53,9 +55,9 @@ boost::system::error_code my_remove( const std::string & path )
{
return boost::system::error_code(
std::remove( path.c_str() ) == 0 ? 0 : errno,
boost::system::posix_category ); // OK for both Windows and POSIX
// Alternatively, could use posix_category
// on Windows and system_category on
boost::system::generic_category() ); // OK for both Windows and POSIX
// Alternatively, could use generic_category()
// on Windows and system_category() on
// POSIX-based systems.
}
@@ -108,6 +110,8 @@ namespace boost
class lib3_error_category_imp : public boost::system::error_category
{
public:
lib3_error_category_imp() : boost::system::error_category() { }
const char * name() const
{
return "lib3";
@@ -116,8 +120,8 @@ namespace boost
boost::system::error_condition default_error_condition( int ev ) const
{
return ev == boo_boo
? boost::system::error_condition( boost::system::posix::io_error,
boost::system::posix_category )
? boost::system::error_condition( boost::system::errc::io_error,
boost::system::generic_category() )
: boost::system::error_condition( ev,
boost::lib3::lib3_error_category );
}
@@ -168,6 +172,8 @@ namespace lib4
class lib4_error_category_imp : public boost::system::error_category
{
public:
lib4_error_category_imp() : boost::system::error_category() { }
const char * name() const
{
return "lib4";
@@ -176,8 +182,8 @@ namespace lib4
boost::system::error_condition default_error_condition( int ev ) const
{
return ev == boo_boo.value()
? boost::system::error_condition( boost::system::posix::io_error,
boost::system::posix_category )
? boost::system::error_condition( boost::system::errc::io_error,
boost::system::generic_category() )
: boost::system::error_condition( ev, lib4::lib4_error_category );
}
@@ -233,15 +239,15 @@ namespace lib4
// switch (ev)
// {
// case user_success:
// return boost::system::error_code(boost::system::posix::success, boost::system::posix_category);
// return boost::system::error_code(boost::system::errc::success, boost::system::generic_category());
// case user_permission_denied:
// return boost::system::error_code(boost::system::posix::permission_denied, boost::system::posix_category);
// return boost::system::error_code(boost::system::errc::permission_denied, boost::system::generic_category());
// case user_out_of_memory:
// return boost::system::error_code(boost::system::posix::not_enough_memory, boost::system::posix_category);
// return boost::system::error_code(boost::system::errc::not_enough_memory, boost::system::generic_category());
// default:
// break;
// }
// return boost::system::error_code(boost::system::posix::no_posix_equivalent, boost::system::posix_category);
// return boost::system::error_code(boost::system::errc::no_posix_equivalent, boost::system::generic_category());
// }
//
// };
@@ -260,8 +266,8 @@ namespace lib4
//
// void check_success(const boost::system::error_code& ec, bool expect)
// {
// BOOST_CHECK( (ec == boost::system::posix::success) == expect );
// if (ec == boost::system::posix::success)
// BOOST_TEST( (ec == boost::system::errc::success) == expect );
// if (ec == boost::system::errc::success)
// std::cout << "yes... " << (expect ? "ok" : "fail") << '\n';
// else
// std::cout << "no... " << (expect ? "fail" : "ok") << '\n';
@@ -269,8 +275,8 @@ namespace lib4
//
// void check_permission_denied(const boost::system::error_code& ec, bool expect)
// {
// BOOST_CHECK( (ec == boost::system::posix::permission_denied) == expect );
// if (ec == boost::system::posix::permission_denied)
// BOOST_TEST( (ec == boost::system::errc::permission_denied) == expect );
// if (ec == boost::system::errc::permission_denied)
// std::cout << "yes... " << (expect ? "ok" : "fail") << '\n';
// else
// std::cout << "no... " << (expect ? "fail" : "ok") << '\n';
@@ -278,8 +284,8 @@ namespace lib4
//
// void check_out_of_memory(const boost::system::error_code& ec, bool expect)
// {
// BOOST_CHECK( (ec == boost::system::posix::not_enough_memory) == expect );
// if (ec == boost::system::posix::not_enough_memory)
// BOOST_TEST( (ec == boost::system::errc::not_enough_memory) == expect );
// if (ec == boost::system::errc::not_enough_memory)
// std::cout << "yes... " << (expect ? "ok" : "fail") << '\n';
// else
// std::cout << "no... " << (expect ? "fail" : "ok") << '\n';
@@ -291,23 +297,23 @@ namespace lib4
// printf("=====\n");
// boost::system::error_code ec;
// check_success(ec, true);
// check_success(boost::system::posix::success, true);
// check_success(boost::system::posix::permission_denied, false);
// check_success(boost::system::posix::not_enough_memory, false);
// check_success(boost::system::errc::success, true);
// check_success(boost::system::errc::permission_denied, false);
// check_success(boost::system::errc::not_enough_memory, false);
// check_success(user_success, true);
// check_success(user_permission_denied, false);
// check_success(user_out_of_memory, false);
// check_permission_denied(ec, false);
// check_permission_denied(boost::system::posix::success, false);
// check_permission_denied(boost::system::posix::permission_denied, true);
// check_permission_denied(boost::system::posix::not_enough_memory, false);
// check_permission_denied(boost::system::errc::success, false);
// check_permission_denied(boost::system::errc::permission_denied, true);
// check_permission_denied(boost::system::errc::not_enough_memory, false);
// check_permission_denied(user_success, false);
// check_permission_denied(user_permission_denied, true);
// check_permission_denied(user_out_of_memory, false);
// check_out_of_memory(ec, false);
// check_out_of_memory(boost::system::posix::success, false);
// check_out_of_memory(boost::system::posix::permission_denied, false);
// check_out_of_memory(boost::system::posix::not_enough_memory, true);
// check_out_of_memory(boost::system::errc::success, false);
// check_out_of_memory(boost::system::errc::permission_denied, false);
// check_out_of_memory(boost::system::errc::not_enough_memory, true);
// check_out_of_memory(user_success, false);
// check_out_of_memory(user_permission_denied, false);
// check_out_of_memory(user_out_of_memory, true);
@@ -333,7 +339,7 @@ namespace lib4
// ------------------------------------------------------------------------ //
int test_main( int, char *[] )
int main( int, char *[] )
{
boost::system::error_code ec;
@@ -342,35 +348,35 @@ int test_main( int, char *[] )
ec = my_mkdir( "/no-such-file-or-directory/will-not-succeed" );
std::cout << "ec.value() is " << ec.value() << '\n';
BOOST_CHECK( ec );
BOOST_CHECK( ec == boost::system::posix::no_such_file_or_directory );
BOOST_CHECK( ec.category() == boost::system::system_category );
BOOST_TEST( ec );
BOOST_TEST( ec == boost::system::errc::no_such_file_or_directory );
BOOST_TEST( ec.category() == boost::system::system_category() );
// Library 2 tests:
ec = my_remove( "/no-such-file-or-directory" );
std::cout << "ec.value() is " << ec.value() << '\n';
BOOST_CHECK( ec );
BOOST_CHECK( ec == boost::system::posix::no_such_file_or_directory );
BOOST_CHECK( ec.category() == boost::system::posix_category );
BOOST_TEST( ec );
BOOST_TEST( ec == boost::system::errc::no_such_file_or_directory );
BOOST_TEST( ec.category() == boost::system::generic_category() );
// Library 3 tests:
ec = boost::lib3::boo_boo;
std::cout << "ec.value() is " << ec.value() << '\n';
BOOST_CHECK( ec );
BOOST_CHECK( ec == boost::lib3::boo_boo );
BOOST_CHECK( ec.value() == boost::lib3::boo_boo );
BOOST_CHECK( ec.category() == boost::lib3::lib3_error_category );
BOOST_TEST( ec );
BOOST_TEST( ec == boost::lib3::boo_boo );
BOOST_TEST( ec.value() == boost::lib3::boo_boo );
BOOST_TEST( ec.category() == boost::lib3::lib3_error_category );
BOOST_CHECK( ec == boost::system::posix::io_error );
BOOST_TEST( ec == boost::system::errc::io_error );
boost::system::error_code ec3( boost::lib3::boo_boo+100,
boost::lib3::lib3_error_category );
BOOST_CHECK( ec3.category() == boost::lib3::lib3_error_category );
BOOST_CHECK( ec3.default_error_condition().category()
BOOST_TEST( ec3.category() == boost::lib3::lib3_error_category );
BOOST_TEST( ec3.default_error_condition().category()
== boost::lib3::lib3_error_category );
// Library 4 tests:
@@ -378,21 +384,21 @@ int test_main( int, char *[] )
ec = lib4::boo_boo;
std::cout << "ec.value() is " << ec.value() << '\n';
BOOST_CHECK( ec );
BOOST_CHECK( ec == lib4::boo_boo );
BOOST_CHECK( ec.value() == lib4::boo_boo.value() );
BOOST_CHECK( ec.category() == lib4::lib4_error_category );
BOOST_TEST( ec );
BOOST_TEST( ec == lib4::boo_boo );
BOOST_TEST( ec.value() == lib4::boo_boo.value() );
BOOST_TEST( ec.category() == lib4::lib4_error_category );
BOOST_CHECK( ec == boost::system::posix::io_error );
BOOST_TEST( ec == boost::system::errc::io_error );
boost::system::error_code ec4( lib4::boo_boo.value()+100,
lib4::lib4_error_category );
BOOST_CHECK( ec4.default_error_condition().category()
BOOST_TEST( ec4.default_error_condition().category()
== lib4::lib4_error_category );
// Test 3
//test3::run();
return 0;
return ::boost::report_errors();
}

View File

@@ -9,23 +9,15 @@
//----------------------------------------------------------------------------//
// VC++ 8.0 warns on usage of certain Standard Library and API functions that
// can cause buffer overruns or other possible security issues if misused.
// See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
// But the wording of the warning is misleading and unsettling, there are no
// portable altersystem functions, and VC++ 8.0's own libraries use the
// functions in question. So turn off the warnings.
#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_DEPRECATE
#include <boost/config/warning_disable.hpp>
#define BOOST_ERROR_CODE_HEADER_ONLY
#include <boost/test/minimal.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/system/error_code.hpp>
int test_main( int, char*[] )
int main( int, char*[] )
{
boost::system::error_code ec( 0, boost::system::system_category );
return 0;
boost::system::error_code ec( 0, boost::system::system_category() );
return ::boost::report_errors();
}

View File

@@ -10,7 +10,7 @@
// This test verifiies that the error_category vtable does not suffer from
// order-of-initialization problems.
#include <boost/test/minimal.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/system/error_code.hpp>
struct foo
@@ -22,7 +22,7 @@ struct foo
}
} f;
int test_main( int, char ** )
int main( int, char ** )
{
return 0;
return ::boost::report_errors();
}

View File

@@ -9,18 +9,15 @@
//----------------------------------------------------------------------------//
// VC++ 8.0 warns on usage of certain Standard Library and API functions that
// can cause buffer overruns or other possible security issues if misused.
// See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
// But the wording of the warning is misleading and unsettling, there are no
// portable alternative functions, and VC++ 8.0's own libraries use the
// functions in question. So turn off the warnings.
#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_DEPRECATE
// test without deprecated features
#define BOOST_SYSTEM_NO_DEPRECATED
#include <boost/test/minimal.hpp>
#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/system/system_error.hpp>
#include <iostream>
#include <string>
#ifdef BOOST_WINDOWS_API
#include <windows.h>
@@ -29,6 +26,7 @@
using boost::system::system_error;
using boost::system::error_code;
using boost::system::system_category;
using std::string;
#define TEST(x,v,w) test(#x,x,v,w)
@@ -38,8 +36,8 @@ namespace
int v, const char * str )
{
std::cout << "test " << desc << "\n what() returns \"" << ex.what() << "\"\n";
BOOST_CHECK( ex.code().value() == v );
BOOST_CHECK( ex.code().category() == system_category );
BOOST_TEST( ex.code().value() == v );
BOOST_TEST( ex.code().category() == system_category() );
# ifdef BOOST_WINDOWS_API
LANGID language_id;
# if !defined(__MINGW32__) && !defined(__CYGWIN__)
@@ -50,7 +48,7 @@ namespace
// std::cout << "GetUserDefaultUILanguage() returns " << language_id << '\n';
if ( language_id == 0x0409 ) // English (United States)
{
BOOST_CHECK( std::string( ex.what() ) == str );
BOOST_TEST( std::string( ex.what() ) == str );
if ( std::string( ex.what() ) != str )
std::cout << "expected \"" << str << "\", but what() returned \""
<< ex.what() << "\"\n";
@@ -58,31 +56,54 @@ namespace
# endif
}
const boost::uint_least32_t uvalue = 1u;
const boost::uint_least32_t uvalue = 2u;
}
int test_main( int, char *[] )
int main( int, char *[] )
{
// all combinations of constructors:
// all constructors, in the same order as they appear in the header:
system_error se_0_m( error_code(0, system_category), "se_0_m" );
system_error se_1_m( 1, system_category, "se_1_m" );
system_error se_0_nm( error_code(0, system_category), "" );
system_error se_1_nm( 1, system_category, "" );
system_error se_0_nmx( error_code(0, system_category), "" );
system_error se_1_nmx( 1, system_category, "" );
system_error se_1u_m( uvalue, system_category, "se_1u_m" );
system_error c1_0( error_code(0, system_category()) );
system_error c1_1( error_code(1, system_category()) );
system_error c1_2u( error_code(uvalue, system_category()) );
TEST( se_0_m, 0, "se_0_m" );
TEST( se_1_m, 1, "se_1_m: Incorrect function" );
TEST( se_0_nm, 0, "" );
TEST( se_1_nm, 1, "Incorrect function" );
TEST( se_0_nmx, 0, "" );
TEST( se_1_nmx, 1, "Incorrect function" );
TEST( se_1u_m, 1, "se_1u_m: Incorrect function" );
system_error c2_0( error_code(0, system_category()), string("c2_0") );
system_error c2_1( error_code(1, system_category()), string("c2_1") );
system_error c3_0( error_code(0, system_category()), "c3_0" );
system_error c3_1( error_code(1, system_category()), "c3_1" );
return 0;
system_error c4_0( 0, system_category() );
system_error c4_1( 1, system_category() );
system_error c4_2u( uvalue, system_category() );
system_error c5_0( 0, system_category(), string("c5_0") );
system_error c5_1( 1, system_category(), string("c5_1") );
system_error c6_0( 0, system_category(), "c6_0" );
system_error c6_1( 1, system_category(), "c6_1" );
TEST( c1_0, 0, "The operation completed successfully" );
TEST( c1_1, 1, "Incorrect function" );
TEST( c1_2u, 2, "The system cannot find the file specified" );
TEST( c2_0, 0, "c2_0: The operation completed successfully" );
TEST( c2_1, 1, "c2_1: Incorrect function" );
TEST( c3_0, 0, "c3_0: The operation completed successfully" );
TEST( c3_1, 1, "c3_1: Incorrect function" );
TEST( c4_0, 0, "The operation completed successfully" );
TEST( c4_1, 1, "Incorrect function" );
TEST( c4_2u, 2, "The system cannot find the file specified" );
TEST( c5_0, 0, "c5_0: The operation completed successfully" );
TEST( c5_1, 1, "c5_1: Incorrect function" );
TEST( c6_0, 0, "c6_0: The operation completed successfully" );
TEST( c6_1, 1, "c6_1: Incorrect function" );
return ::boost::report_errors();
}

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="common"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../../../../.."
PreprocessorDefinitions="BOOST_ALL_NO_LIB;BOOST_ALL_DYN_LINK"
ExceptionHandling="2"
WarningLevel="4"
/>
<Tool
Name="VCPostBuildEventTool"
Description=""
CommandLine=""
/>
</VisualStudioPropertySheet>

View File

@@ -0,0 +1,199 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="error_code_test"
ProjectGUID="{81960557-E9A9-4E81-AC96-9E11C33CB058}"
RootNamespace="error_code_test"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
InheritedPropertySheets="..\common.vsprops"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="4"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description="Executing test $(TargetName).exe..."
CommandLine="&quot;$(TargetDir)\$(TargetName).exe&quot; --result_code=no --report_level=no"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
InheritedPropertySheets="..\common.vsprops"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="4"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description="Executing test $(TargetName).exe..."
CommandLine="&quot;$(TargetDir)\$(TargetName).exe&quot; --result_code=no --report_level=no"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\..\error_code_test.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,57 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C++ Express 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "error_code_test", "error_code_test\error_code_test.vcproj", "{81960557-E9A9-4E81-AC96-9E11C33CB058}"
ProjectSection(ProjectDependencies) = postProject
{22892211-A1F3-435B-8B97-A12E8772599E} = {22892211-A1F3-435B-8B97-A12E8772599E}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "system_error_test", "system_error_test\system_error_test.vcproj", "{CBD12E59-99E5-4F35-9B66-0554D0FBDB76}"
ProjectSection(ProjectDependencies) = postProject
{22892211-A1F3-435B-8B97-A12E8772599E} = {22892211-A1F3-435B-8B97-A12E8772599E}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dynamic_link_test", "dynamic_link_test\dynamic_link_test.vcproj", "{AD186B11-9132-48A9-9F24-3522C2310B0D}"
ProjectSection(ProjectDependencies) = postProject
{F6D9B408-84A3-405A-93ED-DE5AA8CF84D7} = {F6D9B408-84A3-405A-93ED-DE5AA8CF84D7}
{22892211-A1F3-435B-8B97-A12E8772599E} = {22892211-A1F3-435B-8B97-A12E8772599E}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "system_dll", "system_dll\system_dll.vcproj", "{22892211-A1F3-435B-8B97-A12E8772599E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "throw_test_dll", "throw_test_dll\throw_test_dll.vcproj", "{F6D9B408-84A3-405A-93ED-DE5AA8CF84D7}"
ProjectSection(ProjectDependencies) = postProject
{22892211-A1F3-435B-8B97-A12E8772599E} = {22892211-A1F3-435B-8B97-A12E8772599E}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{81960557-E9A9-4E81-AC96-9E11C33CB058}.Debug|Win32.ActiveCfg = Debug|Win32
{81960557-E9A9-4E81-AC96-9E11C33CB058}.Debug|Win32.Build.0 = Debug|Win32
{81960557-E9A9-4E81-AC96-9E11C33CB058}.Release|Win32.ActiveCfg = Release|Win32
{81960557-E9A9-4E81-AC96-9E11C33CB058}.Release|Win32.Build.0 = Release|Win32
{CBD12E59-99E5-4F35-9B66-0554D0FBDB76}.Debug|Win32.ActiveCfg = Debug|Win32
{CBD12E59-99E5-4F35-9B66-0554D0FBDB76}.Debug|Win32.Build.0 = Debug|Win32
{CBD12E59-99E5-4F35-9B66-0554D0FBDB76}.Release|Win32.ActiveCfg = Release|Win32
{CBD12E59-99E5-4F35-9B66-0554D0FBDB76}.Release|Win32.Build.0 = Release|Win32
{AD186B11-9132-48A9-9F24-3522C2310B0D}.Debug|Win32.ActiveCfg = Debug|Win32
{AD186B11-9132-48A9-9F24-3522C2310B0D}.Debug|Win32.Build.0 = Debug|Win32
{AD186B11-9132-48A9-9F24-3522C2310B0D}.Release|Win32.ActiveCfg = Release|Win32
{AD186B11-9132-48A9-9F24-3522C2310B0D}.Release|Win32.Build.0 = Release|Win32
{22892211-A1F3-435B-8B97-A12E8772599E}.Debug|Win32.ActiveCfg = Debug|Win32
{22892211-A1F3-435B-8B97-A12E8772599E}.Debug|Win32.Build.0 = Debug|Win32
{22892211-A1F3-435B-8B97-A12E8772599E}.Release|Win32.ActiveCfg = Release|Win32
{22892211-A1F3-435B-8B97-A12E8772599E}.Release|Win32.Build.0 = Release|Win32
{F6D9B408-84A3-405A-93ED-DE5AA8CF84D7}.Debug|Win32.ActiveCfg = Debug|Win32
{F6D9B408-84A3-405A-93ED-DE5AA8CF84D7}.Debug|Win32.Build.0 = Debug|Win32
{F6D9B408-84A3-405A-93ED-DE5AA8CF84D7}.Release|Win32.ActiveCfg = Release|Win32
{F6D9B408-84A3-405A-93ED-DE5AA8CF84D7}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

31
test/throw_test.cpp Normal file
View File

@@ -0,0 +1,31 @@
// throw_test.cpp --------------------------------------------------------===========-//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// See www.boost.org/LICENSE_1_0.txt
// Library home page is www.boost.org/libs/system
//--------------------------------------------------------------------------------------//
// See dynamic_link_test.cpp comments for use case.
//--------------------------------------------------------------------------------------//
// 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/system/system_error.hpp>
namespace boost
{
namespace system
{
BOOST_SYSTEM_DECL void throw_test()
{
throw system_error(9999, system_category(), "boo boo");
}
}
}