BDE 4.39.x Production Release
Loading...
Searching...
No Matches
baltzo_errorcode.h
Go to the documentation of this file.
1/// @file baltzo_errorcode.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// baltzo_errorcode.h -*-C++-*-
8#ifndef INCLUDED_BALTZO_ERRORCODE
9#define INCLUDED_BALTZO_ERRORCODE
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup baltzo_errorcode baltzo_errorcode
15/// @brief Enumerate the set of named errors for the `baltzo` package.
16/// @addtogroup bal
17/// @{
18/// @addtogroup baltzo
19/// @{
20/// @addtogroup baltzo_errorcode
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#baltzo_errorcode-purpose"> Purpose</a>
25/// * <a href="#baltzo_errorcode-classes"> Classes </a>
26/// * <a href="#baltzo_errorcode-description"> Description </a>
27/// * <a href="#baltzo_errorcode-enumerators"> Enumerators </a>
28/// * <a href="#baltzo_errorcode-usage"> Usage </a>
29/// * <a href="#baltzo_errorcode-example-1-basic-syntax"> Example 1: Basic Syntax </a>
30///
31/// # Purpose {#baltzo_errorcode-purpose}
32/// Enumerate the set of named errors for the `baltzo` package.
33///
34/// # Classes {#baltzo_errorcode-classes}
35///
36/// - baltzo::ErrorCode: namespace for error status `enum`
37///
38/// @see baltzo_localtimedescriptor, baltzo_timezoneutil
39///
40/// # Description {#baltzo_errorcode-description}
41/// This component provides a namespace, `baltzo::ErrorCode`, for
42/// the `enum` type `baltzo::ErrorCode::Enum`, which enumerates the set of named
43/// error codes returned by functions across the `baltzo` package.
44///
45/// ## Enumerators {#baltzo_errorcode-enumerators}
46///
47///
48/// @code
49/// Name Description
50/// ---------------- --------------------------------------
51/// k_UNSUPPORTED_ID Time zone identifier is not supported.
52///
53/// k_OUT_OF_RANGE A conversion would have resulted in a value outside of
54/// the valid range
55/// @endcode
56///
57/// ## Usage {#baltzo_errorcode-usage}
58///
59///
60/// This section illustrates intended use of this component.
61///
62/// ### Example 1: Basic Syntax {#baltzo_errorcode-example-1-basic-syntax}
63///
64///
65/// The following snippets of code provide a simple illustration of
66/// `baltzo::ErrorCode` usage.
67///
68/// First, we create a variable `value` of type `baltzo::ErrorCode::Enum` and
69/// initialize it with the enumerator value
70/// `baltzo::ErrorCode::k_UNSUPPORTED_ID`:
71/// @code
72/// baltzo::ErrorCode::Enum value = baltzo::ErrorCode::k_UNSUPPORTED_ID;
73/// @endcode
74/// Now, we store a pointer to its ASCII representation in a variable
75/// `asciiValue` of type `const char *`:
76/// @code
77/// const char *asciiValue = baltzo::ErrorCode::toAscii(value);
78/// assert(0 == bsl::strcmp(asciiValue, "UNSUPPORTED_ID"));
79/// @endcode
80/// Finally, we print `value` to `bsl::cout`.
81/// @code
82/// bsl::cout << value << bsl::endl;
83/// @endcode
84/// This statement produces the following output on `stdout`:
85/// @code
86/// UNSUPPORTED_ID
87/// @endcode
88/// @}
89/** @} */
90/** @} */
91
92/** @addtogroup bal
93 * @{
94 */
95/** @addtogroup baltzo
96 * @{
97 */
98/** @addtogroup baltzo_errorcode
99 * @{
100 */
101
102#include <balscm_version.h>
103
104#include <bsl_iosfwd.h>
105
106
107namespace baltzo {
108 // ================
109 // struct ErrorCode
110 // ================
111
112/// This `struct` provides a namespace for enumerating the set of named
113/// error codes that may be returned by functions in the `baltzo` package
114/// that take a Zoneinfo string identifier as input. See `Enum` in the
115/// TYPES sub-section for details.
116///
117/// This class:
118/// * supports a complete set of *enumeration* operations
119/// - except for `bdex` serialization
120/// * is `const` *thread-safe*
121/// For terminology see @ref bsldoc_glossary .
122///
123/// See @ref baltzo_errorcode
124struct ErrorCode {
125
126 public:
127 // TYPES
128 enum Enum {
129 k_UNSUPPORTED_ID = 1, // Time zone identifier is not supported.
130
131 k_OUT_OF_RANGE = 2 // A calulation would have resulted in a
132 // value outside of the valid range.
133
134#ifndef BDE_OMIT_INTERNAL_DEPRECATED
136#endif // BDE_OMIT_INTERNAL_DEPRECATED
137
138 };
139
140 public:
141 // CLASS METHODS
142
143 /// Write the string representation of the specified enumeration `value`
144 /// to the specified output `stream`, and return a reference to
145 /// `stream`. Optionally specify an initial indentation `level`, whose
146 /// absolute value is incremented recursively for nested objects. If
147 /// `level` is specified, optionally specify `spacesPerLevel`, whose
148 /// absolute value indicates the number of spaces per indentation level
149 /// for this and all of its nested objects. If `level` is negative,
150 /// suppress indentation of the first line. If `spacesPerLevel` is
151 /// negative, format the entire output on one line, suppressing all but
152 /// the initial indentation (as governed by `level`). See `toAscii` for
153 /// what constitutes the string representation of a `ErrorCode::Enum`
154 /// value.
155 static bsl::ostream& print(bsl::ostream& stream,
156 ErrorCode::Enum value,
157 int level = 0,
158 int spacesPerLevel = 4);
159
160 /// Return the non-modifiable string representation corresponding to the
161 /// specified enumeration `value`, if it exists, and a unique (error)
162 /// string otherwise. The string representation of `value` matches its
163 /// corresponding enumerator name with the "k_" prefix elided. For
164 /// example:
165 /// @code
166 /// bsl::cout << ErrorCode::toAscii(ErrorCode::k_UNSUPPORTED_ID);
167 /// @endcode
168 /// will print the following on standard output:
169 /// @code
170 /// UNSUPPORTED_ID
171 /// @endcode
172 ///
173 /// \note Note that specifying a `value` that does not match any of the
174 /// enumerators will result in a string representation that is distinct
175 /// from any of those corresponding to the enumerators, but is otherwise
176 /// unspecified.
177 static const char *toAscii(ErrorCode::Enum value);
178};
179
180// FREE OPERATORS
181
182/// Write the string representation of the specified enumeration `value` to
183/// the specified output `stream` in a single-line format, and return a
184/// reference to `stream`. See `toAscii` for what constitutes the string representation of a `baltzo::ErrorCode::Enum` value.
185///
186/// \note Note that this
187/// method has the same behavior as
188/// @code
189/// baltzo::ErrorCode::print(stream, value, 0, -1);
190/// @endcode
191bsl::ostream& operator<<(bsl::ostream& stream, ErrorCode::Enum value);
192
193} // close package namespace
194
195// ============================================================================
196// INLINE DEFINITIONS
197// ============================================================================
198
199 // ----------------
200 // struct ErrorCode
201 // ----------------
202
203// FREE OPERATORS
204inline
205bsl::ostream& baltzo::operator<<(bsl::ostream& stream, ErrorCode::Enum value)
206{
207 return ErrorCode::print(stream, value, 0, -1);
208}
209
210
211
212#endif
213
214// ----------------------------------------------------------------------------
215// Copyright 2015 Bloomberg Finance L.P.
216//
217// Licensed under the Apache License, Version 2.0 (the "License");
218// you may not use this file except in compliance with the License.
219// You may obtain a copy of the License at
220//
221// http://www.apache.org/licenses/LICENSE-2.0
222//
223// Unless required by applicable law or agreed to in writing, software
224// distributed under the License is distributed on an "AS IS" BASIS,
225// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
226// See the License for the specific language governing permissions and
227// limitations under the License.
228// ----------------------------- END-OF-FILE ----------------------------------
229
230/** @} */
231/** @} */
232/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition baltzo_datafileloader.h:259
bsl::ostream & operator<<(bsl::ostream &stream, DstPolicy::Enum value)
Definition baltzo_errorcode.h:124
Enum
Definition baltzo_errorcode.h:128
@ k_UNSUPPORTED_ID
Definition baltzo_errorcode.h:129
@ k_OUT_OF_RANGE
Definition baltzo_errorcode.h:131
@ BAETZO_UNSUPPORTED_ID
Definition baltzo_errorcode.h:135
static bsl::ostream & print(bsl::ostream &stream, ErrorCode::Enum value, int level=0, int spacesPerLevel=4)
static const char * toAscii(ErrorCode::Enum value)