blob: d65b29b16405644cca92c72062ab2dde0e3274b3 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:161// -*- C++ -*-
2//===---------------------------- system_error ----------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:165//
Howard Hinnant412dbeb2010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:168//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_SYSTEM_ERROR
12#define _LIBCPP_SYSTEM_ERROR
13
14/*
15 system_error synopsis
16
17namespace std
18{
19
20class error_category
21{
22public:
Howard Hinnanta62f2892011-05-26 19:48:0123 virtual ~error_category() noexcept;
Howard Hinnant3e519522010-05-11 19:42:1624
25 error_category(const error_category&) = delete;
26 error_category& operator=(const error_category&) = delete;
27
Howard Hinnanta62f2892011-05-26 19:48:0128 virtual const char* name() const noexcept = 0;
29 virtual error_condition default_error_condition(int ev) const noexcept;
30 virtual bool equivalent(int code, const error_condition& condition) const noexcept;
31 virtual bool equivalent(const error_code& code, int condition) const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1632 virtual string message(int ev) const = 0;
33
Howard Hinnanta62f2892011-05-26 19:48:0134 bool operator==(const error_category& rhs) const noexcept;
35 bool operator!=(const error_category& rhs) const noexcept;
36 bool operator<(const error_category& rhs) const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1637};
38
Howard Hinnanta62f2892011-05-26 19:48:0139const error_category& generic_category() noexcept;
40const error_category& system_category() noexcept;
Howard Hinnant3e519522010-05-11 19:42:1641
42template <class T> struct is_error_code_enum
43 : public false_type {};
44
45template <class T> struct is_error_condition_enum
46 : public false_type {};
47
48class error_code
49{
50public:
51 // constructors:
Howard Hinnanta62f2892011-05-26 19:48:0152 error_code() noexcept;
53 error_code(int val, const error_category& cat) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1654 template <class ErrorCodeEnum>
Howard Hinnanta62f2892011-05-26 19:48:0155 error_code(ErrorCodeEnum e) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1656
57 // modifiers:
Howard Hinnanta62f2892011-05-26 19:48:0158 void assign(int val, const error_category& cat) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1659 template <class ErrorCodeEnum>
Howard Hinnanta62f2892011-05-26 19:48:0160 error_code& operator=(ErrorCodeEnum e) noexcept;
61 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:1662
63 // observers:
Howard Hinnanta62f2892011-05-26 19:48:0164 int value() const noexcept;
65 const error_category& category() const noexcept;
66 error_condition default_error_condition() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1667 string message() const;
Howard Hinnanta62f2892011-05-26 19:48:0168 explicit operator bool() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1669};
70
71// non-member functions:
Howard Hinnanta62f2892011-05-26 19:48:0172bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1673template <class charT, class traits>
74 basic_ostream<charT,traits>&
75 operator<<(basic_ostream<charT,traits>& os, const error_code& ec);
76
77class error_condition
78{
79public:
80 // constructors:
Howard Hinnanta62f2892011-05-26 19:48:0181 error_condition() noexcept;
82 error_condition(int val, const error_category& cat) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1683 template <class ErrorConditionEnum>
Howard Hinnanta62f2892011-05-26 19:48:0184 error_condition(ErrorConditionEnum e) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1685
86 // modifiers:
Howard Hinnanta62f2892011-05-26 19:48:0187 void assign(int val, const error_category& cat) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1688 template <class ErrorConditionEnum>
Howard Hinnanta62f2892011-05-26 19:48:0189 error_condition& operator=(ErrorConditionEnum e) noexcept;
90 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:1691
92 // observers:
Howard Hinnanta62f2892011-05-26 19:48:0193 int value() const noexcept;
94 const error_category& category() const noexcept;
95 string message() const noexcept;
96 explicit operator bool() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1697};
98
Howard Hinnanta62f2892011-05-26 19:48:0199bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16100
101class system_error
102 : public runtime_error
103{
104public:
105 system_error(error_code ec, const string& what_arg);
106 system_error(error_code ec, const char* what_arg);
107 system_error(error_code ec);
108 system_error(int ev, const error_category& ecat, const string& what_arg);
109 system_error(int ev, const error_category& ecat, const char* what_arg);
110 system_error(int ev, const error_category& ecat);
111
Howard Hinnanta62f2892011-05-26 19:48:01112 const error_code& code() const noexcept;
113 const char* what() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16114};
115
116enum class errc
117{
118 address_family_not_supported, // EAFNOSUPPORT
119 address_in_use, // EADDRINUSE
120 address_not_available, // EADDRNOTAVAIL
121 already_connected, // EISCONN
122 argument_list_too_long, // E2BIG
123 argument_out_of_domain, // EDOM
124 bad_address, // EFAULT
125 bad_file_descriptor, // EBADF
126 bad_message, // EBADMSG
127 broken_pipe, // EPIPE
128 connection_aborted, // ECONNABORTED
129 connection_already_in_progress, // EALREADY
130 connection_refused, // ECONNREFUSED
131 connection_reset, // ECONNRESET
132 cross_device_link, // EXDEV
133 destination_address_required, // EDESTADDRREQ
134 device_or_resource_busy, // EBUSY
135 directory_not_empty, // ENOTEMPTY
136 executable_format_error, // ENOEXEC
137 file_exists, // EEXIST
138 file_too_large, // EFBIG
139 filename_too_long, // ENAMETOOLONG
140 function_not_supported, // ENOSYS
141 host_unreachable, // EHOSTUNREACH
142 identifier_removed, // EIDRM
143 illegal_byte_sequence, // EILSEQ
144 inappropriate_io_control_operation, // ENOTTY
145 interrupted, // EINTR
146 invalid_argument, // EINVAL
147 invalid_seek, // ESPIPE
148 io_error, // EIO
149 is_a_directory, // EISDIR
150 message_size, // EMSGSIZE
151 network_down, // ENETDOWN
152 network_reset, // ENETRESET
153 network_unreachable, // ENETUNREACH
154 no_buffer_space, // ENOBUFS
155 no_child_process, // ECHILD
156 no_link, // ENOLINK
157 no_lock_available, // ENOLCK
158 no_message_available, // ENODATA
159 no_message, // ENOMSG
160 no_protocol_option, // ENOPROTOOPT
161 no_space_on_device, // ENOSPC
162 no_stream_resources, // ENOSR
163 no_such_device_or_address, // ENXIO
164 no_such_device, // ENODEV
165 no_such_file_or_directory, // ENOENT
166 no_such_process, // ESRCH
167 not_a_directory, // ENOTDIR
168 not_a_socket, // ENOTSOCK
169 not_a_stream, // ENOSTR
170 not_connected, // ENOTCONN
171 not_enough_memory, // ENOMEM
172 not_supported, // ENOTSUP
173 operation_canceled, // ECANCELED
174 operation_in_progress, // EINPROGRESS
175 operation_not_permitted, // EPERM
176 operation_not_supported, // EOPNOTSUPP
177 operation_would_block, // EWOULDBLOCK
178 owner_dead, // EOWNERDEAD
179 permission_denied, // EACCES
180 protocol_error, // EPROTO
181 protocol_not_supported, // EPROTONOSUPPORT
182 read_only_file_system, // EROFS
183 resource_deadlock_would_occur, // EDEADLK
184 resource_unavailable_try_again, // EAGAIN
185 result_out_of_range, // ERANGE
186 state_not_recoverable, // ENOTRECOVERABLE
187 stream_timeout, // ETIME
188 text_file_busy, // ETXTBSY
189 timed_out, // ETIMEDOUT
190 too_many_files_open_in_system, // ENFILE
191 too_many_files_open, // EMFILE
192 too_many_links, // EMLINK
193 too_many_symbolic_link_levels, // ELOOP
194 value_too_large, // EOVERFLOW
195 wrong_protocol_type // EPROTOTYPE
196};
197
198template <> struct is_error_condition_enum<errc>
199 : true_type { }
200
Howard Hinnanta62f2892011-05-26 19:48:01201error_code make_error_code(errc e) noexcept;
202error_condition make_error_condition(errc e) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16203
204// Comparison operators:
Howard Hinnanta62f2892011-05-26 19:48:01205bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
206bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
207bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
208bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
209bool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
210bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
211bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
212bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16213
214template <> struct hash<std::error_code>;
215
216} // std
217
218*/
219
220#include <__config>
221#include <cerrno>
222#include <type_traits>
223#include <stdexcept>
224#include <__functional_base>
225
Howard Hinnant073458b2011-10-17 20:05:10226#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16227#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10228#endif
Howard Hinnant3e519522010-05-11 19:42:16229
230_LIBCPP_BEGIN_NAMESPACE_STD
231
232// is_error_code_enum
233
Howard Hinnante0601332010-09-23 17:31:07234template <class _Tp>
235struct _LIBCPP_VISIBLE is_error_code_enum
Howard Hinnant3e519522010-05-11 19:42:16236 : public false_type {};
237
238// is_error_condition_enum
239
Howard Hinnante0601332010-09-23 17:31:07240template <class _Tp>
241struct _LIBCPP_VISIBLE is_error_condition_enum
Howard Hinnant3e519522010-05-11 19:42:16242 : public false_type {};
243
David Chisnall37aab762010-08-11 16:52:41244// Some error codes are not present on all platforms, so we provide equivalents
245// for them:
246
Howard Hinnant3e519522010-05-11 19:42:16247//enum class errc
248struct errc
249{
250enum _ {
251 address_family_not_supported = EAFNOSUPPORT,
252 address_in_use = EADDRINUSE,
253 address_not_available = EADDRNOTAVAIL,
254 already_connected = EISCONN,
255 argument_list_too_long = E2BIG,
256 argument_out_of_domain = EDOM,
257 bad_address = EFAULT,
258 bad_file_descriptor = EBADF,
259 bad_message = EBADMSG,
260 broken_pipe = EPIPE,
261 connection_aborted = ECONNABORTED,
262 connection_already_in_progress = EALREADY,
263 connection_refused = ECONNREFUSED,
264 connection_reset = ECONNRESET,
265 cross_device_link = EXDEV,
266 destination_address_required = EDESTADDRREQ,
267 device_or_resource_busy = EBUSY,
268 directory_not_empty = ENOTEMPTY,
269 executable_format_error = ENOEXEC,
270 file_exists = EEXIST,
271 file_too_large = EFBIG,
272 filename_too_long = ENAMETOOLONG,
273 function_not_supported = ENOSYS,
274 host_unreachable = EHOSTUNREACH,
275 identifier_removed = EIDRM,
276 illegal_byte_sequence = EILSEQ,
277 inappropriate_io_control_operation = ENOTTY,
278 interrupted = EINTR,
279 invalid_argument = EINVAL,
280 invalid_seek = ESPIPE,
281 io_error = EIO,
282 is_a_directory = EISDIR,
283 message_size = EMSGSIZE,
284 network_down = ENETDOWN,
285 network_reset = ENETRESET,
286 network_unreachable = ENETUNREACH,
287 no_buffer_space = ENOBUFS,
288 no_child_process = ECHILD,
289 no_link = ENOLINK,
290 no_lock_available = ENOLCK,
David Chisnall37aab762010-08-11 16:52:41291#ifdef ENODATA
Howard Hinnant3e519522010-05-11 19:42:16292 no_message_available = ENODATA,
David Chisnall37aab762010-08-11 16:52:41293#else
294 no_message_available = ENOMSG,
295#endif
Howard Hinnant3e519522010-05-11 19:42:16296 no_message = ENOMSG,
297 no_protocol_option = ENOPROTOOPT,
298 no_space_on_device = ENOSPC,
David Chisnall37aab762010-08-11 16:52:41299#ifdef ENOSR
Howard Hinnant3e519522010-05-11 19:42:16300 no_stream_resources = ENOSR,
David Chisnall37aab762010-08-11 16:52:41301#else
302 no_stream_resources = ENOMEM,
303#endif
Howard Hinnant3e519522010-05-11 19:42:16304 no_such_device_or_address = ENXIO,
305 no_such_device = ENODEV,
306 no_such_file_or_directory = ENOENT,
307 no_such_process = ESRCH,
308 not_a_directory = ENOTDIR,
309 not_a_socket = ENOTSOCK,
David Chisnall37aab762010-08-11 16:52:41310#ifdef ENOSTR
Howard Hinnant3e519522010-05-11 19:42:16311 not_a_stream = ENOSTR,
David Chisnall37aab762010-08-11 16:52:41312#else
313 not_a_stream = EINVAL,
314#endif
Howard Hinnant3e519522010-05-11 19:42:16315 not_connected = ENOTCONN,
316 not_enough_memory = ENOMEM,
317 not_supported = ENOTSUP,
318 operation_canceled = ECANCELED,
319 operation_in_progress = EINPROGRESS,
320 operation_not_permitted = EPERM,
321 operation_not_supported = EOPNOTSUPP,
322 operation_would_block = EWOULDBLOCK,
323 owner_dead = EOWNERDEAD,
324 permission_denied = EACCES,
325 protocol_error = EPROTO,
326 protocol_not_supported = EPROTONOSUPPORT,
327 read_only_file_system = EROFS,
328 resource_deadlock_would_occur = EDEADLK,
329 resource_unavailable_try_again = EAGAIN,
330 result_out_of_range = ERANGE,
331 state_not_recoverable = ENOTRECOVERABLE,
David Chisnall37aab762010-08-11 16:52:41332#ifdef ETIME
Howard Hinnant3e519522010-05-11 19:42:16333 stream_timeout = ETIME,
David Chisnall37aab762010-08-11 16:52:41334#else
335 stream_timeout = ETIMEDOUT,
336#endif
Howard Hinnant3e519522010-05-11 19:42:16337 text_file_busy = ETXTBSY,
338 timed_out = ETIMEDOUT,
339 too_many_files_open_in_system = ENFILE,
340 too_many_files_open = EMFILE,
341 too_many_links = EMLINK,
342 too_many_symbolic_link_levels = ELOOP,
343 value_too_large = EOVERFLOW,
344 wrong_protocol_type = EPROTOTYPE
345};
346
347 _ __v_;
348
Howard Hinnante0601332010-09-23 17:31:07349 _LIBCPP_ALWAYS_INLINE
Howard Hinnant3e519522010-05-11 19:42:16350 errc(_ __v) : __v_(__v) {}
Howard Hinnante0601332010-09-23 17:31:07351 _LIBCPP_ALWAYS_INLINE
Howard Hinnant3e519522010-05-11 19:42:16352 operator int() const {return __v_;}
353
354};
355
Howard Hinnante0601332010-09-23 17:31:07356template <>
357struct _LIBCPP_VISIBLE is_error_condition_enum<errc>
Howard Hinnant3e519522010-05-11 19:42:16358 : true_type { };
359
Howard Hinnante0601332010-09-23 17:31:07360template <>
361struct _LIBCPP_VISIBLE is_error_condition_enum<errc::_>
Howard Hinnant3e519522010-05-11 19:42:16362 : true_type { };
363
364class error_condition;
365class error_code;
366
367// class error_category
368
369class __do_message;
370
Howard Hinnante0601332010-09-23 17:31:07371class _LIBCPP_VISIBLE error_category
Howard Hinnant3e519522010-05-11 19:42:16372{
373public:
Howard Hinnanta62f2892011-05-26 19:48:01374 virtual ~error_category() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16375
376private:
Howard Hinnanta62f2892011-05-26 19:48:01377 error_category() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16378 error_category(const error_category&);// = delete;
379 error_category& operator=(const error_category&);// = delete;
380
381public:
Howard Hinnanta62f2892011-05-26 19:48:01382 virtual const char* name() const _NOEXCEPT = 0;
383 virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
384 virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
385 virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16386 virtual string message(int __ev) const = 0;
387
388 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01389 bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;}
Howard Hinnant3e519522010-05-11 19:42:16390
391 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01392 bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);}
Howard Hinnant3e519522010-05-11 19:42:16393
394 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01395 bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;}
Howard Hinnant3e519522010-05-11 19:42:16396
397 friend class __do_message;
398};
399
400class _LIBCPP_HIDDEN __do_message
401 : public error_category
402{
403public:
404 virtual string message(int ev) const;
405};
406
Howard Hinnanta62f2892011-05-26 19:48:01407const error_category& generic_category() _NOEXCEPT;
408const error_category& system_category() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16409
Howard Hinnante0601332010-09-23 17:31:07410class _LIBCPP_VISIBLE error_condition
Howard Hinnant3e519522010-05-11 19:42:16411{
412 int __val_;
413 const error_category* __cat_;
414public:
415 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01416 error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {}
Howard Hinnant3e519522010-05-11 19:42:16417
418 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01419 error_condition(int __val, const error_category& __cat) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16420 : __val_(__val), __cat_(&__cat) {}
421
Howard Hinnantc003db12011-11-29 18:15:50422 template <class _Ep>
Howard Hinnant3e519522010-05-11 19:42:16423 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc003db12011-11-29 18:15:50424 error_condition(_Ep __e,
425 typename enable_if<is_error_condition_enum<_Ep>::value>::type* = 0
Howard Hinnanta62f2892011-05-26 19:48:01426 ) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16427 {*this = make_error_condition(__e);}
428
429 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01430 void assign(int __val, const error_category& __cat) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16431 {
432 __val_ = __val;
433 __cat_ = &__cat;
434 }
435
Howard Hinnantc003db12011-11-29 18:15:50436 template <class _Ep>
Howard Hinnant3e519522010-05-11 19:42:16437 _LIBCPP_ALWAYS_INLINE
438 typename enable_if
439 <
Howard Hinnantc003db12011-11-29 18:15:50440 is_error_condition_enum<_Ep>::value,
Howard Hinnant3e519522010-05-11 19:42:16441 error_condition&
442 >::type
Howard Hinnantc003db12011-11-29 18:15:50443 operator=(_Ep __e) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16444 {*this = make_error_condition(__e); return *this;}
445
446 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01447 void clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16448 {
449 __val_ = 0;
450 __cat_ = &generic_category();
451 }
452
453 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01454 int value() const _NOEXCEPT {return __val_;}
Howard Hinnant3e519522010-05-11 19:42:16455
456 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01457 const error_category& category() const _NOEXCEPT {return *__cat_;}
Howard Hinnant3e519522010-05-11 19:42:16458 string message() const;
459
460 _LIBCPP_ALWAYS_INLINE
461 //explicit
Howard Hinnanta62f2892011-05-26 19:48:01462 operator bool() const _NOEXCEPT {return __val_ != 0;}
Howard Hinnant3e519522010-05-11 19:42:16463};
464
465inline _LIBCPP_INLINE_VISIBILITY
466error_condition
Howard Hinnanta62f2892011-05-26 19:48:01467make_error_condition(errc __e) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16468{
469 return error_condition(static_cast<int>(__e), generic_category());
470}
471
472inline _LIBCPP_INLINE_VISIBILITY
473bool
Howard Hinnanta62f2892011-05-26 19:48:01474operator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16475{
476 return __x.category() < __y.category()
477 || __x.category() == __y.category() && __x.value() < __y.value();
478}
479
480// error_code
481
Howard Hinnante0601332010-09-23 17:31:07482class _LIBCPP_VISIBLE error_code
Howard Hinnant3e519522010-05-11 19:42:16483{
484 int __val_;
485 const error_category* __cat_;
486public:
487 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01488 error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {}
Howard Hinnant3e519522010-05-11 19:42:16489
490 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01491 error_code(int __val, const error_category& __cat) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16492 : __val_(__val), __cat_(&__cat) {}
493
Howard Hinnantc003db12011-11-29 18:15:50494 template <class _Ep>
Howard Hinnant3e519522010-05-11 19:42:16495 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc003db12011-11-29 18:15:50496 error_code(_Ep __e,
497 typename enable_if<is_error_code_enum<_Ep>::value>::type* = 0
Howard Hinnanta62f2892011-05-26 19:48:01498 ) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16499 {*this = make_error_code(__e);}
500
501 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01502 void assign(int __val, const error_category& __cat) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16503 {
504 __val_ = __val;
505 __cat_ = &__cat;
506 }
507
Howard Hinnantc003db12011-11-29 18:15:50508 template <class _Ep>
Howard Hinnant3e519522010-05-11 19:42:16509 _LIBCPP_ALWAYS_INLINE
510 typename enable_if
511 <
Howard Hinnantc003db12011-11-29 18:15:50512 is_error_code_enum<_Ep>::value,
Howard Hinnant3e519522010-05-11 19:42:16513 error_code&
514 >::type
Howard Hinnantc003db12011-11-29 18:15:50515 operator=(_Ep __e) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16516 {*this = make_error_code(__e); return *this;}
517
518 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01519 void clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16520 {
521 __val_ = 0;
522 __cat_ = &system_category();
523 }
524
525 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01526 int value() const _NOEXCEPT {return __val_;}
Howard Hinnant3e519522010-05-11 19:42:16527
528 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01529 const error_category& category() const _NOEXCEPT {return *__cat_;}
Howard Hinnant3e519522010-05-11 19:42:16530
531 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01532 error_condition default_error_condition() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16533 {return __cat_->default_error_condition(__val_);}
534
535 string message() const;
536
537 _LIBCPP_ALWAYS_INLINE
538 //explicit
Howard Hinnanta62f2892011-05-26 19:48:01539 operator bool() const _NOEXCEPT {return __val_ != 0;}
Howard Hinnant3e519522010-05-11 19:42:16540};
541
542inline _LIBCPP_INLINE_VISIBILITY
543error_code
Howard Hinnanta62f2892011-05-26 19:48:01544make_error_code(errc __e) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16545{
546 return error_code(static_cast<int>(__e), generic_category());
547}
548
549inline _LIBCPP_INLINE_VISIBILITY
550bool
Howard Hinnanta62f2892011-05-26 19:48:01551operator<(const error_code& __x, const error_code& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16552{
553 return __x.category() < __y.category()
554 || __x.category() == __y.category() && __x.value() < __y.value();
555}
556
557inline _LIBCPP_INLINE_VISIBILITY
558bool
Howard Hinnanta62f2892011-05-26 19:48:01559operator==(const error_code& __x, const error_code& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16560{
561 return __x.category() == __y.category() && __x.value() == __y.value();
562}
563
564inline _LIBCPP_INLINE_VISIBILITY
565bool
Howard Hinnanta62f2892011-05-26 19:48:01566operator==(const error_code& __x, const error_condition& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16567{
568 return __x.category().equivalent(__x.value(), __y)
569 || __y.category().equivalent(__x, __y.value());
570}
571
572inline _LIBCPP_INLINE_VISIBILITY
573bool
Howard Hinnanta62f2892011-05-26 19:48:01574operator==(const error_condition& __x, const error_code& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16575{
576 return __y == __x;
577}
578
579inline _LIBCPP_INLINE_VISIBILITY
580bool
Howard Hinnanta62f2892011-05-26 19:48:01581operator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16582{
583 return __x.category() == __y.category() && __x.value() == __y.value();
584}
585
586inline _LIBCPP_INLINE_VISIBILITY
587bool
Howard Hinnanta62f2892011-05-26 19:48:01588operator!=(const error_code& __x, const error_code& __y) _NOEXCEPT
589{return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16590
591inline _LIBCPP_INLINE_VISIBILITY
592bool
Howard Hinnanta62f2892011-05-26 19:48:01593operator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT
594{return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16595
596inline _LIBCPP_INLINE_VISIBILITY
597bool
Howard Hinnanta62f2892011-05-26 19:48:01598operator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT
599{return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16600
601inline _LIBCPP_INLINE_VISIBILITY
602bool
Howard Hinnanta62f2892011-05-26 19:48:01603operator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT
604{return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16605
606template <>
Howard Hinnante0601332010-09-23 17:31:07607struct _LIBCPP_VISIBLE hash<error_code>
Howard Hinnant3e519522010-05-11 19:42:16608 : public unary_function<error_code, size_t>
609{
Howard Hinnante0601332010-09-23 17:31:07610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01611 size_t operator()(const error_code& __ec) const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16612 {
613 return static_cast<size_t>(__ec.value());
614 }
615};
616
617// system_error
618
Howard Hinnante0601332010-09-23 17:31:07619class _LIBCPP_VISIBLE system_error
Howard Hinnant3e519522010-05-11 19:42:16620 : public runtime_error
621{
622 error_code __ec_;
623public:
624 system_error(error_code __ec, const string& __what_arg);
625 system_error(error_code __ec, const char* __what_arg);
626 system_error(error_code __ec);
627 system_error(int __ev, const error_category& __ecat, const string& __what_arg);
628 system_error(int __ev, const error_category& __ecat, const char* __what_arg);
629 system_error(int __ev, const error_category& __ecat);
Howard Hinnanta62f2892011-05-26 19:48:01630 ~system_error() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16631
632 _LIBCPP_ALWAYS_INLINE
Howard Hinnanta62f2892011-05-26 19:48:01633 const error_code& code() const _NOEXCEPT {return __ec_;}
Howard Hinnant3e519522010-05-11 19:42:16634
635private:
636 static string __init(const error_code&, string);
637};
638
639void __throw_system_error(int ev, const char* what_arg);
640
641_LIBCPP_END_NAMESPACE_STD
642
643#endif // _LIBCPP_SYSTEM_ERROR