OSDN Git Service

2007-08-29 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / std / system_error
1 // <system_error> -*- C++ -*-
2
3 // Copyright (C) 2007 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING.  If not, write to
18 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 // Boston, MA 02110-1301, USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 /** @file include/system_error
31  *  This is a Standard C++ Library header.
32  */
33
34 #ifndef _GLIBCXX_SYSTEM_ERROR
35 #define _GLIBCXX_SYSTEM_ERROR 1
36
37 #pragma GCC system_header
38
39 #ifndef __GXX_EXPERIMENTAL_CXX0X__
40 # include <c++0x_warning.h>
41 #endif
42
43 #include <bits/c++config.h>
44 #include <cerrno>
45 #include <iosfwd>
46 #include <stdexcept>
47
48 _GLIBCXX_BEGIN_NAMESPACE(std)
49
50   class system_error;
51   class error_code;
52   class error_category;
53
54   extern const error_category& system_category;
55
56   enum posix_errno
57     {
58       address_family_not_supported =            EAFNOSUPPORT,
59       address_in_use =                          EADDRINUSE,
60       address_not_available =                   EADDRNOTAVAIL,
61       already_connected =                       EISCONN,
62       argument_list_too_long =                  E2BIG,
63       argument_out_of_domain =                  EDOM,
64       bad_address =                             EFAULT,
65       bad_file_descriptor =                     EBADF,
66       bad_message =                             EBADMSG,
67       broken_pipe =                             EPIPE,
68       connection_aborted =                      ECONNABORTED,
69       connection_already_in_progress =          EALREADY,
70       connection_refused =                      ECONNREFUSED,
71       connection_reset =                        ECONNRESET,
72       cross_device_link =                       EXDEV,
73       destination_address_required =            EDESTADDRREQ,
74       device_or_resource_busy =                 EBUSY,
75       directory_not_empty =                     ENOTEMPTY,
76       executable_format_error =                 ENOEXEC,
77       file_exists =                             EEXIST,
78       file_too_large =                          EFBIG,
79       filename_too_long =                       ENAMETOOLONG,
80       function_not_supported =                  ENOSYS,
81       host_unreachable =                        EHOSTUNREACH,
82       identifier_removed =                      EIDRM,
83       illegal_byte_sequence =                   EILSEQ,
84       inappropriate_io_control_operation =      ENOTTY,
85       interrupted =                             EINTR,
86       invalid_argument =                        EINVAL,
87       invalid_seek =                            ESPIPE,
88       io_error =                                EIO,
89       is_a_directory =                          EISDIR,
90       message_size =                            EMSGSIZE,
91       network_down =                            ENETDOWN,
92       network_reset =                           ENETRESET,
93       network_unreachable =                     ENETUNREACH,
94       no_buffer_space =                         ENOBUFS,
95       no_child_process =                        ECHILD,
96
97 #ifdef _GLIBCXX_HAVE_ENOLINK
98       no_link =                                 ENOLINK,
99 #endif
100       no_lock_available =                       ENOLCK,
101
102 #ifdef _GLIBCXX_HAVE_ENODATA
103       no_message_available =                    ENODATA, 
104 #endif
105
106       no_message =                              ENOMSG, 
107       no_protocol_option =                      ENOPROTOOPT,
108       no_space_on_device =                      ENOSPC,
109
110 #ifdef _GLIBCXX_HAVE_ENOSR
111       no_stream_resources =                     ENOSR,
112 #endif
113
114       no_such_device_or_address =               ENXIO,
115       no_such_device =                          ENODEV,
116       no_such_file_or_directory =               ENOENT,
117       no_such_process =                         ESRCH,
118       not_a_directory =                         ENOTDIR,
119       not_a_socket =                            ENOTSOCK,
120
121 #ifdef _GLIBCXX_HAVE_ENOSTR
122       not_a_stream =                            ENOSTR,
123 #endif
124
125       not_connected =                           ENOTCONN,
126       not_enough_memory =                       ENOMEM,
127       not_supported =                           ENOTSUP,
128       operation_canceled =                      ECANCELED,
129       operation_in_progress =                   EINPROGRESS,
130       operation_not_permitted =                 EPERM,
131       operation_not_supported =                 EOPNOTSUPP,
132       operation_would_block =                   EWOULDBLOCK,
133 #ifdef _GLIBCXX_HAVE_EOWNERDEAD
134       owner_dead =                              EOWNERDEAD,
135 #endif
136       permission_denied =                       EACCES,
137 #ifdef _GLIBCXX_HAVE_EPROTO
138       protocol_error =                          EPROTO,
139 #endif
140       protocol_not_supported =                  EPROTONOSUPPORT,
141       read_only_file_system =                   EROFS,
142       resource_deadlock_would_occur =           EDEADLK,
143       resource_unavailable_try_again =          EAGAIN,
144       result_out_of_range =                     ERANGE,
145 #ifdef _GLIBCXX_HAVE_ENOTRECOVERABLE
146       state_not_recoverable =                   ENOTRECOVERABLE,
147 #endif
148
149 #ifdef _GLIBCXX_HAVE_ETIME
150       stream_timeout =                          ETIME,
151 #endif
152
153       text_file_busy =                          ETXTBSY,
154       timed_out =                               ETIMEDOUT,
155       too_many_files_open_in_system =           ENFILE,
156       too_many_files_open =                     EMFILE,
157       too_many_links =                          EMLINK,
158       too_many_synbolic_link_levels =           ELOOP,
159       value_too_large =                         EOVERFLOW,
160       wrong_protocol_type =                     EPROTOTYPE,
161       no_posix_equivalent = 1L << 16
162     };
163
164   struct error_category
165   {
166     error_category() { }
167
168     bool 
169     operator==(const error_category& __other) const
170     { return this == &__other; }
171
172     bool 
173     operator!=(const error_category& __other) const
174     { return this != &__other; }
175
176     virtual posix_errno 
177     posix(int __v) const = 0;
178
179     virtual const string& 
180     name() const = 0;
181
182   private:
183     error_category(const error_category&);
184
185     error_category& 
186     operator=(const error_category&);
187   };
188
189   struct error_code
190   {
191     error_code() throw()
192     : _M_value(0), _M_cat(&system_category) { }
193
194     error_code(int __v, const error_category& __cat) throw()
195     : _M_value(__v), _M_cat(&__cat) { }
196
197     error_code(posix_errno __v)
198     : _M_value(__v), _M_cat(&system_category) { }
199
200     void 
201     assign(int __v, const error_category& __cat) throw()
202     {
203       _M_value = __v;
204       _M_cat = &__cat; 
205     }
206
207     void 
208     clear() throw()
209     { 
210       _M_value = 0;
211       _M_cat = &system_category;
212    } 
213
214     int
215     value() const throw() { return _M_value; }
216       
217     const error_category&  
218     category() const { return *_M_cat; }
219
220     posix_errno            
221     posix() const throw() { return this->category().posix(_M_value); }
222
223     // Safe bool idiom.
224     // explicit operator bool() const throw()
225     // { return _M_value != 0; }
226     typedef void (*__bool_type)();
227
228     static void __not_bool_type() { }
229
230     operator __bool_type() const throw()
231     { return _M_value != 0 ? &__not_bool_type : false; }
232
233     bool operator==(const error_code& __other) const
234     { return value() == __other.value() && category() == __other.category(); }
235
236     bool operator!=(const error_code& __other) const
237     { return !(this == &__other); }
238
239   private:
240     int                         _M_value;
241     const error_category*       _M_cat;
242   };
243
244   class system_error : public std::runtime_error
245   {
246   private:
247     error_code  _M_code;
248
249   public:
250     system_error(const string& __what, error_code __ec = error_code())
251     : runtime_error(__what), _M_code(__ec) { }
252
253     system_error(const string& __what, int __v, const error_category& __ecat)
254     : runtime_error(__what), _M_code(error_code(__v, __ecat)) { }
255
256     virtual ~system_error() throw();
257
258     const error_code& 
259     code() const throw() { return _M_code; }
260   };
261
262 _GLIBCXX_END_NAMESPACE
263
264 #endif 
265