Boost logo

Boost-Commit :

From: bdawes_at_[hidden]
Date: 2007-11-12 10:22:24


Author: bemandawes
Date: 2007-11-12 10:22:24 EST (Mon, 12 Nov 2007)
New Revision: 41033
URL: http://svn.boost.org/trac/boost/changeset/41033

Log:
Add separate headers for system-specific enums, thus reducing coupling. Suggested by Emil Dotchevski.

Added:
   trunk/boost/system/cygwin_error.hpp
      - copied unchanged from r41032, /branches/system/boost/system/cygwin_error.hpp
   trunk/boost/system/linux_error.hpp
      - copied unchanged from r41032, /branches/system/boost/system/linux_error.hpp
   trunk/boost/system/windows_error.hpp
      - copied unchanged from r41032, /branches/system/boost/system/windows_error.hpp
Text files modified:
   trunk/boost/system/error_code.hpp | 263 +++++----------------------------------
   trunk/libs/system/doc/index.html | 22 +++
   trunk/libs/system/doc/reference.html | 48 ++++++
   trunk/libs/system/test/system_error_test.cpp | 2
   4 files changed, 104 insertions(+), 231 deletions(-)

Modified: trunk/boost/system/error_code.hpp
==============================================================================
--- trunk/boost/system/error_code.hpp (original)
+++ trunk/boost/system/error_code.hpp 2007-11-12 10:22:24 EST (Mon, 12 Nov 2007)
@@ -25,9 +25,9 @@
 // TODO: undef these macros if not already defined
 #include <boost/cerrno.hpp>
 
-# ifdef BOOST_WINDOWS_API
-# include <winerror.h>
-# endif
+#if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API)
+# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined
+#endif
 
 #include <boost/config/abi_prefix.hpp> // must be the last #include
 
@@ -143,6 +143,39 @@
     template<> struct is_error_condition_enum<posix_error::posix_errno>
       { static const bool value = true; };
 
+
+ // ----------------------------------------------------------------------//
+
+ // Operating system specific interfaces --------------------------------//
+
+
+ // The interface is divided into general and system-specific portions to
+ // meet these requirements:
+ //
+ // * Code calling an operating system API can create an error_code with
+ // a single category (system_category), even for POSIX-like operating
+ // systems that return some POSIX errno values and some native errno
+ // values. This code should not have to pay the cost of distinguishing
+ // between categories, since it is not yet known if that is needed.
+ //
+ // * Users wishing to write system-specific code should be given enums for
+ // at least the common error cases.
+ //
+ // * System specific code should fail at compile time if moved to another
+ // operating system.
+
+ // The system specific portions of the interface are located in headers
+ // with names reflecting the operating system. For example,
+ //
+ // <boost/system/cygwin_error.hpp>
+ // <boost/system/linux_error.hpp>
+ // <boost/system/windows_error.hpp>
+ //
+ // These headers are effectively empty for compiles on operating systems
+ // where they are not applicable.
+
+ // ----------------------------------------------------------------------//
+
     // class error_category ------------------------------------------------//
 
     class error_category : public noncopyable
@@ -448,230 +481,6 @@
       return s;
     }
 
