Boost logo

Boost-Commit :

From: bdawes_at_[hidden]
Date: 2007-11-08 09:45:31


Author: bemandawes
Date: 2007-11-08 09:45:31 EST (Thu, 08 Nov 2007)
New Revision: 40933
URL: http://svn.boost.org/trac/boost/changeset/40933

Log:
Add separate headers for system-specific enums, thus reducing coupling. Suggested by Emil Dotchevski.
Added:
   branches/system/boost/system/cygwin_error.hpp (contents, props changed)
   branches/system/boost/system/linux_error.hpp (contents, props changed)
   branches/system/boost/system/windows_error.hpp (contents, props changed)
Text files modified:
   branches/system/boost/system/error_code.hpp | 263 +++++----------------------------------
   branches/system/libs/system/test/system_error_test.cpp | 2
   2 files changed, 37 insertions(+), 228 deletions(-)

Added: branches/system/boost/system/cygwin_error.hpp
==============================================================================
--- (empty file)
+++ branches/system/boost/system/cygwin_error.hpp 2007-11-08 09:45:31 EST (Thu, 08 Nov 2007)
@@ -0,0 +1,56 @@
+// boost/system/cygwin_error.hpp -------------------------------------------//
+
+// Copyright Beman Dawes 2007
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See library home page at http://www.boost.org/libs/system
+
+#ifndef BOOST_CYGWIN_ERROR_HPP
+#define BOOST_CYGWIN_ERROR_HPP
+
+// This header is effectively empty for compiles on operating systems where
+// it is not applicable.
+
+# ifdef __CYGWIN__
+
+#include <boost/system/error_code.hpp>
+
+namespace boost
+{
+ namespace system
+ {
+ // 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.
+
+ 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 ); }
+ }
+ }
+}
+
+#endif // __CYGWIN__
+
+#endif // BOOST_CYGWIN_ERROR_HPP

Modified: branches/system/boost/system/error_code.hpp
==============================================================================
--- branches/system/boost/system/error_code.hpp (original)
+++ branches/system/boost/system/error_code.hpp 2007-11-08 09:45:31 EST (Thu, 08 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
 

Added: branches/system/boost/system/linux_error.hpp
==============================================================================
--- (empty file)
+++ branches/system/boost/system/linux_error.hpp 2007-11-08 09:45:31 EST (Thu, 08 Nov 2007)
@@ -0,0 +1,110 @@
+// boost/system/linux_error.hpp -------------------------------------------//
+
+// Copyright Beman Dawes 2007
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See library home page at http://www.boost.org/libs/system
+
+#ifndef BOOST_LINUX_ERROR_HPP
+#define BOOST_LINUX_ERROR_HPP
+
+// This header is effectively empty for compiles on operating systems where
+// it is not applicable.
+
+#if defined(linux) || defined(__linux) || defined(__linux__)
+
+#include <boost/system/error_code.hpp>
+
+namespace boost
+{
+ namespace system
+ {
+ // 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.
+
+ 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 ); }
+ }
+
+ } // namespace system
+} // namespace boost
+
+#endif // Linux
+
+#endif // BOOST_LINUX_ERROR_HPP

Added: branches/system/boost/system/windows_error.hpp
==============================================================================
--- (empty file)
+++ branches/system/boost/system/windows_error.hpp 2007-11-08 09:45:31 EST (Thu, 08 Nov 2007)
@@ -0,0 +1,118 @@
+// boost/system/windows_error.hpp ------------------------------------------//
+
+// Copyright Beman Dawes 2007
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See library home page at http://www.boost.org/libs/system
+
+#ifndef BOOST_WINDOWS_ERROR_HPP
+#define BOOST_WINDOWS_ERROR_HPP
+
+// This header is effectively empty for compiles on operating systems where
+// it is not applicable.
+
+#include <boost/system/config.hpp>
+
+#ifdef BOOST_WINDOWS_API
+
+#include <boost/system/error_code.hpp>
+#include <winerror.h>
+
+namespace boost
+{
+ namespace system
+ {
+
+ // 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 ); }
+ }
+
+ } // namespace system
+} // namespace boost
+
+#endif // BOOST_WINDOWS_API
+
+#endif // BOOST_WINDOWS_ERROR_HPP

Modified: branches/system/libs/system/test/system_error_test.cpp
==============================================================================
--- branches/system/libs/system/test/system_error_test.cpp (original)
+++ branches/system/libs/system/test/system_error_test.cpp 2007-11-08 09:45:31 EST (Thu, 08 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