BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlde_base64decoderoptions.h
Go to the documentation of this file.
1/// @file bdlde_base64decoderoptions.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlde_base64decoderoptions.h -*-C++-*-
8#ifndef INCLUDED_BDLDE_BASE64DECODEROPTIONS
9#define INCLUDED_BDLDE_BASE64DECODEROPTIONS
10
11#include <bsls_ident.h>
12BSLS_IDENT_RCSID(bdlde_base64decoderoptions_h,"$Id$ $CSID$")
14
15/// @defgroup bdlde_base64decoderoptions bdlde_base64decoderoptions
16/// @brief Provide value-semantic attribute class for decoder options.
17/// @addtogroup bdl
18/// @{
19/// @addtogroup bdlde
20/// @{
21/// @addtogroup bdlde_base64decoderoptions
22/// @{
23///
24/// <h1> Outline </h1>
25/// * <a href="#bdlde_base64decoderoptions-purpose"> Purpose</a>
26/// * <a href="#bdlde_base64decoderoptions-classes"> Classes </a>
27/// * <a href="#bdlde_base64decoderoptions-description"> Description </a>
28/// * <a href="#bdlde_base64decoderoptions-usage"> Usage </a>
29/// * <a href="#bdlde_base64decoderoptions-example-1-basic-usage"> Example 1: Basic Usage </a>
30/// * <a href="#bdlde_base64decoderoptions-example-2"> Example 2: </a>
31/// * <a href="#bdlde_base64decoderoptions-example-3"> Example 3: </a>
32/// * <a href="#bdlde_base64decoderoptions-example-4"> Example 4: </a>
33///
34/// # Purpose {#bdlde_base64decoderoptions-purpose}
35/// Provide value-semantic attribute class for decoder options.
36///
37/// # Classes {#bdlde_base64decoderoptions-classes}
38///
39/// - bdlde::Base64DecoderOptions: options for decoder
40///
41/// @see bdlde_base64decoderoptions, bdlde_base64decoder,
42/// bdlde_base64encoder, bdlde_base64alphabet
43///
44/// # Description {#bdlde_base64decoderoptions-description}
45/// This component provides a value-semantic attribute class for
46/// specifying options for `bdlde::Base64Decoder`.
47///
48/// This `class` supports default-generated copy construction and copy
49/// assignment, but the constructor is private. To create an object one must
50/// call one of the class methods, which will return a newly-constructed object
51/// by value. Specialized class methods are provided to create objects
52/// configured for the `mime`, `urlSafe`, and `standard` configurations.
53///
54/// Other configurations may be obtained by specifying arguments to the `custom`
55/// class method, or by calling the setters after the object is created.
56///
57/// ## Usage {#bdlde_base64decoderoptions-usage}
58///
59///
60/// This section illustrates intended use of this component.
61///
62/// ### Example 1: Basic Usage {#bdlde_base64decoderoptions-example-1-basic-usage}
63///
64///
65/// Suppose we want a `Base64DecoderOptions` object configured for MIME
66/// encoding, meaning `alphabet == e_BASIC`, `isPadded == true`, and
67/// `ignoreMode = e_IGNORE_WHITESPACE`.
68///
69/// First, we call the `mime` class method, and we're done.
70/// @code
71/// const bdlde::Base64DecoderOptions& mimeOptions =
72/// bdlde::Base64DecoderOptions::mime();
73/// @endcode
74/// Then, we check the attributes:
75/// @code
76/// assert(mimeOptions.ignoreMode() ==
77/// bdlde::Base64IgnoreMode::e_IGNORE_WHITESPACE);
78/// assert(mimeOptions.alphabet() == bdlde::Base64Alphabet::e_BASIC);
79/// assert(mimeOptions.isPadded() == true);
80/// @endcode
81/// Now, we stream the object:
82/// @code
83/// mimeOptions.print(cout);
84/// @endcode
85/// Finally, we observe the output:
86/// @code
87/// [
88/// ignoreMode = IGNORE_WHITESPACE
89/// alphabet = BASIC
90/// isPadded = true
91/// ]
92/// @endcode
93///
94/// ### Example 2: {#bdlde_base64decoderoptions-example-2}
95///
96///
97/// Suppose we want a `Base64DecoderOptions` object configured for translating
98/// URL's. That would mean `alphabet == e_URL`, `isPadded == false`, and
99/// ignoring neither unrecognized characters nor whitespace.
100///
101/// First, the class method `urlSafe` returns an object configured exactly that
102/// way, so we simply call it:
103/// @code
104/// const bdlde::Base64DecoderOptions& urlOptions =
105/// bdlde::Base64DecoderOptions::urlSafe();
106/// @endcode
107/// Then, we check the attributes:
108/// @code
109/// assert(urlOptions.ignoreMode() == bdlde::Base64IgnoreMode::e_IGNORE_NONE);
110/// assert(urlOptions.alphabet() == bdlde::Base64Alphabet::e_URL);
111/// assert(urlOptions.isPadded() == false);
112/// @endcode
113/// Now, we stream the object:
114/// @code
115/// urlOptions.print(cout);
116/// @endcode
117/// Finally, we observe the output:
118/// @code
119/// [
120/// ignoreMode = IGNORE_NONE
121/// alphabet = URL
122/// isPadded = false
123/// ]
124/// @endcode
125///
126/// ### Example 3: {#bdlde_base64decoderoptions-example-3}
127///
128///
129/// Suppose we want an options object configured for standard Base64:
130///
131/// First, we can simply call the `standard` class method:
132/// @code
133/// const bdlde::Base64DecoderOptions& standardOptions =
134/// bdlde::Base64DecoderOptions::standard();
135/// @endcode
136/// Then, we check the attributes:
137/// @code
138/// assert(standardOptions.ignoreMode() ==
139/// bdlde::Base64IgnoreMode::e_IGNORE_NONE);
140/// assert(standardOptions.alphabet() ==
141/// bdlde::Base64Alphabet::e_BASIC);
142/// assert(standardOptions.isPadded() == true);
143/// @endcode
144/// Now, we stream the object:
145/// @code
146/// standardOptions.print(cout);
147/// @endcode
148/// Finally, we observe the output:
149/// @code
150/// [
151/// ignoreMode = IGNORE_NONE
152/// alphabet = BASIC
153/// isPadded = true
154/// ]
155/// @endcode
156///
157/// ### Example 4: {#bdlde_base64decoderoptions-example-4}
158///
159///
160/// Suppose we want a really strangely configured options object with
161/// `alphabet == e_URL`, and padding, and ignoring neither unrecognized
162/// characters nor whitespace.
163///
164/// First, we can simply call the `custom` class method. The `padded` and
165/// `unrecognizedIsError == true` arguments are last, and they default to
166/// `true`, so we don't have to pass that.
167/// @code
168/// const bdlde::Base64DecoderOptions& customOptions =
169/// bdlde::Base64DecoderOptions::custom(
170/// bdlde::Base64IgnoreMode::e_IGNORE_NONE,
171/// bdlde::Base64Alphabet::e_URL,
172/// true);
173/// @endcode
174/// Then, we check the attributes:
175/// @code
176/// assert(customOptions.ignoreMode() ==
177/// bdlde::Base64IgnoreMode::e_IGNORE_NONE);
178/// assert(customOptions.alphabet() == bdlde::Base64Alphabet::e_URL);
179/// assert(customOptions.isPadded() == true);
180/// @endcode
181/// Now, we stream the object:
182/// @code
183/// cout << customOptions << endl;
184/// @endcode
185/// Finally, we observe the output:
186/// @code
187/// [ ignoreMode = IGNORE_NONE alphabet = URL isPadded = true ]
188/// @endcode
189/// @}
190/** @} */
191/** @} */
192
193/** @addtogroup bdl
194 * @{
195 */
196/** @addtogroup bdlde
197 * @{
198 */
199/** @addtogroup bdlde_base64decoderoptions
200 * @{
201 */
202
203#include <bdlde_base64alphabet.h>
205
207
208#include <bsls_assert.h>
209
210#include <bsl_iosfwd.h>
211
212
213namespace bdlde {
214
215 // ==========================
216 // class Base64DecoderOptions
217 // ==========================
218
219/// This `class` stores the configuration of a `Base64Decoder`.
220///
221/// See @ref bdlde_base64decoderoptions
223
225
226 // DATA
227 IgnoreMode::Enum d_ignoreMode; // what types of chars, if any, are
228 // ignored
229 Base64Alphabet::Enum d_alphabet; // alphabet -- basic or url
230 bool d_isPadded; // is input padded with '='?
231
232 private:
233 // PRIVATE CREATORS
234
235 /// Create a `Base64DecoderOptions` object having the specified `alphabet`,
236 /// `padded`, and `ignoreMode` attribute values. The behavior is undefined
237 /// unless `alphabet` is a defined value of `Base64Alphabet::Enum` and
238 /// `ignoreMode` is a defined value of `Base64IgnoreMode::Enum`.
241 bool padded);
242
243 public:
244 // CLASS METHODS
245
246 /// Return a `Base64DecoderOptions` object having the specified `alphabet`,
247 /// `padded`, and `ignoreMode` attribute values. The behavior is unless
248 /// `ignoreMode` is a defined value of `IgnoreMode`, and `alphabet` is a
249 /// defined value of `Base64Alphabet::Enum`.
250 static
254 bool padded);
255
256 /// Return a `Base64DecoderOptions` object having the attributes
257 /// `alphabet == Base64Alphabet::e_BASIC`, `isPadded == true`, and the
258 /// specified `ignoreMode`. If `ignoreMode` is not specified, it
259 /// defaults to `e_IGNORE_WHITESPACE`. This conforms to RFC 2045.
260 static
263
264 /// Return a `Base64DecoderOptions` object having the specified
265 /// `ignoreMode` and `padded`, and the attribute
266 /// `alphabet == Base64Alphabet::e_BASIC`. If `padded` is not
267 /// specified, it defaults to `true`. If `ignoreMode` is not specified,
268 /// it defaults to `e_IGNORE_NOTHING`. This conforms to RFC 4648
269 /// section 4.
270 static
273 bool padded = true);
274
275 /// Return a `Base64DecoderOptions` object having the attributes
276 /// `alphabet == Base64Alphabet::e_URL`, `isPadded == false` and the
277 /// specified `ignoreMode`. If `ignoreMode` is not specified, it
278 /// defaults to `e_IGNORE_NOTHING`. This conforms to RFC 4648 section
279 /// 5.
280 static
283 bool padded = false);
284
285 // CREATORS
286
287 /// Default copy constructor.
289
290 /// Destroy this object.
292
293 // MANIPULATORS
294
295 /// Default operator=().
297
298 /// Set the `alphabet` attribute to the specified `value`. The behavior
299 /// is undefined unless `value` is either `e_BASIC` or `e_UTL`.
301
302 /// Set the `ignoreMode` attribute to the specified `value`. The
303 /// behavior is undefined unless `value` is valid value of the
304 /// `IgnoreMode` enum.
306
307 /// Set the `isPadded` attribute to the specified `value`.
308 void setIsPadded(bool value);
309
310 // ACCESSORS
311
312 /// Format this object to the specified output `stream` at the optionally
313 /// specified indentation `level` and return a reference to the modifiable
314 /// `stream`. If `level` is specified, optionally specify
315 /// `spacesPerLevel`, the number of spaces per indentation level for this
316 /// and all of its nested objects. Each line is indented by the absolute
317 /// value of `level * spacesPerLevel`. If `level` is negative, suppress
318 /// indentation of the first line. If `spacesPerLevel` is negative,
319 /// suppress line breaks and format the entire output on one line. If
320 /// `stream` is initially invalid, this operation has no effect. Note that
321 /// a trailing newline is provided in multiline mode only.
322 bsl::ostream& print(bsl::ostream& stream,
323 int level = 0,
324 int spacesPerLevel = 4) const;
325
326 /// Return the value of the `alphabet` attribute.
328
329 /// Return the value of the `ignoreMode` attribute.
331
332 /// Return the value of the `isPadded` attribute.
333 bool isPadded() const;
334};
335
336// FREE OPERATORS
337
338/// Return `true` if the specified `lhs` and `rhs` attribute objects have the
339/// same value, and `false` otherwise. Two attribute objects have the same
340/// value if each respective attribute has the same value.
341bool operator==(const Base64DecoderOptions& lhs,
342 const Base64DecoderOptions& rhs);
343
344/// Return `true` if the specified `lhs` and `rhs` attribute objects do not
345/// have the same value, and `false` otherwise. Two attribute objects do not
346/// have the same value if one or more respective attributes differ in values.
347bool operator!=(const Base64DecoderOptions& lhs,
348 const Base64DecoderOptions& rhs);
349
350/// Format the specified `rhs` to the specified output `stream` and return a
351/// reference to the modifiable `stream`.
352bsl::ostream& operator<<(bsl::ostream& stream,
353 const Base64DecoderOptions& rhs);
354
355} // close package namespace
356
357
358// TRAITS
359namespace bsl {
360
361template <>
364
365
366} // close namespace bsl
367
368// ============================================================================
369// INLINE FUNCTION DEFINITIONS
370// ============================================================================
371
372
373namespace bdlde {
374
375 // --------------------------
376 // class Base64DecoderOptions
377 // --------------------------
378
379// PRIVATE CREATORS
380inline
381Base64DecoderOptions::Base64DecoderOptions(IgnoreMode::Enum ignoreMode,
382 Base64Alphabet::Enum alphabet,
383 bool padded)
384: d_ignoreMode(ignoreMode)
385, d_alphabet(alphabet)
386, d_isPadded(padded)
387{
388 BSLS_ASSERT(Base64IgnoreMode::e_IGNORE_NONE == ignoreMode ||
389 Base64IgnoreMode::e_IGNORE_WHITESPACE == ignoreMode ||
390 Base64IgnoreMode::e_IGNORE_UNRECOGNIZED == ignoreMode);
391 BSLS_ASSERT(Base64Alphabet::e_BASIC == alphabet ||
392 Base64Alphabet::e_URL == alphabet);
393}
394
395// CLASS METHODS
396inline
397Base64DecoderOptions Base64DecoderOptions::custom(
398 IgnoreMode::Enum ignoreMode,
399 Base64Alphabet::Enum alphabet,
400 bool padded)
401{
402 return Base64DecoderOptions(ignoreMode,
403 alphabet,
404 padded);
405}
406
407inline
408Base64DecoderOptions Base64DecoderOptions::mime(IgnoreMode::Enum ignoreMode)
409{
410 return Base64DecoderOptions(ignoreMode,
411 Base64Alphabet::e_BASIC,
412 true);
413}
414
415inline
416Base64DecoderOptions Base64DecoderOptions::standard(
417 IgnoreMode::Enum ignoreMode,
418 bool padded)
419{
420 return Base64DecoderOptions(ignoreMode,
421 Base64Alphabet::e_BASIC,
422 padded);
423}
424
425inline
426Base64DecoderOptions Base64DecoderOptions::urlSafe(IgnoreMode::Enum ignoreMode,
427 bool padded)
428{
429 return Base64DecoderOptions(ignoreMode,
430 Base64Alphabet::e_URL,
431 padded);
432}
433
434// MANIPULATORS
435inline
436void Base64DecoderOptions::setAlphabet(Base64Alphabet::Enum value)
437{
438 BSLS_ASSERT(Base64Alphabet::e_BASIC == value ||
439 Base64Alphabet::e_URL == value);
440
441 d_alphabet = value;
442}
443
444inline
445void Base64DecoderOptions::setIsPadded(bool value)
446{
447 d_isPadded = value;
448}
449
450inline
451void Base64DecoderOptions::setIgnoreMode(IgnoreMode::Enum value)
452{
453 BSLS_ASSERT(static_cast<unsigned>(value) <= 2);
454
455 d_ignoreMode = value;
456}
457
458// ACCESSORS
459inline
460Base64Alphabet::Enum Base64DecoderOptions::alphabet() const
461{
462 return d_alphabet;
463}
464
465inline
466Base64IgnoreMode::Enum Base64DecoderOptions::ignoreMode() const
467{
468 return d_ignoreMode;
469}
470
471inline
472bool Base64DecoderOptions::isPadded() const
473{
474 return d_isPadded;
475}
476
477} // close package namespace
478
479
480#endif
481
482// ----------------------------------------------------------------------------
483// Copyright 2022 Bloomberg Finance L.P.
484//
485// Licensed under the Apache License, Version 2.0 (the "License");
486// you may not use this file except in compliance with the License.
487// You may obtain a copy of the License at
488//
489// http://www.apache.org/licenses/LICENSE-2.0
490//
491// Unless required by applicable law or agreed to in writing, software
492// distributed under the License is distributed on an "AS IS" BASIS,
493// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
494// See the License for the specific language governing permissions and
495// limitations under the License.
496// ----------------------------- END-OF-FILE ----------------------------------
497
498/** @} */
499/** @} */
500/** @} */
Definition bdlde_base64decoderoptions.h:222
Base64DecoderOptions & operator=(const Base64DecoderOptions &)=default
Default operator=().
Base64Alphabet::Enum alphabet() const
Return the value of the alphabet attribute.
Definition bdlde_base64decoderoptions.h:460
static Base64DecoderOptions urlSafe(IgnoreMode::Enum ignoreMode=IgnoreMode::e_IGNORE_NONE, bool padded=false)
Definition bdlde_base64decoderoptions.h:426
void setIsPadded(bool value)
Set the isPadded attribute to the specified value.
Definition bdlde_base64decoderoptions.h:445
void setAlphabet(Base64Alphabet::Enum value)
Definition bdlde_base64decoderoptions.h:436
void setIgnoreMode(IgnoreMode::Enum value)
Definition bdlde_base64decoderoptions.h:451
static Base64DecoderOptions custom(IgnoreMode::Enum ignoreMode, Base64Alphabet::Enum alphabet, bool padded)
Definition bdlde_base64decoderoptions.h:397
static Base64DecoderOptions mime(IgnoreMode::Enum ignoreMode=IgnoreMode::e_IGNORE_WHITESPACE)
Definition bdlde_base64decoderoptions.h:408
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
Base64DecoderOptions(const Base64DecoderOptions &)=default
Default copy constructor.
IgnoreMode::Enum ignoreMode() const
Return the value of the ignoreMode attribute.
Definition bdlde_base64decoderoptions.h:466
~Base64DecoderOptions()=default
Destroy this object.
static Base64DecoderOptions standard(IgnoreMode::Enum ignoreMode=IgnoreMode::e_IGNORE_NONE, bool padded=true)
Definition bdlde_base64decoderoptions.h:416
bool isPadded() const
Return the value of the isPadded attribute.
Definition bdlde_base64decoderoptions.h:472
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT_RCSID(tag, str)
Definition bsls_ident.h:260
#define BSLS_IDENT_PRAGMA_ONCE
Definition bsls_ident.h:310
Definition bdlde_base64alphabet.h:118
bsl::ostream & operator<<(bsl::ostream &stream, Base64Alphabet::Enum value)
Definition bdlb_printmethods.h:283
Enum
Definition bdlde_base64alphabet.h:135
Definition bdlde_base64ignoremode.h:133
Enum
Definition bdlde_base64ignoremode.h:136
@ e_IGNORE_WHITESPACE
Definition bdlde_base64ignoremode.h:139
@ e_IGNORE_NONE
Definition bdlde_base64ignoremode.h:136
Definition bslmf_istriviallycopyable.h:329