- // ----------------------------------------------------------------------//
-
- // Operating system specific interfaces --------------------------------//
-
-
- // The interface is divided into general and system-specific portions to
- // meet these requirements:
- //
- // * Code calling an operating system API can create an error_code with
- // a single category (system_category), even for POSIX-like operating
- // systems that return some POSIX errno values and some native errno
- // values. This code should not have to pay the cost of distinguishing
- // between categories, since it is not yet known if that is needed.
- //
- // * Users wishing to write system-specific code should be given enums for
- // at least the common error cases.
- //
- // * System specific code should fail at compile time if moved to another
- // operating system.
-
-#ifdef BOOST_POSIX_API
-
- // POSIX-based systems -------------------------------------------------//
-
- // To construct an error_code after a API error:
- //
- // 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
- // errno values that POSIX-based systems typically provide in addition to
- // POSIX values, use the system specific enums below.
-
-# ifdef __CYGWIN__
-
- namespace cygwin_error
- {
- enum cygwin_errno
- {
- no_net = ENONET,
- no_package = ENOPKG,
- no_share = ENOSHARE
- };
- } // namespace cygwin_error
-
- template<> struct is_error_code_enum<cygwin_error::cygwin_errno>
- { static const bool value = true; };
-
- namespace cygwin_error
- {
- inline error_code make_error_code( cygwin_errno e )
- { return error_code( e, system_category ); }
- }
-
-# elif defined(linux) || defined(__linux) || defined(__linux__)
-
- namespace linux_error
- {
- enum linux_errno
- {
- advertise_error = EADV,
- bad_exchange = EBADE,
- bad_file_number = EBADFD,
- bad_font_format = EBFONT,
- bad_request_code = EBADRQC,
- bad_request_descriptor = EBADR,
- bad_slot = EBADSLT,
- channel_range = ECHRNG,
- communication_error = ECOMM,
- dot_dot_error = EDOTDOT,
- exchange_full = EXFULL,
- host_down = EHOSTDOWN,
- is_named_file_type= EISNAM,
- key_expired = EKEYEXPIRED,
- key_rejected = EKEYREJECTED,
- key_revoked = EKEYREVOKED,
- level2_halt= EL2HLT,
- level2_no_syncronized= EL2NSYNC,
- level3_halt = EL3HLT,
- level3_reset = EL3RST,
- link_range = ELNRNG,
- medium_type = EMEDIUMTYPE,
- no_anode= ENOANO,
- no_block_device = ENOTBLK,
- no_csi = ENOCSI,
- no_key = ENOKEY,
- no_medium = ENOMEDIUM,
- no_network = ENONET,
- no_package = ENOPKG,
- not_avail = ENAVAIL,
- not_named_file_type= ENOTNAM,
- not_recoverable = ENOTRECOVERABLE,
- not_unique = ENOTUNIQ,
- owner_dead = EOWNERDEAD,
- protocol_no_supported = EPFNOSUPPORT,
- remote_address_changed = EREMCHG,
- remote_io_error = EREMOTEIO,
- remote_object = EREMOTE,
- restart_needed = ERESTART,
- shared_library_access = ELIBACC,
- shared_library_bad = ELIBBAD,
- shared_library_execute = ELIBEXEC,
- shared_library_max_ = ELIBMAX,
- shared_library_section= ELIBSCN,
- shutdown = ESHUTDOWN,
- socket_type_not_supported = ESOCKTNOSUPPORT,
- srmount_error = ESRMNT,
- stream_pipe_error = ESTRPIPE,
- too_many_references = ETOOMANYREFS,
- too_many_users = EUSERS,
- unattached = EUNATCH,
- unclean = EUCLEAN
- };
- } // namespace linux_error
-
-# ifndef BOOST_SYSTEM_NO_DEPRECATED
- namespace Linux = linux_error;
-# endif
-
- template<> struct is_error_code_enum<linux_error::linux_errno>
- { static const bool value = true; };
-
- namespace linux_error
- {
- inline error_code make_error_code( linux_errno e )
- { return error_code( e, system_category ); }
- }
-
-# endif
-
- // TODO: Add more POSIX-based operating systems here
-
-
-#elif defined(BOOST_WINDOWS_API)
-
- // Microsoft Windows ---------------------------------------------------//
-
- // To construct an error_code after a API error:
- //
- // error_code( ::GetLastError(), system_category )
-
- namespace windows_error
- {
- enum windows_error_code
- {
- success = 0,
- // These names and values are based on Windows winerror.h
- invalid_function = ERROR_INVALID_FUNCTION,
- file_not_found = ERROR_FILE_NOT_FOUND,
- path_not_found = ERROR_PATH_NOT_FOUND,
- too_many_open_files = ERROR_TOO_MANY_OPEN_FILES,
- access_denied = ERROR_ACCESS_DENIED,
- invalid_handle = ERROR_INVALID_HANDLE,
- arena_trashed = ERROR_ARENA_TRASHED,
- not_enough_memory = ERROR_NOT_ENOUGH_MEMORY,
- invalid_block = ERROR_INVALID_BLOCK,
- bad_environment = ERROR_BAD_ENVIRONMENT,
- bad_format = ERROR_BAD_FORMAT,
- invalid_access = ERROR_INVALID_ACCESS,
- outofmemory = ERROR_OUTOFMEMORY,
- invalid_drive = ERROR_INVALID_DRIVE,
- current_directory = ERROR_CURRENT_DIRECTORY,
- not_same_device = ERROR_NOT_SAME_DEVICE,
- no_more_files = ERROR_NO_MORE_FILES,
- write_protect = ERROR_WRITE_PROTECT,
- bad_unit = ERROR_BAD_UNIT,
- not_ready = ERROR_NOT_READY,
- bad_command = ERROR_BAD_COMMAND,
- crc = ERROR_CRC,
- bad_length = ERROR_BAD_LENGTH,
- seek = ERROR_SEEK,
- not_dos_disk = ERROR_NOT_DOS_DISK,
- sector_not_found = ERROR_SECTOR_NOT_FOUND,
- out_of_paper = ERROR_OUT_OF_PAPER,
- write_fault = ERROR_WRITE_FAULT,
- read_fault = ERROR_READ_FAULT,
- gen_failure = ERROR_GEN_FAILURE,
- sharing_violation = ERROR_SHARING_VIOLATION,
- lock_violation = ERROR_LOCK_VIOLATION,
- wrong_disk = ERROR_WRONG_DISK,
- sharing_buffer_exceeded = ERROR_SHARING_BUFFER_EXCEEDED,
- handle_eof = ERROR_HANDLE_EOF,
- handle_disk_full= ERROR_HANDLE_DISK_FULL,
- rem_not_list = ERROR_REM_NOT_LIST,
- dup_name = ERROR_DUP_NAME,
- bad_net_path = ERROR_BAD_NETPATH,
- network_busy = ERROR_NETWORK_BUSY,
- // ...
- file_exists = ERROR_FILE_EXISTS,
- cannot_make = ERROR_CANNOT_MAKE,
- // ...
- broken_pipe = ERROR_BROKEN_PIPE,
- open_failed = ERROR_OPEN_FAILED,
- buffer_overflow = ERROR_BUFFER_OVERFLOW,
- disk_full= ERROR_DISK_FULL,
- // ...
- lock_failed = ERROR_LOCK_FAILED,
- busy = ERROR_BUSY,
- cancel_violation = ERROR_CANCEL_VIOLATION,
- already_exists = ERROR_ALREADY_EXISTS
- // ...
-
- // TODO: add more Windows errors
- };
-
- } // namespace windows
-
-# ifndef BOOST_SYSTEM_NO_DEPRECATED
- namespace windows = windows_error;
-# endif
-
- template<> struct is_error_code_enum<windows_error::windows_error_code>
- { static const bool value = true; };
-
- namespace windows_error
- {
- inline error_code make_error_code( windows_error_code e )
- { return error_code( e, system_category ); }
- }
-
-#else
-# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined
-#endif
-
   } // namespace system
 } // namespace boost
 

