BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlde_charconvertstatus.h
Go to the documentation of this file.
1/// @file bdlde_charconvertstatus.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlde_charconvertstatus.h -*-C++-*-
8#ifndef INCLUDED_BDLDE_CHARCONVERTSTATUS
9#define INCLUDED_BDLDE_CHARCONVERTSTATUS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlde_charconvertstatus bdlde_charconvertstatus
15/// @brief Provide masks for interpreting status from charconvert functions.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlde
19/// @{
20/// @addtogroup bdlde_charconvertstatus
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlde_charconvertstatus-purpose"> Purpose</a>
25/// * <a href="#bdlde_charconvertstatus-classes"> Classes </a>
26/// * <a href="#bdlde_charconvertstatus-description"> Description </a>
27/// * <a href="#bdlde_charconvertstatus-enumerators"> Enumerators </a>
28/// * <a href="#bdlde_charconvertstatus-usage"> Usage </a>
29/// * <a href="#bdlde_charconvertstatus-example-1-basic-syntax"> Example 1: Basic Syntax </a>
30///
31/// # Purpose {#bdlde_charconvertstatus-purpose}
32/// Provide masks for interpreting status from charconvert functions.
33///
34/// # Classes {#bdlde_charconvertstatus-classes}
35///
36/// - bdlde::CharConvertStatus: namespace for bit-wise mask of charconvert status
37///
38/// @see bdlde_charconvertutf16, bdlde_charconvertucs2
39///
40/// # Description {#bdlde_charconvertstatus-description}
41/// This component provides a namespace for the `enum` type
42/// `bdlde::CharConvertStatus::Enum`, which enumerates the set of bit-wise masks
43/// that can be used to interpret return values from translation functions in
44/// components @ref bdlde_charconvertutf16 and @ref bdlde_charconvertucs2 .
45///
46/// ## Enumerators {#bdlde_charconvertstatus-enumerators}
47///
48///
49/// @code
50/// Name Description
51/// ------------------- ---------------------------------------------
52/// k_INVALID_INPUT_BIT Invalid code points or sequences of bytes / words
53/// were encountered in the input.
54/// k_OUT_OF_SPACE_BIT The space provided for the output was
55/// insufficient for the translation.
56/// @endcode
57///
58/// ## Usage {#bdlde_charconvertstatus-usage}
59///
60///
61/// This section illustrates intended use of this component.
62///
63/// ### Example 1: Basic Syntax {#bdlde_charconvertstatus-example-1-basic-syntax}
64///
65///
66/// The following snippets of code provide a simple illustration of
67/// `bdlde::CharConvertStatus` usage.
68///
69/// First, we create a variable `value` of type `bdlde::CharConvertStatus::Enum`
70/// and initialize it with the value 3, which is not a valid value of the
71/// `enum`.
72/// @code
73/// bdlde::CharConvertStatus::Enum value =
74/// bdlde::CharConvertStatus::k_INVALID_INPUT_BIT;
75/// @endcode
76/// Next, we store a pointer to its ASCII representation in a variable
77/// `asciiValue` of type `const char *`:
78/// @code
79/// const char *asciiValue = bdlde::CharConvertStatus::toAscii(value);
80/// assert(0 == bsl::strcmp(asciiValue, "INVALID_INPUT_BIT"));
81/// @endcode
82/// Finally, we print `value` to `bsl::cout`.
83/// @code
84/// if (veryVerbose) {
85/// bsl::cout << value << bsl::endl;
86/// }
87/// @endcode
88/// This statement produces the following output on `stdout`:
89/// @code
90/// INVALID_INPUT_BIT
91/// @endcode
92/// @}
93/** @} */
94/** @} */
95
96/** @addtogroup bdl
97 * @{
98 */
99/** @addtogroup bdlde
100 * @{
101 */
102/** @addtogroup bdlde_charconvertstatus
103 * @{
104 */
105
106#include <bdlscm_version.h>
107
108#include <bsl_iosfwd.h>
109
110
111namespace bdlde {
112
113 // ========================
114 // struct CharConvertStatus
115 // ========================
116
117/// This `struct` provides a namespace for enumerating the set of mask
118/// codes that can be used to interpret `int` return values from translation
119/// functions in `bdede`.
120///
121/// This class:
122/// * supports a complete set of *enumeration* operations
123/// - except for `bdex` serialization
124/// * is `const` *thread-safe*
125/// For terminology see @ref bsldoc_glossary .
127
128 public:
129 // TYPES
130 enum Enum {
131 k_INVALID_INPUT_BIT = 0x1, // Invalid code points or sequences of
132 // bytes or words were encountered in
133 // the input.
134 k_OUT_OF_SPACE_BIT = 0x2 // The space provided for the output
135 // was insufficient for the
136 // translation.
137 };
138
139 public:
140 // CLASS METHODS
141
142 /// Write the string representation of the specified enumeration `value`
143 /// to the specified output `stream`, and return a reference to
144 /// `stream`. Optionally specify an initial indentation `level`, whose
145 /// absolute value is incremented recursively for nested objects. If
146 /// `level` is specified, optionally specify `spacesPerLevel`, whose
147 /// absolute value indicates the number of spaces per indentation level
148 /// for this and all of its nested objects. If `level` is negative,
149 /// suppress indentation of the first line. If `spacesPerLevel` is
150 /// negative, format the entire output on one line, suppressing all but
151 /// the initial indentation (as governed by `level`). See `toAscii` for
152 /// what constitutes the string representation of a
153 /// `CharConvertStatus::Enum` value.
154 static bsl::ostream& print(bsl::ostream& stream,
156 int level = 0,
157 int spacesPerLevel = 4);
158
159 /// Return the non-modifiable string representation corresponding to the
160 /// specified enumeration `value`, if it exists, and a unique (error)
161 /// string otherwise. The string representation of `value` matches its
162 /// corresponding enumerator name with the "k_" prefix elided. For
163 /// example:
164 /// @code
165 /// bsl::cout << CharConvertStatus::toAscii(
166 /// CharConvertStatus::k_OUT_OF_SPACE_BIT);
167 /// @endcode
168 /// will print the following on standard output:
169 /// @code
170 /// OUT_OF_SPACE_BIT
171 /// @endcode
172 /// Note that specifying a `value` that does not match any of the
173 /// enumerators will result in a string representation that is distinct
174 /// from any of those corresponding to the enumerators, but is otherwise
175 /// unspecified.
176 static const char *toAscii(CharConvertStatus::Enum value);
177};
178
179// FREE OPERATORS
180
181/// Write the string representation of the specified enumeration `value` to
182/// the specified output `stream` in a single-line format, and return a
183/// reference to `stream`. See `toAscii` for what constitutes the string
184/// representation of a `bdlde::CharConvertStatus::Enum` value. Note that
185/// this method has the same behavior as
186/// @code
187/// bdlde::CharConvertStatus::print(stream, value, 0, -1);
188/// @endcode
189bsl::ostream& operator<<(bsl::ostream& stream,
191
192} // close package namespace
193
194// ============================================================================
195// INLINE FUNCTION DEFINITIONS
196// ============================================================================
197
198 // -------------------------------
199 // struct bdlde::CharConvertStatus
200 // -------------------------------
201
202// FREE OPERATORS
203inline
204bsl::ostream& bdlde::operator<<(bsl::ostream& stream,
205 CharConvertStatus::Enum value)
206{
207 return CharConvertStatus::print(stream, value, 0, -1);
208}
209
210
211
212#endif
213
214// ----------------------------------------------------------------------------
215// Copyright 2018 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)
Definition bsls_ident.h:195
Definition bdlde_base64alphabet.h:118
bsl::ostream & operator<<(bsl::ostream &stream, Base64Alphabet::Enum value)
Definition bdlde_charconvertstatus.h:126
static bsl::ostream & print(bsl::ostream &stream, CharConvertStatus::Enum value, int level=0, int spacesPerLevel=4)
Enum
Definition bdlde_charconvertstatus.h:130
@ k_INVALID_INPUT_BIT
Definition bdlde_charconvertstatus.h:131
@ k_OUT_OF_SPACE_BIT
Definition bdlde_charconvertstatus.h:134
static const char * toAscii(CharConvertStatus::Enum value)