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