Modified: trunk/libs/system/doc/index.html
==============================================================================
--- trunk/libs/system/doc/index.html (original)
+++ trunk/libs/system/doc/index.html 2007-11-12 10:22:24 EST (Mon, 12 Nov 2007)
@@ -43,6 +43,22 @@
       <a href="#Acknowledgements">Acknowledgements</a>
     </td>
   </tr>
+ <tr>
+ <td width="100%" bgcolor="#D7EEFF" align="center">
+ <b><i>Headers</i></b></td>
+ </tr>
+ <tr>
+ <td width="100%" bgcolor="#E8F5FF">
+ <boost/system/error_code.hpp><br>
+ <a href="reference.html#Header-system_error">
+ &lt;boost/system/system_error.hpp&gt;</a><br>
+ <a href="../../../boost/system/cygwin_error.hpp">
+ &lt;boost/system/cygwin_error.hpp&gt;</a><br>
+ <a href="../../../boost/system/linux_error.hpp">
+ &lt;boost/system/linux_error.hpp&gt;</a><br>
+ <a href="../../../boost/system/windows_error.hpp">
+ &lt;boost/system/windows_error.hpp&gt;</a></td>
+ </tr>
 </table>
 
 <h2><a name="Introduction">Introduction</a></h2>
@@ -73,6 +89,10 @@
 occurrences and must be dealt with as they arise, programs become littered with
 try/catch blocks, unreadable, and very inefficient. The Boost System library
 supports both error reporting by exception and by error code.</p>
+<p>In addition to portable errors codes and conditions supported by the <code>
+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>
 <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
@@ -117,7 +137,7 @@
 <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 -->September 14, 2007<!--webbot bot="Timestamp" endspan i-checksum="37985" --> </font>
+<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->November 12, 2007<!--webbot bot="Timestamp" endspan i-checksum="39581" --> </font>
 </p>
 
 </body>

Modified: trunk/libs/system/doc/reference.html
==============================================================================
--- trunk/libs/system/doc/reference.html (original)
+++ trunk/libs/system/doc/reference.html 2007-11-12 10:22:24 EST (Mon, 12 Nov 2007)
@@ -38,6 +38,7 @@
   <tr>
     <td width="100%" bgcolor="#E8F5FF">
       <a href="#Introduction">Introduction</a><br>
+ Macros<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;Class error_category synopsis<br>
@@ -68,8 +69,51 @@
 <p>This reference documentation describes components that&nbsp;
 programs may use to report error conditions originating from the operating
 system or other low-level application program interfaces.</p>
-<p>System Library components do not change the value of <code>
+<p>Boost.System library components never change the value of <code>
 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">
+ <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>
+ </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,
+ otherwise not defined.</td>
+ <td valign="top">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,
+ otherwise not defined.</td>
+ <td valign="top">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>
+ </tr>
+</table>
 <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>
@@ -699,7 +743,7 @@
 <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 -->October 23, 2007<!--webbot bot="Timestamp" endspan i-checksum="30853" --> </font>
+<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->November 12, 2007<!--webbot bot="Timestamp" endspan i-checksum="39581" --> </font>
 </p>
 
 </body>

Modified: trunk/libs/system/test/system_error_test.cpp
==============================================================================
--- trunk/libs/system/test/system_error_test.cpp (original)
+++ trunk/libs/system/test/system_error_test.cpp 2007-11-12 10:22:24 EST (Mon, 12 Nov 2007)
@@ -42,7 +42,7 @@
     BOOST_CHECK( ex.code().category() == system_category );
 # ifdef BOOST_WINDOWS_API
     LANGID language_id;
-# ifndef __MINGW32__
+# if !defined(__MINGW32__) && !defined(__CYGWIN__)
       language_id = ::GetUserDefaultUILanguage();
 # else
       language_id = 0x0409; // Assume US English


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk