File: error_code.h

package info (click to toggle)
libthrust 1.17.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,900 kB
  • sloc: ansic: 29,519; cpp: 23,989; python: 1,421; sh: 811; perl: 460; makefile: 112
file content (522 lines) | stat: -rw-r--r-- 18,347 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
/*
 *  Copyright 2008-2013 NVIDIA Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */


/*! \file error_code.h
 *  \brief An object used to hold error values, such as those originating from the
 *         operating system or other low-level application program interfaces.
 */

#pragma once

#include <thrust/detail/config.h>
#include <thrust/detail/type_traits.h>
#include <thrust/system/detail/errno.h>
#include <iostream>

THRUST_NAMESPACE_BEGIN

namespace system
{


/*! \addtogroup system_diagnostics
 *  \{
 */

class error_condition;
class error_code;

/*! A metafunction returning whether or not the parameter is an \p error_code enum.
 */
template<typename T> struct is_error_code_enum : public thrust::detail::false_type {};

/*! A metafunction returning whether or not the parameter is an \p error_condition enum.
 */
template<typename T> struct is_error_condition_enum : public thrust::detail::false_type {};


// XXX N3092 prefers enum class errc { ... }
namespace errc
{

/*! An enum containing common error codes.
 */
enum errc_t
{
  address_family_not_supported       = detail::eafnosupport,
  address_in_use                     = detail::eaddrinuse,
  address_not_available              = detail::eaddrnotavail,
  already_connected                  = detail::eisconn,
  argument_list_too_long             = detail::e2big,
  argument_out_of_domain             = detail::edom,
  bad_address                        = detail::efault,
  bad_file_descriptor                = detail::ebadf,
  bad_message                        = detail::ebadmsg,
  broken_pipe                        = detail::epipe,
  connection_aborted                 = detail::econnaborted,
  connection_already_in_progress     = detail::ealready,
  connection_refused                 = detail::econnrefused,
  connection_reset                   = detail::econnreset,
  cross_device_link                  = detail::exdev,
  destination_address_required       = detail::edestaddrreq,
  device_or_resource_busy            = detail::ebusy,
  directory_not_empty                = detail::enotempty,
  executable_format_error            = detail::enoexec,
  file_exists                        = detail::eexist,
  file_too_large                     = detail::efbig,
  filename_too_long                  = detail::enametoolong,
  function_not_supported             = detail::enosys,
  host_unreachable                   = detail::ehostunreach,
  identifier_removed                 = detail::eidrm,
  illegal_byte_sequence              = detail::eilseq,
  inappropriate_io_control_operation = detail::enotty,
  interrupted                        = detail::eintr,
  invalid_argument                   = detail::einval,
  invalid_seek                       = detail::espipe,
  io_error                           = detail::eio,
  is_a_directory                     = detail::eisdir,
  message_size                       = detail::emsgsize,
  network_down                       = detail::enetdown,
  network_reset                      = detail::enetreset,
  network_unreachable                = detail::enetunreach,
  no_buffer_space                    = detail::enobufs,
  no_child_process                   = detail::echild,
  no_link                            = detail::enolink,
  no_lock_available                  = detail::enolck,
  no_message_available               = detail::enodata,
  no_message                         = detail::enomsg,
  no_protocol_option                 = detail::enoprotoopt,
  no_space_on_device                 = detail::enospc,
  no_stream_resources                = detail::enosr,
  no_such_device_or_address          = detail::enxio,
  no_such_device                     = detail::enodev,
  no_such_file_or_directory          = detail::enoent,
  no_such_process                    = detail::esrch,
  not_a_directory                    = detail::enotdir,
  not_a_socket                       = detail::enotsock,
  not_a_stream                       = detail::enostr,
  not_connected                      = detail::enotconn,
  not_enough_memory                  = detail::enomem,
  not_supported                      = detail::enotsup,
  operation_canceled                 = detail::ecanceled,
  operation_in_progress              = detail::einprogress,
  operation_not_permitted            = detail::eperm,
  operation_not_supported            = detail::eopnotsupp,
  operation_would_block              = detail::ewouldblock,
  owner_dead                         = detail::eownerdead,
  permission_denied                  = detail::eacces,
  protocol_error                     = detail::eproto,
  protocol_not_supported             = detail::eprotonosupport,
  read_only_file_system              = detail::erofs,
  resource_deadlock_would_occur      = detail::edeadlk,
  resource_unavailable_try_again     = detail::eagain,
  result_out_of_range                = detail::erange,
  state_not_recoverable              = detail::enotrecoverable,
  stream_timeout                     = detail::etime,
  text_file_busy                     = detail::etxtbsy,
  timed_out                          = detail::etimedout,
  too_many_files_open_in_system      = detail::enfile,
  too_many_files_open                = detail::emfile,
  too_many_links                     = detail::emlink,
  too_many_symbolic_link_levels      = detail::eloop,
  value_too_large                    = detail::eoverflow,
  wrong_protocol_type                = detail::eprototype
}; // end errc_t

} // end namespace errc


/*! Specialization of \p is_error_condition_enum for \p errc::errc_t
 */
template<> struct is_error_condition_enum<errc::errc_t> : public thrust::detail::true_type {};


// [19.5.1.1] class error_category

/*! \brief The class \p error_category serves as a base class for types used to identify the
 *         source and encoding of a particular category of error code. Classes may be derived
 *         from \p error_category to support categories of errors in addition to those defined
 *         in the C++ International Standard.
 */
class error_category
{
  public:
    /*! Destructor does nothing.
     */
    inline virtual ~error_category(void);

    // XXX enable upon c++0x
    // error_category(const error_category &) = delete;
    // error_category &operator=(const error_category &) = delete;

    /*! \return A string naming the error category.
     */
    inline virtual const char *name(void) const = 0;

    /*! \return \p error_condition(ev, *this).
     */
    inline virtual error_condition default_error_condition(int ev) const;

    /*! \return <tt>default_error_condition(code) == condition</tt>
     */
    inline virtual bool equivalent(int code, const error_condition &condition) const;

    /*! \return <tt>*this == code.category() && code.value() == condition</tt>
     */
    inline virtual bool equivalent(const error_code &code, int condition) const;

    /*! \return A string that describes the error condition denoted by \p ev.
     */
    virtual std::string message(int ev) const = 0;

    /*! \return <tt>*this == &rhs</tt>
     */
    inline bool operator==(const error_category &rhs) const;

    /*! \return <tt>!(*this == rhs)</tt>
     */
    inline bool operator!=(const error_category &rhs) const;

    /*! \return <tt>less<const error_category*>()(this, &rhs)</tt>
     *  \note \c less provides a total ordering for pointers.
     */
    inline bool operator<(const error_category &rhs) const;
}; // end error_category


// [19.5.1.5] error_category objects


/*! \return A reference to an object of a type derived from class \p error_category.
 *  \note The object's \p default_error_condition and \p equivalent virtual functions
 *        shall behave as specified for the class \p error_category. The object's
 *        \p name virtual function shall return a pointer to the string <tt>"generic"</tt>.
 */
inline const error_category &generic_category(void);


/*! \return A reference to an object of a type derived from class \p error_category.
 *  \note The object's \p equivalent virtual functions shall behave as specified for
 *        class \p error_category. The object's \p name virtual function shall return
 *        a pointer to the string <tt>"system"</tt>. The object's \p default_error_condition
 *        virtual function shall behave as follows:
 *
 *        If the argument <tt>ev</tt> corresponds to a POSIX <tt>errno</tt> value
 *        \c posv, the function shall return <tt>error_condition(ev,generic_category())</tt>.
 *        Otherwise, the function shall return <tt>error_condition(ev,system_category())</tt>.
 *        What constitutes correspondence for any given operating system is unspecified.
 */
inline const error_category &system_category(void);


// [19.5.2] Class error_code


/*! \brief The class \p error_code describes an object used to hold error code values, such as
 *         those originating from the operating system or other low-level application program
 *         interfaces.
 */
class error_code
{
  public:
    // [19.5.2.2] constructors:

    /*! Effects: Constructs an object of type \p error_code.
     *  \post <tt>value() == 0</tt> and <tt>category() == &system_category()</tt>.
     */
    inline error_code(void);

    /*! Effects: Constructs an object of type \p error_code.
     *  \post <tt>value() == val</tt> and <tt>category() == &cat</tt>.
     */
    inline error_code(int val, const error_category &cat);

    /*! Effects: Constructs an object of type \p error_code.
     *  \post <tt>*this == make_error_code(e)</tt>.
     */
    template <typename ErrorCodeEnum>
      error_code(ErrorCodeEnum e
// XXX WAR msvc's problem with enable_if
#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
        , typename thrust::detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value>::type * = 0
#endif // THRUST_HOST_COMPILER_MSVC
        );

    // [19.5.2.3] modifiers:

    /*! \post <tt>value() == val</tt> and <tt>category() == &cat</tt>.
     */
    inline void assign(int val, const error_category &cat);

    /*! \post <tt>*this == make_error_code(e)</tt>.
     */
    template <typename ErrorCodeEnum>
// XXX WAR msvc's problem with enable_if
#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
      typename thrust::detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value, error_code>::type &
#else
      error_code &
#endif // THRUST_HOST_COMPILER_MSVC
        operator=(ErrorCodeEnum e);

    /*! \post <tt>value() == 0</tt> and <tt>category() == system_category()</tt>.
     */
    inline void clear(void);

    // [19.5.2.4] observers:

    /*! \return An integral value of this \p error_code object.
     */
    inline int value(void) const;

    /*! \return An \p error_category describing the category of this \p error_code object.
     */
    inline const error_category &category(void) const;

    /*! \return <tt>category().default_error_condition()</tt>.
     */
    inline error_condition default_error_condition(void) const;

    /*! \return <tt>category().message(value())</tt>.
     */
    inline std::string message(void) const;

    // XXX replace the below upon c++0x
    // inline explicit operator bool (void) const;

    /*! \return <tt>value() != 0</tt>.
     */
    inline operator bool (void) const;

    /*! \cond
     */
  private:
    int m_val;
    const error_category *m_cat;
    /*! \endcond
     */
}; // end error_code


// [19.5.2.5] Class error_code non-member functions


// XXX replace errc::errc_t with errc upon c++0x
/*! \return <tt>error_code(static_cast<int>(e), generic_category())</tt>
 */
inline error_code make_error_code(errc::errc_t e);


/*! \return <tt>lhs.category() < rhs.category() || lhs.category() == rhs.category() && lhs.value() < rhs.value()</tt>.
 */
inline bool operator<(const error_code &lhs, const error_code &rhs);


/*! Effects: <tt>os << ec.category().name() << ':' << ec.value()</tt>.
 */
template <typename charT, typename traits>
  std::basic_ostream<charT,traits>&
    operator<<(std::basic_ostream<charT,traits>& os, const error_code &ec);


// [19.5.3] class error_condition


/*! \brief The class \p error_condition describes an object used to hold values identifying
 *  error conditions.
 *
 *  \note \p error_condition values are portable abstractions, while \p error_code values
 *        are implementation specific.
 */
class error_condition
{
  public:
    // [19.5.3.2] constructors

    /*! Constructs an object of type \p error_condition.
     *  \post <tt>value() == 0</tt>.
     *  \post <tt>category() == generic_category()</tt>.
     */
    inline error_condition(void);

    /*! Constructs an object of type \p error_condition.
     *  \post <tt>value() == val</tt>.
     *  \post <tt>category() == cat</tt>.
     */
    inline error_condition(int val, const error_category &cat);

    /*! Constructs an object of type \p error_condition.
     *  \post <tt>*this == make_error_condition(e)</tt>.
     *  \note This constructor shall not participate in overload resolution unless
     *        <tt>is_error_condition_enum<ErrorConditionEnum>::value</tt> is <tt>true</tt>.
     */
    template<typename ErrorConditionEnum>
      error_condition(ErrorConditionEnum e
// XXX WAR msvc's problem with enable_if
#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
        , typename thrust::detail::enable_if<is_error_condition_enum<ErrorConditionEnum>::value>::type * = 0
#endif // THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
                     );

    // [19.5.3.3] modifiers

