BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslstl_errc.h
Go to the documentation of this file.
1/// @file bslstl_errc.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_errc.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_ERRC
9#define INCLUDED_BSLSTL_ERRC
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14// BDE_VERIFY pragma: -TP25 // CLASSES are not defined in C++11
15
16/// @defgroup bslstl_errc bslstl_errc
17/// @brief Provide a standard compliant version of `errc`.
18/// @addtogroup bsl
19/// @{
20/// @addtogroup bslstl
21/// @{
22/// @addtogroup bslstl_errc
23/// @{
24///
25/// <h1> Outline </h1>
26/// * <a href="#bslstl_errc-purpose"> Purpose</a>
27/// * <a href="#bslstl_errc-classes"> Classes </a>
28/// * <a href="#bslstl_errc-description"> Description </a>
29/// * <a href="#bslstl_errc-usage"> Usage </a>
30/// * <a href="#bslstl_errc-example-1-descriptive-system-error-value-names"> Example 1: Descriptive System Error Value Names </a>
31///
32/// # Purpose {#bslstl_errc-purpose}
33/// Provide a standard compliant version of `errc`.
34///
35/// # Classes {#bslstl_errc-classes}
36///
37/// - bsl::errc: namespace for `errc` enumeration type
38/// - bsl::ErrcEnum: `typedef` for `bsl::errc::Enum` or `std::errc`
39///
40/// **Canonical header:** bsl_system_error.h
41///
42/// # Description {#bslstl_errc-description}
43/// This component defines an enumeration `bsl::errc::Enum`, and
44/// marks it eligible to participate as an error condition in the @ref system_error
45/// facility. In C++11 mode, the vendor-supplied `<system_error>`
46/// implementation is used instead, and the corresponding names from `std` are
47/// imported into `bsl`.
48///
49/// This component also defines the type alias `bsl::ErrcEnum` that can be used
50/// as the type of the `errc` enumeration in both C++03 and C++11 mode. Because
51/// `errc` is defined in C++11 as an `enum class`, we cannot emulate use of
52/// `std::errc` in C++03 mode - that tag can either be used to qualify the
53/// enumeration literals or name the type, but not both. This component chooses
54/// to have `bsl::errc` be the literal qualifier and `bsl::ErrcEnum` be the type
55/// so to use this component portably, one would, for example, write
56/// @code
57/// bsl::ErrcEnum error_value = bsl::errc::io_error;
58/// @endcode
59///
60/// ## Usage {#bslstl_errc-usage}
61///
62///
63/// In this section we show intended use of this component.
64///
65/// ### Example 1: Descriptive System Error Value Names {#bslstl_errc-example-1-descriptive-system-error-value-names}
66///
67///
68/// Suppose we would like to have more descriptive and non-macro names for
69/// `errno` system error values. We can use the `errc` from the @ref system_error
70/// facility of the C++ standard for this.
71///
72/// First, we do something that will set an error value.
73/// @code
74/// strtod("1e2000", 0);
75/// @endcode
76/// Finally, we check for that error using the descriptive name.
77/// @code
78/// bsl::ErrcEnum expected = bsl::errc::result_out_of_range;
79/// assert(static_cast<int>(expected) == errno);
80/// @endcode
81/// @}
82/** @} */
83/** @} */
84
85/** @addtogroup bsl
86 * @{
87 */
88/** @addtogroup bslstl
89 * @{
90 */
91/** @addtogroup bslstl_errc
92 * @{
93 */
94
95#include <bslscm_version.h>
96
98
100
101#include <bsls_libraryfeatures.h>
102
103#include <errno.h>
104
105#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
106#include <bsls_nativestd.h>
107#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
108
109#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
110
111#include <system_error>
112
113namespace bsl {
114using std::errc;
115
116typedef std::errc ErrcEnum; // Portable typedef for 'errc'
117} // close namespace bsl
118
119#else
120
121namespace bsl {
122
123 // =============
124 // struct 'errc'
125 // =============
126
127/// This `struct` defines an enumeration type that provides named literals
128/// for the `errno` values defined in the `<cerrno>` header. Note that in
129/// the C++11 standard, `std::errc` is defined as an `enum class`, so that
130/// literals can be qualified with `std::errc::` and objects of the type can
131/// be declared as `std::errc`. In C++03 mode, we cannot have both, and we
132/// have chosen in favor of allowing the literals to be qualified, so
133/// objects of the type must be declared as `bsl::errc::Enum`. For
134/// portability between modes, declare objects of the enumeration type as
135/// `bsl::ErrcEnum`.
136struct errc {
137
138 // TYPES
139 enum Enum {
140 address_family_not_supported = EAFNOSUPPORT,
141 address_in_use = EADDRINUSE,
142 address_not_available = EADDRNOTAVAIL,
143 already_connected = EISCONN,
144 argument_list_too_long = E2BIG,
145 argument_out_of_domain = EDOM,
146 bad_address = EFAULT,
147 bad_file_descriptor = EBADF,
148 bad_message = EBADMSG,
149 broken_pipe = EPIPE,
150 connection_aborted = ECONNABORTED,
151 connection_already_in_progress = EALREADY,
152 connection_refused = ECONNREFUSED,
153 connection_reset = ECONNRESET,
154 cross_device_link = EXDEV,
155 destination_address_required = EDESTADDRREQ,
156 device_or_resource_busy = EBUSY,
157 directory_not_empty = ENOTEMPTY,
158 executable_format_error = ENOEXEC,
159 file_exists = EEXIST,
160 file_too_large = EFBIG,
161 filename_too_long = ENAMETOOLONG,
162 function_not_supported = ENOSYS,
163 host_unreachable = EHOSTUNREACH,
164 identifier_removed = EIDRM,
165 illegal_byte_sequence = EILSEQ,
166 inappropriate_io_control_operation = ENOTTY,
167 interrupted = EINTR,
168 invalid_argument = EINVAL,
169 invalid_seek = ESPIPE,
170 io_error = EIO,
171 is_a_directory = EISDIR,
172 message_size = EMSGSIZE,
173 network_down = ENETDOWN,
174 network_reset = ENETRESET,
175 network_unreachable = ENETUNREACH,
176 no_buffer_space = ENOBUFS,
177 no_child_process = ECHILD,
178 no_link = ENOLINK,
179 no_lock_available = ENOLCK,
180 no_message_available = ENODATA,
181 no_message = ENOMSG,
182 no_protocol_option = ENOPROTOOPT,
183 no_space_on_device = ENOSPC,
184 no_stream_resources = ENOSR,
185 no_such_device_or_address = ENXIO,
186 no_such_device = ENODEV,
187 no_such_file_or_directory = ENOENT,
188 no_such_process = ESRCH,
189 not_a_directory = ENOTDIR,
190 not_a_socket = ENOTSOCK,
191 not_a_stream = ENOSTR,
192 not_connected = ENOTCONN,
193 not_enough_memory = ENOMEM,
194 not_supported = ENOTSUP,
195 operation_canceled = ECANCELED,
196 operation_in_progress = EINPROGRESS,
197 operation_not_permitted = EPERM,
198 operation_not_supported = EOPNOTSUPP,
199 operation_would_block = EWOULDBLOCK,
200 owner_dead = EOWNERDEAD,
201 permission_denied = EACCES,
202 protocol_error = EPROTO,
203 protocol_not_supported = EPROTONOSUPPORT,
204 read_only_file_system = EROFS,
205 resource_deadlock_would_occur = EDEADLK,
206 resource_unavailable_try_again = EAGAIN,
207 result_out_of_range = ERANGE,
208 state_not_recoverable = ENOTRECOVERABLE,
209 stream_timeout = ETIME,
210 text_file_busy = ETXTBSY,
211 timed_out = ETIMEDOUT,
212 too_many_files_open_in_system = ENFILE,
213 too_many_files_open = EMFILE,
214 too_many_links = EMLINK,
215 too_many_symbolic_link_levels = ELOOP,
216 value_too_large = EOVERFLOW,
217 wrong_protocol_type = EPROTOTYPE
218 };
219};
220
221typedef errc::Enum ErrcEnum; // Portable typedef for 'errc'
222
223 // ------------------------------
224 // struct is_error_condition_enum
225 // ------------------------------
226
227/// Mark the `errc` enumeration as an error condition.
228template <>
229struct is_error_condition_enum<errc::Enum> : public bsl::true_type {
230};
231
232} // close namespace bsl
233
234#endif
235#endif
236
237// ----------------------------------------------------------------------------
238// Copyright 2019 Bloomberg Finance L.P.
239//
240// Licensed under the Apache License, Version 2.0 (the "License");
241// you may not use this file except in compliance with the License.
242// You may obtain a copy of the License at
243//
244// http://www.apache.org/licenses/LICENSE-2.0
245//
246// Unless required by applicable law or agreed to in writing, software
247// distributed under the License is distributed on an "AS IS" BASIS,
248// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
249// See the License for the specific language governing permissions and
250// limitations under the License.
251// ----------------------------- END-OF-FILE ----------------------------------
252
253/** @} */
254/** @} */
255/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlb_printmethods.h:283
std::errc ErrcEnum
Definition bslstl_errc.h:116