BDE 4.14.0 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 .
122struct ErrorCode {
123
124 public:
125 // TYPES
126 enum Enum {
127 k_UNSUPPORTED_ID = 1, // Time zone identifier is not supported.
128
129 k_OUT_OF_RANGE = 2 // A calulation would have resulted in a
130 // value outside of the valid range.
131
132#ifndef BDE_OMIT_INTERNAL_DEPRECATED
134#endif // BDE_OMIT_INTERNAL_DEPRECATED
135
136 };
137
138 public:
139 // CLASS METHODS
140
141 /// Write the string representation of the specified enumeration `value`
142 /// to the specified output `stream`, and return a reference to
143 /// `stream`. Optionally specify an initial indentation `level`, whose
144 /// absolute value is incremented recursively for nested objects. If
145 /// `level` is specified, optionally specify `spacesPerLevel`, whose
146 /// absolute value indicates the number of spaces per indentation level
147 /// for this and all of its nested objects. If `level` is negative,
148 /// suppress indentation of the first line. If `spacesPerLevel` is
149 /// negative, format the entire output on one line, suppressing all but
150 /// the initial indentation (as governed by `level`). See `toAscii` for
151 /// what constitutes the string representation of a `ErrorCode::Enum`
152 /// value.
153 static bsl::ostream& print(bsl::ostream& stream,
154 ErrorCode::Enum value,
155 int level = 0,
156 int spacesPerLevel = 4);
157
158 /// Return the non-modifiable string representation corresponding to the
159 /// specified enumeration `value`, if it exists, and a unique (error)
160 /// string otherwise. The string representation of `value` matches its
161 /// corresponding enumerator name with the "k_" prefix elided. For
162 /// example:
163 /// @code
164 /// bsl::cout << ErrorCode::toAscii(ErrorCode::k_UNSUPPORTED_ID);
165 /// @endcode
166 /// will print the following on standard output:
167 /// @code
168 /// UNSUPPORTED_ID
169 /// @endcode
170 /// Note that specifying a `value` that does not match any of the
171 /// enumerators will result in a string representation that is distinct
172 /// from any of those corresponding to the enumerators, but is otherwise
173 /// unspecified.
174 static const char *toAscii(ErrorCode::Enum value);
175};
176
177// FREE OPERATORS
178
179/// Write the string representation of the specified enumeration `value` to
180/// the specified output `stream` in a single-line format, and return a
181/// reference to `stream`. See `toAscii` for what constitutes the string
182/// representation of a `baltzo::ErrorCode::Enum` value. Note that this
183/// method has the same behavior as
184/// @code
185/// baltzo::ErrorCode::print(stream, value, 0, -1);
186/// @endcode
187bsl::ostream& operator<<(bsl::ostream& stream, ErrorCode::Enum value);
188
189} // close package namespace
190
191// ============================================================================
192// INLINE DEFINITIONS
193// ============================================================================
194
195 // ----------------
196 // struct ErrorCode
197 // ----------------
198
199// FREE OPERATORS
200inline
201bsl::ostream& baltzo::operator<<(bsl::ostream& stream, ErrorCode::Enum value)
202{
203 return ErrorCode::print(stream, value, 0, -1);
204}
205
206
207
208#endif
209
210// ----------------------------------------------------------------------------
211// Copyright 2015 Bloomberg Finance L.P.
212//
213// Licensed under the Apache License, Version 2.0 (the "License");
214// you may not use this file except in compliance with the License.
215// You may obtain a copy of the License at
216//
217// http://www.apache.org/licenses/LICENSE-2.0
218//
219// Unless required by applicable law or agreed to in writing, software
220// distributed under the License is distributed on an "AS IS" BASIS,
221// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
222// See the License for the specific language governing permissions and
223// limitations under the License.
224// ----------------------------- END-OF-FILE ----------------------------------
225
226/** @} */
227/** @} */
228/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition baltzo_datafileloader.h:263
bsl::ostream & operator<<(bsl::ostream &stream, DstPolicy::Enum value)
Definition baltzo_errorcode.h:122
Enum
Definition baltzo_errorcode.h:126
@ k_UNSUPPORTED_ID
Definition baltzo_errorcode.h:127
@ k_OUT_OF_RANGE
Definition baltzo_errorcode.h:129
@ BAETZO_UNSUPPORTED_ID
Definition baltzo_errorcode.h:133
static bsl::ostream & print(bsl::ostream &stream, ErrorCode::Enum value, int level=0, int spacesPerLevel=4)
static const char * toAscii(ErrorCode::Enum value)