    /*! Assigns to this \p error_code object from an error value and an \p error_category.
     *  \param val The new value to return from <tt>value()</tt>.
     *  \param cat The new \p error_category to return from <tt>category()</tt>.
     *  \post <tt>value() == val</tt>.
     *  \post <tt>category() == cat</tt>.
     */
    inline void assign(int val, const error_category &cat);

    /*! Assigns to this \p error_code object from an error condition enumeration.
     *  \return *this
     *  \post <tt>*this == make_error_condition(e)</tt>.
     *  \note This operator shall not participate in overload resolution unless
     *        <tt>is_error_condition_enum<ErrorConditionEnum>::value</tt> is <tt>true</tt>.
     */
    template<typename ErrorConditionEnum>
// XXX WAR msvc's problem with enable_if
#if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
      typename thrust::detail::enable_if<is_error_condition_enum<ErrorConditionEnum>::value, error_condition>::type &
#else
      error_condition &
#endif // THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
        operator=(ErrorConditionEnum e);

    /*! Clears this \p error_code object.
     *  \post <tt>value == 0</tt>
     *  \post <tt>category() == generic_category()</tt>.
     */
    inline void clear(void);

    // [19.5.3.4] observers

    /*! \return The value encoded by this \p error_condition.
     */
    inline int value(void) const;

    /*! \return A <tt>const</tt> reference to the \p error_category encoded by this \p error_condition.
     */
    inline const error_category &category(void) const;

    /*! \return <tt>category().message(value())</tt>.
     */
    inline std::string message(void) const;

    // XXX replace below with this upon c++0x
    //explicit operator bool (void) const;
    
    /*! \return <tt>value() != 0</tt>.
     */
    inline operator bool (void) const;

    /*! \cond
     */

  private:
    int m_val;
    const error_category *m_cat;

    /*! \endcond
     */
}; // end error_condition



// [19.5.3.5] Class error_condition non-member functions

// XXX replace errc::errc_t with errc upon c++0x
/*! \return <tt>error_condition(static_cast<int>(e), generic_category())</tt>.
 */
inline error_condition make_error_condition(errc::errc_t e);


/*! \return <tt>lhs.category() < rhs.category() || lhs.category() == rhs.category() && lhs.value() < rhs.value()</tt>.
 */
inline bool operator<(const error_condition &lhs, const error_condition &rhs);


// [19.5.4] Comparison operators


/*! \return <tt>lhs.category() == rhs.category() && lhs.value() == rhs.value()</tt>.
 */
inline bool operator==(const error_code &lhs, const error_code &rhs);


/*! \return <tt>lhs.category().equivalent(lhs.value(), rhs) || rhs.category().equivalent(lhs,rhs.value())</tt>.
 */
inline bool operator==(const error_code &lhs, const error_condition &rhs);


/*! \return <tt>rhs.category().equivalent(lhs.value(), lhs) || lhs.category().equivalent(rhs, lhs.value())</tt>.
 */
inline bool operator==(const error_condition &lhs, const error_code &rhs);


/*! \return <tt>lhs.category() == rhs.category() && lhs.value() == rhs.value()</tt>
 */
inline bool operator==(const error_condition &lhs, const error_condition &rhs);


/*! \return <tt>!(lhs == rhs)</tt>
 */
inline bool operator!=(const error_code &lhs, const error_code &rhs);


/*! \return <tt>!(lhs == rhs)</tt>
 */
inline bool operator!=(const error_code &lhs, const error_condition &rhs);


/*! \return <tt>!(lhs == rhs)</tt>
 */
inline bool operator!=(const error_condition &lhs, const error_code &rhs);


/*! \return <tt>!(lhs == rhs)</tt>
 */
inline bool operator!=(const error_condition &lhs, const error_condition &rhs);

/*! \} // end system_diagnostics
 */


} // end system


// import names into thrust::
using system::error_category;
using system::error_code;
using system::error_condition;
using system::is_error_code_enum;
using system::is_error_condition_enum;
using system::make_error_code;
using system::make_error_condition;

// XXX replace with using system::errc upon c++0x
namespace errc = system::errc;

using system::generic_category;
using system::system_category;

THRUST_NAMESPACE_END

#include <thrust/system/detail/error_category.inl>
#include <thrust/system/detail/error_code.inl>
#include <thrust/system/detail/error_condition.inl>