2
* Copyright 2008-2011 NVIDIA Corporation
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
/*! \file error_code.h
19
* \brief An object used to hold error values, such as those originating from the
20
* operating system or other low-level application program interfaces.
25
#include <thrust/detail/config.h>
26
#include <thrust/detail/type_traits.h>
27
#include <thrust/system/detail/errno.h>
37
/*! \addtogroup system
41
class error_condition;
44
/*! A metafunction returning whether or not the parameter is an \p error_code enum.
46
template<typename T> struct is_error_code_enum : public thrust::detail::false_type {};
48
/*! A metafunction returning whether or not the parameter is an \p error_condition enum.
50
template<typename T> struct is_error_condition_enum : public thrust::detail::false_type {};
53
// XXX N3092 prefers enum class errc { ... }
59
address_family_not_supported = detail::eafnosupport,
60
address_in_use = detail::eaddrinuse,
61
address_not_available = detail::eaddrnotavail,
62
already_connected = detail::eisconn,
63
argument_list_too_long = detail::e2big,
64
argument_out_of_domain = detail::edom,
65
bad_address = detail::efault,
66
bad_file_descriptor = detail::ebadf,
67
bad_message = detail::ebadmsg,
68
broken_pipe = detail::epipe,
69
connection_aborted = detail::econnaborted,
70
connection_already_in_progress = detail::ealready,
71
connection_refused = detail::econnrefused,
72
connection_reset = detail::econnreset,
73
cross_device_link = detail::exdev,
74
destination_address_required = detail::edestaddrreq,
75
device_or_resource_busy = detail::ebusy,
76
directory_not_empty = detail::enotempty,
77
executable_format_error = detail::enoexec,
78
file_exists = detail::eexist,
79
file_too_large = detail::efbig,
80
filename_too_long = detail::enametoolong,
81
function_not_supported = detail::enosys,
82
host_unreachable = detail::ehostunreach,
83
identifier_removed = detail::eidrm,
84
illegal_byte_sequence = detail::eilseq,
85
inappropriate_io_control_operation = detail::enotty,
86
interrupted = detail::eintr,
87
invalid_argument = detail::einval,
88
invalid_seek = detail::espipe,
89
io_error = detail::eio,
90
is_a_directory = detail::eisdir,
91
message_size = detail::emsgsize,
92
network_down = detail::enetdown,
93
network_reset = detail::enetreset,
94
network_unreachable = detail::enetunreach,
95
no_buffer_space = detail::enobufs,
96
no_child_process = detail::echild,
97
no_link = detail::enolink,
98
no_lock_available = detail::enolck,
99
no_message_available = detail::enodata,
100
no_message = detail::enomsg,
101
no_protocol_option = detail::enoprotoopt,
102
no_space_on_device = detail::enospc,
103
no_stream_resources = detail::enosr,
104
no_such_device_or_address = detail::enxio,
105
no_such_device = detail::enodev,
106
no_such_file_or_directory = detail::enoent,
107
no_such_process = detail::esrch,
108
not_a_directory = detail::enotdir,
109
not_a_socket = detail::enotsock,
110
not_a_stream = detail::enostr,
111
not_connected = detail::enotconn,
112
not_enough_memory = detail::enomem,
113
not_supported = detail::enotsup,
114
operation_canceled = detail::ecanceled,
115
operation_in_progress = detail::einprogress,
116
operation_not_permitted = detail::eperm,
117
operation_not_supported = detail::eopnotsupp,
118
operation_would_block = detail::ewouldblock,
119
owner_dead = detail::eownerdead,
120
permission_denied = detail::eacces,
121
protocol_error = detail::eproto,
122
protocol_not_supported = detail::eprotonosupport,
123
read_only_file_system = detail::erofs,
124
resource_deadlock_would_occur = detail::edeadlk,
125
resource_unavailable_try_again = detail::eagain,
126
result_out_of_range = detail::erange,
127
state_not_recoverable = detail::enotrecoverable,
128
stream_timeout = detail::etime,
129
text_file_busy = detail::etxtbsy,
130
timed_out = detail::etimedout,
131
too_many_files_open_in_system = detail::enfile,
132
too_many_files_open = detail::emfile,
133
too_many_links = detail::emlink,
134
too_many_symbolic_link_levels = detail::eloop,
135
value_too_large = detail::eoverflow,
136
wrong_protocol_type = detail::eprototype,
139
} // end namespace errc
142
template<> struct is_error_condition_enum<errc::errc_t> : public thrust::detail::true_type {};
145
// [19.5.1.1] class error_category
147
/*! \brief The class \p error_category serves as a base class for types used to identify the
148
* source and encoding of a particular category of error code. Classes may be derived
149
* from \p error_category to support categories of errors in addition to those defined
150
* in the C++ International Standard.
155
/*! Destructor does nothing.
157
inline virtual ~error_category(void);
159
// XXX enable upon c++0x
160
// error_category(const error_category &) = delete;
161
// error_category &operator=(const error_category &) = delete;
163
/*! \return A string naming the error category.
165
inline virtual const char *name(void) const = 0;
167
/*! \return \p error_condition(ev, *this).
169
inline virtual error_condition default_error_condition(int ev) const;
171
/*! \return <tt>default_error_condition(code) == condition</tt>
173
inline virtual bool equivalent(int code, const error_condition &condition) const;
175
/*! \return <tt>*this == code.category() && code.value() == condition</tt>
177
inline virtual bool equivalent(const error_code &code, int condition) const;
179
/*! \return A string that describes the error condition denoted by \p ev.
181
virtual std::string message(int ev) const = 0;
183
/*! \return <tt>*this == &rhs</tt>
185
inline bool operator==(const error_category &rhs) const;
187
/*! \return <tt>!(*this == rhs)</tt>
189
inline bool operator!=(const error_category &rhs) const;
191
/*! \return <tt>less<const error_category*>()(this, &rhs)</tt>
192
* \note \c less provides a total ordering for pointers.
194
inline bool operator<(const error_category &rhs) const;
195
}; // end error_category
198
// [19.5.1.5] error_category objects
201
/*! \return A reference to an object of a type derived from class \p error_category.
202
* \note The object's \p default_error_condition and \p equivalent virtual functions
203
* shall behave as specified for the class \p error_category. The object's
204
* \p name virtual function shall return a pointer to the string <tt>"generic"</tt>.
206
inline const error_category &generic_category(void);
209
/*! \return A reference to an object of a type derived from class \p error_category.
210
* \note The object's \p equivalent virtual functions shall behave as specified for
211
* class \p error_category. The object's \p name virtual function shall return
212
* a pointer to the string <tt>"system"</tt>. The object's \p default_error_condition
213
* virtual function shall behave as follows:
215
* If the argument <tt>ev</tt> corresponds to a POSIX <tt>errno</tt> value
216
* \c posv, the function shall return <tt>error_condition(ev,generic_category())</tt>.
217
* Otherwise, the function shall return <tt>error_condition(ev,system_category())</tt>.
218
* What constitutes correspondence for any given operating system is unspecified.
220
inline const error_category &system_category(void);
223
// [19.5.2] Class error_code
226
/*! \brief The class \p error_code describes an object used to hold error code values, such as
227
* those originating from the operating system or other low-level application program
233
// [19.5.2.2] constructors:
235
/*! Effects: Constructs an object of type \p error_code.
236
* \post <tt>value() == 0</tt> and <tt>category() == &system_category()</tt>.
238
inline error_code(void);
240
/*! Effects: Constructs an object of type \p error_code.
241
* \post <tt>value() == val</tt> and <tt>category() == &cat</tt>.
243
inline error_code(int val, const error_category &cat);
245
/*! Effects: Constructs an object of type \p error_code.
246
* \post <tt>*this == make_error_code(e)</tt>.
248
template <typename ErrorCodeEnum>
249
error_code(ErrorCodeEnum e
250
// XXX WAR msvc's problem with enable_if
251
#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
252
, typename thrust::detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value>::type * = 0
253
#endif // THRUST_HOST_COMPILER_MSVC
256
// [19.5.2.3] modifiers:
258
/*! \post <tt>value() == val</tt> and <tt>category() == &cat</tt>.
260
inline void assign(int val, const error_category &cat);
262
/*! \post <tt>*this == make_error_code(e)</tt>.
264
template <typename ErrorCodeEnum>
265
// XXX WAR msvc's problem with enable_if
266
#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
267
typename thrust::detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value, error_code>::type &
270
#endif // THRUST_HOST_COMPILER_MSVC
271
operator=(ErrorCodeEnum e);
273
/*! \post <tt>value() == 0</tt> and <tt>category() == system_category()</tt>.
275
inline void clear(void);
277
// [19.5.2.4] observers:
279
/*! \return An integral value of this \p error_code object.
281
inline int value(void) const;
283
/*! \return An \p error_category describing the category of this \p error_code object.
285
inline const error_category &category(void) const;
287
/*! \return <tt>category().default_error_condition()</tt>.
289
inline error_condition default_error_condition(void) const;
291
/*! \return <tt>category().message(value())</tt>.
293
inline std::string message(void) const;
295
// XXX replace the below upon c++0x
296
// inline explicit operator bool (void) const;
298
/*! \return <tt>value() != 0</tt>.
300
inline operator bool (void) const;
306
const error_category *m_cat;
312
// [19.5.2.5] Class error_code non-member functions
315
// XXX replace errc::errc_t with errc upon c++0x
316
/*! \return <tt>error_code(static_cast<int>(e), generic_category())</tt>
318
inline error_code make_error_code(errc::errc_t e);
321
/*! \return <tt>lhs.category() < rhs.category() || lhs.category() == rhs.category() && lhs.value() < rhs.value()</tt>.
323
inline bool operator<(const error_code &lhs, const error_code &rhs);
326
/*! Effects: <tt>os << ec.category().name() << ':' << ec.value()</tt>.
328
template <typename charT, typename traits>
329
std::basic_ostream<charT,traits>&
330
operator<<(std::basic_ostream<charT,traits>& os, const error_code &ec);
333
// [19.5.3] class error_condition
336
/*! \brief The class \p error_condition describes an object used to hold values identifying
339
* \note \p error_condition values are portable abstractions, while \p error_code values
340
* are implementation specific.
342
class error_condition
345
// [19.5.3.2] constructors
347
/*! Constructs an object of type \p error_condition.
348
* \post <tt>value() == 0</tt>.
349
* \post <tt>category() == generic_category()</tt>.
351
inline error_condition(void);
353
/*! Constructs an object of type \p error_condition.
354
* \post <tt>value() == val</tt>.
355
* \post <tt>category() == cat</tt>.
357
inline error_condition(int val, const error_category &cat);
359
/*! Constructs an object of type \p error_condition.
360
* \post <tt>*this == make_error_condition(e)</tt>.
361
* \note This constructor shall not participate in overload resolution unless
362
* <tt>is_error_condition_enum<ErrorConditionEnum>::value</tt> is <tt>true</tt>.
364
template<typename ErrorConditionEnum>
365
error_condition(ErrorConditionEnum e
366
// XXX WAR msvc's problem with enable_if
367
#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
368
, typename thrust::detail::enable_if<is_error_condition_enum<ErrorConditionEnum>::value>::type * = 0
369
#endif // THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
372
// [19.5.3.3] modifiers
374
/*! Assigns to this \p error_code object from an error value and an \p error_category.
375
* \param val The new value to return from <tt>value()</tt>.
376
* \param cat The new \p error_category to return from <tt>category()</tt>.
377
* \post <tt>value() == val</tt>.
378
* \post <tt>category() == cat</tt>.
380
inline void assign(int val, const error_category &cat);
382
/*! Assigns to this \p error_code object from an error condition enumeration.
384
* \post <tt>*this == make_error_condition(e)</tt>.
385
* \note This operator shall not participate in overload resolution unless
386
* <tt>is_error_condition_enum<ErrorConditionEnum>::value</tt> is <tt>true</tt>.
388
template<typename ErrorConditionEnum>
389
// XXX WAR msvc's problem with enable_if
390
#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
391
typename thrust::detail::enable_if<is_error_condition_enum<ErrorConditionEnum>::value, error_condition>::type &
394
#endif // THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
395
operator=(ErrorConditionEnum e);
397
/*! Clears this \p error_code object.
398
* \post <tt>value == 0</tt>
399
* \post <tt>category() == generic_category()</tt>.
401
inline void clear(void);
403
// [19.5.3.4] observers
405
/*! \return The value encoded by this \p error_condition.
407
inline int value(void) const;
409
/*! \return A <tt>const</tt> reference to the \p error_category encoded by this \p error_condition.
411
inline const error_category &category(void) const;
413
/*! \return <tt>category().message(value())</tt>.
415
inline std::string message(void) const;
417
// XXX replace below with this upon c++0x
418
//explicit operator bool (void) const;
420
/*! \return <tt>value() != 0</tt>.
422
inline operator bool (void) const;
429
const error_category *m_cat;
433
}; // end error_condition
437
// [19.5.3.5] Class error_condition non-member functions
439
// XXX replace errc::errc_t with errc upon c++0x
440
/*! \return <tt>error_condition(static_cast<int>(e), generic_category())</tt>.
442
inline error_condition make_error_condition(errc::errc_t e);
445
/*! \return <tt>lhs.category() < rhs.category() || lhs.category() == rhs.category() && lhs.value() < rhs.value()</tt>.
447
inline bool operator<(const error_condition &lhs, const error_condition &rhs);
450
// [19.5.4] Comparison operators
453
/*! \return <tt>lhs.category() == rhs.category() && lhs.value() == rhs.value()</tt>.
455
inline bool operator==(const error_code &lhs, const error_code &rhs);
458
/*! \return <tt>lhs.category().equivalent(lhs.value(), rhs) || rhs.category().equivalent(lhs,rhs.value())</tt>.
460
inline bool operator==(const error_code &lhs, const error_condition &rhs);
463
/*! \return <tt>rhs.category().equivalent(lhs.value(), lhs) || lhs.category().equivalent(rhs, lhs.value())</tt>.
465
inline bool operator==(const error_condition &lhs, const error_code &rhs);
468
/*! \return <tt>lhs.category() == rhs.category() && lhs.value() == rhs.value()</tt>
470
inline bool operator==(const error_condition &lhs, const error_condition &rhs);
473
/*! \return <tt>!(lhs == rhs)</tt>
475
inline bool operator!=(const error_code &lhs, const error_code &rhs);
478
/*! \return <tt>!(lhs == rhs)</tt>
480
inline bool operator!=(const error_code &lhs, const error_condition &rhs);
483
/*! \return <tt>!(lhs == rhs)</tt>
485
inline bool operator!=(const error_condition &lhs, const error_code &rhs);
488
/*! \return <tt>!(lhs == rhs)</tt>
490
inline bool operator!=(const error_condition &lhs, const error_condition &rhs);
499
// import names into thrust::
500
using system::error_category;
501
using system::error_code;
502
using system::error_condition;
503
using system::is_error_code_enum;
504
using system::is_error_condition_enum;
505
using system::make_error_code;
506
using system::make_error_condition;
508
// XXX replace with using system::errc upon c++0x
509
namespace errc = system::errc;
511
using system::generic_category;
512
using system::system_category;
516
#include <thrust/system/detail/error_category.inl>
517
#include <thrust/system/detail/error_code.inl>
518
#include <thrust/system/detail/error_condition.inl>