forked from boostorg/system
Add separate headers for system-specific enums, thus reducing coupling. Suggested by Emil Dotchevski.
[SVN r41033]
This commit is contained in:
@@ -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 @@ namespace boost
|
||||
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 @@ namespace boost
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user