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