BDE 4.14.0 Production release
Loading...
Searching...
No Matches
baljsn_encoderoptions.h
Go to the documentation of this file.
1/// @file baljsn_encoderoptions.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// baljsn_encoderoptions.h -*-C++-*-
8#ifndef INCLUDED_BALJSN_ENCODEROPTIONS
9#define INCLUDED_BALJSN_ENCODEROPTIONS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup baljsn_encoderoptions baljsn_encoderoptions
15/// @brief Provide an attribute class for specifying JSON encoding options.
16/// @addtogroup bal
17/// @{
18/// @addtogroup baljsn
19/// @{
20/// @addtogroup baljsn_encoderoptions
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#baljsn_encoderoptions-purpose"> Purpose</a>
25/// * <a href="#baljsn_encoderoptions-classes"> Classes </a>
26/// * <a href="#baljsn_encoderoptions-description"> Description </a>
27/// * <a href="#baljsn_encoderoptions-attributes"> Attributes </a>
28/// * <a href="#baljsn_encoderoptions-implementation-note"> Implementation Note </a>
29/// * <a href="#baljsn_encoderoptions-usage"> Usage </a>
30/// * <a href="#baljsn_encoderoptions-example-1-creating-and-populating-an-options-object"> Example 1: Creating and Populating an Options Object </a>
31///
32/// # Purpose {#baljsn_encoderoptions-purpose}
33/// Provide an attribute class for specifying JSON encoding options.
34///
35/// # Classes {#baljsn_encoderoptions-classes}
36///
37/// - baljsn::EncoderOptions: options for encoding objects in the JSON format
38///
39/// @see baljsn_encoder, baljsn_decoderoptions
40///
41/// # Description {#baljsn_encoderoptions-description}
42/// This component provides a single, simply constrained
43/// (value-semantic) attribute class, `baljsn::EncoderOptions`, that is used to
44/// specify options for encoding objects in the JSON format.
45///
46/// ## Attributes {#baljsn_encoderoptions-attributes}
47///
48///
49/// @code
50/// Name Type Default Simple Constraints
51/// ------------------ ----------- ------- ------------------
52/// encodingStyle EncodingStyle e_COMPACT none
53/// initialIndentLevel int 0 >= 0
54/// spacesPerLevel int 0 >= 0
55/// encodeEmptyArrays bool false none
56/// encodeNullElements bool false none
57/// encodeInfAndNaNAsStrings
58/// bool false none
59/// encodeQuotedDecimal64
60/// bool true none
61/// datetimeFractionalSecondPrecision
62/// int 3 >= 0 and <= 6
63/// maxFloatPrecision int 0 >= 1 and <= 9 or 0
64/// maxDoublePrecision int 0 >= 1 and <= 17 or 0
65/// @endcode
66/// * `encodingStyle`: encoding style used to encode the JSON data.
67/// * `initialIndentLevel`: Initial indent level for the topmost element.
68/// * `spacesPerLevel`: spaces per additional indent level.
69/// * `encodeEmptyArrays`: option specifying if empty arrays should be encoded
70/// (empty arrays occurring as selections of choices are always encoded).
71/// * `encodeNullElements`: option specifying if null elements should be
72/// encoded.
73/// * `encodeInfAndNaNAsStrings`: JSON does not provide a way to encode these
74/// values as they are not numbers. This option
75/// provides a way to encode these values.
76/// Although the resulting output is a valid
77/// JSON document, decoders expecting floating
78/// point numbers to be encoded only as numbers
79/// will fail to decode. Users of this option
80/// must therefore exercise caution and ensure
81/// that if this option is used then the parser
82/// decoding the generated JSON can handle
83/// doubles as strings.
84/// * `encodeQuotedDecimal64`: option specifying a way to encode `Decimal64`
85/// values. If the `encodeQuotedDecimal64`
86/// attribute value is `true` (the default), the
87/// `Decimal64` values will be encoded quoted,
88/// and otherwise they will be encoded as numbers.
89/// Encoding a Decimal64 as a JSON number will
90/// frequently result in it being later decoded as
91/// a binary floating point number, and in the
92/// process losing digits of precision that were
93/// the point of using the Decimal64 type in the
94/// first place. Care should be taken when setting
95/// this option to `false` (though it may be useful
96/// when communicating with endpoints that are
97/// known to correctly handle high precision JSON
98/// numbers).
99/// * `datetimeFractionalSecondPrecision`: option specifying the number of
100/// decimal places used for seconds when
101/// encoding `Datetime` and
102/// `DatetimeTz`.
103/// * `maxFloatPrecision`: [**DEPRECATED**] option specifying the maximum number
104/// of decimal places used to encode each `float` value.
105/// When 0 (the default value) the encoder will use the
106/// minimum that is necessary to restore the binary
107/// value into a `float`. We recommend against setting
108/// this option: the option was provided prior to the
109/// current default behavior (of choosing the shortest
110/// presentation that can be restored to the original
111/// value) being available.
112/// * `maxDoublePrecision`: [**DEPRECATED**] option specifying the maximum number
113/// of decimal places used to encode each `double`
114/// value. When 0 (the default value) the encoder will
115/// use the minimum that is necessary to restore the
116/// binary value into a `double`. We recommend against
117/// setting this option: the option was provided prior
118/// to the current default behavior (of choosing the
119/// shortest presentation that can be restored to the
120/// original value) being available.
121///
122/// ### Implementation Note {#baljsn_encoderoptions-implementation-note}
123///
124///
125/// This file was generated from a script and was subsequently modified to add
126/// documentation and to make other changes. The steps to generate and update
127/// this file can be found in the `doc/generating_codec_options.txt` file.
128///
129/// ## Usage {#baljsn_encoderoptions-usage}
130///
131///
132/// This section illustrates intended use of this component.
133///
134/// ### Example 1: Creating and Populating an Options Object {#baljsn_encoderoptions-example-1-creating-and-populating-an-options-object}
135///
136///
137/// This component is designed to be used at a higher level to set the options
138/// for encoding objects in the JSON format. This example shows how to create
139/// and populate an options object.
140///
141/// First, we default-construct a `baljsn::EncoderOptions` object:
142/// @code
143/// const int INITIAL_INDENT_LEVEL = 1;
144/// const int SPACES_PER_LEVEL = 4;
145/// const bool ENCODE_EMPTY_ARRAYS = true;
146/// const bool ENCODE_NULL_ELEMENTS = true;
147/// const bool ENCODE_INF_NAN_AS_STRINGS = true;
148/// const int DATETIME_PRECISION = 6;
149/// const int FLOAT_PRECISION = 3;
150/// const int DOUBLE_PRECISION = 9;
151/// const bool ENCODE_QUOTED_DECIMAL64 = false;
152///
153/// baljsn::EncoderOptions options;
154/// assert(0 == options.initialIndentLevel());
155/// assert(0 == options.spacesPerLevel());
156/// assert(baljsn::EncoderOptions::e_COMPACT == options.encodingStyle());
157/// assert(false == options.encodeEmptyArrays());
158/// assert(false == options.encodeNullElements());
159/// assert(false == options.encodeInfAndNaNAsStrings());
160/// assert(3 == options.datetimeFractionalSecondPrecision());
161/// assert(0 == options.maxFloatPrecision());
162/// assert(0 == options.maxDoublePrecision());
163/// assert(true == options.encodeQuotedDecimal64());
164/// @endcode
165/// Next, we populate that object to encode in a prett format using a
166/// pre-defined initial indent level and spaces per level:
167/// @code
168/// options.setEncodingStyle(baljsn::EncodingStyle::e_PRETTY);
169/// assert(baljsn::EncoderOptions::e_PRETTY == options.encodingStyle());
170///
171/// options.setInitialIndentLevel(INITIAL_INDENT_LEVEL);
172/// assert(INITIAL_INDENT_LEVEL == options.initialIndentLevel());
173///
174/// options.setSpacesPerLevel(SPACES_PER_LEVEL);
175/// assert(SPACES_PER_LEVEL == options.spacesPerLevel());
176///
177/// options.setEncodeEmptyArrays(ENCODE_EMPTY_ARRAYS);
178/// assert(ENCODE_EMPTY_ARRAYS == options.encodeEmptyArrays());
179///
180/// options.setEncodeNullElements(ENCODE_NULL_ELEMENTS);
181/// assert(ENCODE_NULL_ELEMENTS == options.encodeNullElements());
182///
183/// options.setEncodeInfAndNaNAsStrings(ENCODE_INF_NAN_AS_STRINGS);
184/// assert(ENCODE_INF_NAN_AS_STRINGS == options.encodeInfAndNaNAsStrings());
185///
186/// options.setDatetimeFractionalSecondPrecision(DATETIME_PRECISION);
187/// assert(DATETIME_PRECISION == options.datetimeFractionalSecondPrecision());
188///
189/// options.setMaxFloatPrecision(FLOAT_PRECISION);
190/// assert(FLOAT_PRECISION == options.maxFloatPrecision());
191///
192/// options.setMaxDoublePrecision(DOUBLE_PRECISION);
193/// assert(DOUBLE_PRECISION == options.maxDoublePrecision());
194///
195/// options.setEncodeQuotedDecimal64(ENCODE_QUOTED_DECIMAL64);
196/// ASSERT(ENCODE_QUOTED_DECIMAL64 == options.encodeQuotedDecimal64());
197/// @endcode
198/// @}
199/** @} */
200/** @} */
201
202/** @addtogroup bal
203 * @{
204 */
205/** @addtogroup baljsn
206 * @{
207 */
208/** @addtogroup baljsn_encoderoptions
209 * @{
210 */
211
212#include <balscm_version.h>
213
214#include <bslalg_typetraits.h>
215
216#include <bdlat_attributeinfo.h>
217#include <bdlat_selectioninfo.h>
218#include <bdlat_typetraits.h>
219
220#include <bsls_assert.h>
221#include <bsls_objectbuffer.h>
222#include <bsls_review.h>
223
224#include <baljsn_encodingstyle.h>
225
226#include <bsl_limits.h>
227#include <bsl_iosfwd.h>
228
229
230
231namespace baljsn { class EncoderOptions; }
232namespace baljsn {
233
234 // ====================
235 // class EncoderOptions
236 // ====================
237
238/// Options for performing JSON encoding. `EncodingStyle` is either
239/// `COMPACT` or `PRETTY`. If `EncodingStyle` is `COMPACT`, no whitespace
240/// will be added between elements. If encoding style is `PRETTY`, then the
241/// `InitialIndentLevel` and `SpacesPerLevel` parameters are used to specify
242/// the formatting of the output. Note that `InitialIndentLevel` and
243/// `SpacesPerLevel` are ignored when `EncodingStyle` is `COMPACT` (this is
244/// the default). The `EncodeEmptyArrays` and `EncodeNullElements` encode
245/// empty array and null elements respectively. By default empty array and
246/// null elements are not encoded. The `EncodeInfAndNaNAsStrings` attribute
247/// provides users the option to encode `Infinity` and `NaN` floating point
248/// values as strings. These values do not have a valid JSON representation
249/// and by default such value will result in an encoding error. The
250/// `DatetimeFractionalSecondPrecision` specifies the precision of
251/// milliseconds printed with date time values. By default a precision of
252/// `3` decimal places is used. The `MaxFloatPrecision` and
253/// `MaxDoublePrecision` attributes allow specifying the maximum precision
254/// for `float` and `double` values. When not specified, or 0 is specified,
255/// the precision is determined automatically to use enough digits to ensure
256/// restoring the original binary floating point value by a reader. We
257/// recommend against setting these options: they were provided prior to the
258/// current default behavior (of choosing the shortest presentation that can
259/// be restored to the original value) being available.
260///
261/// See @ref baljsn_encoderoptions
263
264 // INSTANCE DATA
265
266 // initial indentation level for the topmost element
267 int d_initialIndentLevel;
268
269 // spaces per additional level of indentation
270 int d_spacesPerLevel;
271
272 // option specifying the number of decimal places used for milliseconds
273 // when encoding `Datetime` and `DatetimeTz` values
274 int d_datetimeFractionalSecondPrecision;
275
276 // option specifying the maximum number of decimal places used to
277 // encode each `float` value
278 int d_maxFloatPrecision;
279
280 // option specifying the maximum number of decimal places used to
281 // encode each `double` value
282 int d_maxDoublePrecision;
283
284 // encoding style used to encode values
285 baljsn::EncodingStyle::Value d_encodingStyle;
286
287 // option specifying if empty arrays should be encoded (empty arrays
288 // occurring as selections of choices are always encoded)
289 bool d_encodeEmptyArrays;
290
291 // option specifying if null elements should be encoded
292 bool d_encodeNullElements;
293
294 // option specifying a way to encode `Infinity` and `NaN` floating
295 // point values. JSON does not provide a way to encode these values as
296 // they are not numbers. Although the resulting output is a valid JSON
297 // document, decoders expecting floating point numbers to be encoded
298 // only as numbers will fail to decode. Users of this option must
299 // therefore exercise caution and ensure that if this option is used
300 // then the parser decoding the generated JSON can handle doubles as
301 // strings.
302 bool d_encodeInfAndNaNAsStrings;
303
304 // option specifying a way to encode `Decimal64` values. If the option
305 // value is `true` then the `Decimal64` value is encoded quoted
306 // { "dec": "1.2e-5" }, and unquoted { "dec": 1.2e-5 } otherwise.
307 bool d_encodeQuotedDecimal64;
308 public:
309 // TYPES
310
311 // This `enum` provides enumerators to specify the encoding styles. This
312 // `enum` is replicated in this `class` for backwards-compatibility with
313 // `baejsn`. Users should use `baljsn::EncodingStyle` directly.
317#ifndef BDE_OMIT_INTERNAL_DEPRECATED
320#endif // BDE_OMIT_INTERNAL_DEPRECATED
321 };
322
323 enum {
334 };
335
336 enum {
337 NUM_ATTRIBUTES = 10
338 };
339
340 enum {
351 };
352
353 // CONSTANTS
354 static const char CLASS_NAME[];
355
357
359
361
363
365
367
369
371
373
375
377
378 public:
379 // CLASS METHODS
380
381 /// Return attribute information for the attribute indicated by the
382 /// specified `id` if the attribute exists, and 0 otherwise.
384
385 /// Return attribute information for the attribute indicated by the
386 /// specified `name` of the specified `nameLength` if the attribute
387 /// exists, and 0 otherwise.
389 const char *name,
390 int nameLength);
391
392 // CREATORS
393
394 /// Create an object of type `EncoderOptions` having the default value.
396
397 /// Create an object of type `EncoderOptions` having the value of the
398 /// specified `original` object.
400
401 /// Destroy this object.
403
404 // MANIPULATORS
405
406 /// Assign to this object the value of the specified `rhs` object.
408
409 /// Reset this object to the default value (i.e., its value upon
410 /// default construction).
411 void reset();
412
413 /// Invoke the specified `manipulator` sequentially on the address of
414 /// each (modifiable) attribute of this object, supplying `manipulator`
415 /// with the corresponding attribute information structure until such
416 /// invocation returns a non-zero value. Return the value from the
417 /// last invocation of `manipulator` (i.e., the invocation that
418 /// terminated the sequence).
419 template<class MANIPULATOR>
420 int manipulateAttributes(MANIPULATOR& manipulator);
421
422 /// Invoke the specified `manipulator` on the address of
423 /// the (modifiable) attribute indicated by the specified `id`,
424 /// supplying `manipulator` with the corresponding attribute
425 /// information structure. Return the value returned from the
426 /// invocation of `manipulator` if `id` identifies an attribute of this
427 /// class, and -1 otherwise.
428 template<class MANIPULATOR>
429 int manipulateAttribute(MANIPULATOR& manipulator, int id);
430
431 /// Invoke the specified `manipulator` on the address of the (modifiable)
432 /// attribute indicated by the specified `name` of the specified
433 /// `nameLength`, supplying `manipulator` with the corresponding attribute
434 /// information structure. Return the value returned from the invocation
435 /// of `manipulator` if `name` identifies an attribute of this class, and
436 /// -1 otherwise.
437 template<class MANIPULATOR>
438 int manipulateAttribute(MANIPULATOR& manipulator,
439 const char *name,
440 int nameLength);
441
442 /// Set the "InitialIndentLevel" attribute of this object to the specified
443 /// `value`.
444 void setInitialIndentLevel(int value);
445
446 /// Set the "SpacesPerLevel" attribute of this object to the specified
447 /// `value`.
448 void setSpacesPerLevel(int value);
449
451 /// Set the "EncodingStyle" attribute of this object to the specified
452 /// `value`.
454
455 /// Set the "EncodeEmptyArrays" attribute of this object to the specified
456 /// `value`.
457 void setEncodeEmptyArrays(bool value);
458
459 /// Set the "EncodeNullElements" attribute of this object to the specified
460 /// `value`.
461 void setEncodeNullElements(bool value);
462
463 /// Set the "EncodeInfAndNaNAsStrings" attribute of this object to the
464 /// specified `value`.
465 void setEncodeInfAndNaNAsStrings(bool value);
466
467 /// Set the "DatetimeFractionalSecondPrecision" attribute of this object
468 /// to the specified `value`.
470
471 /// Set the "MaxFloatPrecision" attribute of this object to the
472 /// specified `value`.
473 void setMaxFloatPrecision(int value);
474
475 /// Set the "MaxDoublePrecision" attribute of this object to the
476 /// specified `value`.
477 void setMaxDoublePrecision(int value);
478
479 /// Set the "EncodeQuotedDecimal64" attribute of this object to the
480 /// specified `value`.
481 void setEncodeQuotedDecimal64(bool value);
482
483 // ACCESSORS
484
485 /// Format this object to the specified output `stream` at the
486 /// optionally specified indentation `level` and return a reference to
487 /// the modifiable `stream`. If `level` is specified, optionally
488 /// specify `spacesPerLevel`, the number of spaces per indentation level
489 /// for this and all of its nested objects. Each line is indented by
490 /// the absolute value of `level * spacesPerLevel`. If `level` is
491 /// negative, suppress indentation of the first line. If
492 /// `spacesPerLevel` is negative, suppress line breaks and format the
493 /// entire output on one line. If `stream` is initially invalid, this
494 /// operation has no effect. Note that a trailing newline is provided
495 /// in multiline mode only.
496 bsl::ostream& print(bsl::ostream& stream,
497 int level = 0,
498 int spacesPerLevel = 4) const;
499
500 /// Invoke the specified `accessor` sequentially on each
501 /// (non-modifiable) attribute of this object, supplying `accessor`
502 /// with the corresponding attribute information structure until such
503 /// invocation returns a non-zero value. Return the value from the
504 /// last invocation of `accessor` (i.e., the invocation that terminated
505 /// the sequence).
506 template<class ACCESSOR>
507 int accessAttributes(ACCESSOR& accessor) const;
508
509 /// Invoke the specified `accessor` on the (non-modifiable) attribute
510 /// of this object indicated by the specified `id`, supplying `accessor`
511 /// with the corresponding attribute information structure. Return the
512 /// value returned from the invocation of `accessor` if `id` identifies
513 /// an attribute of this class, and -1 otherwise.
514 template<class ACCESSOR>
515 int accessAttribute(ACCESSOR& accessor, int id) const;
516
517 /// Invoke the specified `accessor` on the (non-modifiable) attribute
518 /// of this object indicated by the specified `name` of the specified
519 /// `nameLength`, supplying `accessor` with the corresponding attribute
520 /// information structure. Return the value returned from the
521 /// invocation of `accessor` if `name` identifies an attribute of this
522 /// class, and -1 otherwise.
523 template<class ACCESSOR>
524 int accessAttribute(ACCESSOR& accessor,
525 const char *name,
526 int nameLength) const;
527
528 /// Return a reference to the non-modifiable "InitialIndentLevel"
529 /// attribute of this object.
530 int initialIndentLevel() const;
531
532 /// Return a reference to the non-modifiable "SpacesPerLevel" attribute
533 /// of this object.
534 int spacesPerLevel() const;
535
536 /// Return a reference to the non-modifiable "EncodingStyle" attribute
537 /// of this object.
539
540 /// Return a reference to the non-modifiable "EncodeEmptyArrays"
541 /// attribute of this object. Note that empty arrays occurring as
542 /// selections of choices are always encoded regardless of the setting
543 /// of this option.
544 bool encodeEmptyArrays() const;
545
546 /// Return a reference to the non-modifiable "EncodeNullElements"
547 /// attribute of this object.
548 bool encodeNullElements() const;
549
550 /// Return a reference to the non-modifiable "EncodeInfAndNaNAsStrings"
551 /// attribute of this object.
552 bool encodeInfAndNaNAsStrings() const;
553
554 /// Return a reference to the non-modifiable
555 /// "DatetimeFractionalSecondPrecision" attribute of this object.
557
558 /// Return a reference to the non-modifiable "MaxFloatPrecision"
559 /// attribute of this object.
560 int maxFloatPrecision() const;
561
562 /// Return a reference to the non-modifiable "MaxDoublePrecision"
563 /// attribute of this object.
564 int maxDoublePrecision() const;
565
566 /// Return the value of the "EncodeQuotedDecimal64" attribute of this
567 /// object.
568 bool encodeQuotedDecimal64() const;
569};
570
571// FREE OPERATORS
572
573/// Return `true` if the specified `lhs` and `rhs` attribute objects have
574/// the same value, and `false` otherwise. Two attribute objects have the
575/// same value if each respective attribute has the same value.
576inline
577bool operator==(const EncoderOptions& lhs, const EncoderOptions& rhs);
578
579/// Return `true` if the specified `lhs` and `rhs` attribute objects do not
580/// have the same value, and `false` otherwise. Two attribute objects do
581/// not have the same value if one or more respective attributes differ in
582/// values.
583inline
584bool operator!=(const EncoderOptions& lhs, const EncoderOptions& rhs);
585
586/// Format the specified `rhs` to the specified output `stream` and
587/// return a reference to the modifiable `stream`.
588inline
589bsl::ostream& operator<<(bsl::ostream& stream, const EncoderOptions& rhs);
590
591} // close package namespace
592
593// TRAITS
594
596
597// ============================================================================
598// INLINE FUNCTION DEFINITIONS
599// ============================================================================
600
601namespace baljsn {
602
603 // --------------------
604 // class EncoderOptions
605 // --------------------
606
607// CLASS METHODS
608// MANIPULATORS
609template <class MANIPULATOR>
610int EncoderOptions::manipulateAttributes(MANIPULATOR& manipulator)
611{
612 int ret;
613
614 ret = manipulator(&d_initialIndentLevel, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_INITIAL_INDENT_LEVEL]);
615 if (ret) {
616 return ret;
617 }
618
619 ret = manipulator(&d_spacesPerLevel, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_SPACES_PER_LEVEL]);
620 if (ret) {
621 return ret;
622 }
623
624 ret = manipulator(&d_encodingStyle, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODING_STYLE]);
625 if (ret) {
626 return ret;
627 }
628
629 ret = manipulator(&d_encodeEmptyArrays, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_EMPTY_ARRAYS]);
630 if (ret) {
631 return ret;
632 }
633
634 ret = manipulator(&d_encodeNullElements, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_NULL_ELEMENTS]);
635 if (ret) {
636 return ret;
637 }
638
639 ret = manipulator(&d_encodeInfAndNaNAsStrings, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_INF_AND_NA_N_AS_STRINGS]);
640 if (ret) {
641 return ret;
642 }
643
644 ret = manipulator(&d_datetimeFractionalSecondPrecision, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_DATETIME_FRACTIONAL_SECOND_PRECISION]);
645 if (ret) {
646 return ret;
647 }
648
649 ret = manipulator(&d_maxFloatPrecision, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_MAX_FLOAT_PRECISION]);
650 if (ret) {
651 return ret;
652 }
653
654 ret = manipulator(&d_maxDoublePrecision, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_MAX_DOUBLE_PRECISION]);
655 if (ret) {
656 return ret;
657 }
658
659 ret = manipulator(&d_encodeQuotedDecimal64, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_QUOTED_DECIMAL64]);
660 if (ret) {
661 return ret;
662 }
663
664 return ret;
665}
666
667template <class MANIPULATOR>
668int EncoderOptions::manipulateAttribute(MANIPULATOR& manipulator, int id)
669{
670 enum { NOT_FOUND = -1 };
671
672 switch (id) {
674 return manipulator(&d_initialIndentLevel, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_INITIAL_INDENT_LEVEL]);
675 } break;
677 return manipulator(&d_spacesPerLevel, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_SPACES_PER_LEVEL]);
678 } break;
680 return manipulator(&d_encodingStyle, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODING_STYLE]);
681 } break;
683 return manipulator(&d_encodeEmptyArrays, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_EMPTY_ARRAYS]);
684 } break;
686 return manipulator(&d_encodeNullElements, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_NULL_ELEMENTS]);
687 } break;
689 return manipulator(&d_encodeInfAndNaNAsStrings, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_INF_AND_NA_N_AS_STRINGS]);
690 } break;
692 return manipulator(&d_datetimeFractionalSecondPrecision, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_DATETIME_FRACTIONAL_SECOND_PRECISION]);
693 } break;
695 return manipulator(&d_maxFloatPrecision, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_MAX_FLOAT_PRECISION]);
696 } break;
698 return manipulator(&d_maxDoublePrecision, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_MAX_DOUBLE_PRECISION]);
699 } break;
701 return manipulator(&d_encodeQuotedDecimal64, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_QUOTED_DECIMAL64]);
702 } break;
703 default:
704 return NOT_FOUND;
705 }
706}
707
708template <class MANIPULATOR>
710 MANIPULATOR& manipulator,
711 const char *name,
712 int nameLength)
713{
714 enum { NOT_FOUND = -1 };
715
716 const bdlat_AttributeInfo *attributeInfo =
717 lookupAttributeInfo(name, nameLength);
718 if (0 == attributeInfo) {
719 return NOT_FOUND;
720 }
721
722 return manipulateAttribute(manipulator, attributeInfo->d_id);
723}
724
725inline
727{
728 BSLS_ASSERT(0 <= value);
729
730 d_initialIndentLevel = value;
731}
732
733inline
735{
736 BSLS_ASSERT(0 <= value);
737
738 d_spacesPerLevel = value;
739}
740
741inline
743{
744 d_encodingStyle = value;
745}
746
747inline
750{
751 d_encodingStyle = static_cast<baljsn::EncodingStyle::Value>(value);
752}
753
754inline
756{
757 d_encodeEmptyArrays = value;
758}
759
760inline
762{
763 d_encodeNullElements = value;
764}
765
766inline
768{
769 d_encodeInfAndNaNAsStrings = value;
770}
771
772inline
774{
775 BSLS_ASSERT(0 <= value );
776 BSLS_ASSERT( value <= 6);
777
778 d_datetimeFractionalSecondPrecision = value;
779}
780
781inline
783{
784 d_maxFloatPrecision = value;
785}
786
787inline
789{
790 d_maxDoublePrecision = value;
791}
792
793inline
795{
796 d_encodeQuotedDecimal64 = value;
797}
798
799// ACCESSORS
800template <class ACCESSOR>
801int EncoderOptions::accessAttributes(ACCESSOR& accessor) const
802{
803 int ret;
804
805 ret = accessor(d_initialIndentLevel, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_INITIAL_INDENT_LEVEL]);
806 if (ret) {
807 return ret;
808 }
809
810 ret = accessor(d_spacesPerLevel, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_SPACES_PER_LEVEL]);
811 if (ret) {
812 return ret;
813 }
814
815 ret = accessor(d_encodingStyle, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODING_STYLE]);
816 if (ret) {
817 return ret;
818 }
819
820 ret = accessor(d_encodeEmptyArrays, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_EMPTY_ARRAYS]);
821 if (ret) {
822 return ret;
823 }
824
825 ret = accessor(d_encodeNullElements, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_NULL_ELEMENTS]);
826 if (ret) {
827 return ret;
828 }
829
830 ret = accessor(d_encodeInfAndNaNAsStrings, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_INF_AND_NA_N_AS_STRINGS]);
831 if (ret) {
832 return ret;
833 }
834
835 ret = accessor(d_datetimeFractionalSecondPrecision, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_DATETIME_FRACTIONAL_SECOND_PRECISION]);
836 if (ret) {
837 return ret;
838 }
839
840 ret = accessor(d_maxFloatPrecision, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_MAX_FLOAT_PRECISION]);
841 if (ret) {
842 return ret;
843 }
844
845 ret = accessor(d_maxDoublePrecision, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_MAX_DOUBLE_PRECISION]);
846 if (ret) {
847 return ret;
848 }
849
850 ret = accessor(d_encodeQuotedDecimal64, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_QUOTED_DECIMAL64]);
851 if (ret) {
852 return ret;
853 }
854
855 return ret;
856}
857
858template <class ACCESSOR>
859int EncoderOptions::accessAttribute(ACCESSOR& accessor, int id) const
860{
861 enum { NOT_FOUND = -1 };
862
863 switch (id) {
865 return accessor(d_initialIndentLevel, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_INITIAL_INDENT_LEVEL]);
866 } break;
868 return accessor(d_spacesPerLevel, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_SPACES_PER_LEVEL]);
869 } break;
871 return accessor(d_encodingStyle, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODING_STYLE]);
872 } break;
874 return accessor(d_encodeEmptyArrays, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_EMPTY_ARRAYS]);
875 } break;
877 return accessor(d_encodeNullElements, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_NULL_ELEMENTS]);
878 } break;
880 return accessor(d_encodeInfAndNaNAsStrings, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_INF_AND_NA_N_AS_STRINGS]);
881 } break;
883 return accessor(d_datetimeFractionalSecondPrecision, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_DATETIME_FRACTIONAL_SECOND_PRECISION]);
884 } break;
886 return accessor(d_maxFloatPrecision, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_MAX_FLOAT_PRECISION]);
887 } break;
889 return accessor(d_maxDoublePrecision, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_MAX_DOUBLE_PRECISION]);
890 } break;
892 return accessor(d_encodeQuotedDecimal64, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_ENCODE_QUOTED_DECIMAL64]);
893 } break;
894 default:
895 return NOT_FOUND;
896 }
897}
898
899template <class ACCESSOR>
901 ACCESSOR& accessor,
902 const char *name,
903 int nameLength) const
904{
905 enum { NOT_FOUND = -1 };
906
907 const bdlat_AttributeInfo *attributeInfo =
908 lookupAttributeInfo(name, nameLength);
909 if (0 == attributeInfo) {
910 return NOT_FOUND;
911 }
912
913 return accessAttribute(accessor, attributeInfo->d_id);
914}
915
916inline
918{
919 return d_initialIndentLevel;
920}
921
922inline
924{
925 return d_spacesPerLevel;
926}
927
928inline
933
934inline
936{
937 return d_encodeEmptyArrays;
938}
939
940inline
942{
943 return d_encodeNullElements;
944}
945
946inline
948{
949 return d_encodeInfAndNaNAsStrings;
950}
951
952inline
954{
955 return d_datetimeFractionalSecondPrecision;
956}
957
958inline
960{
961 return d_maxFloatPrecision;
962}
963
964inline
966{
967 return d_maxDoublePrecision;
968}
969
970inline
972{
973 return d_encodeQuotedDecimal64;
974}
975
976} // close package namespace
977
978// FREE FUNCTIONS
979
980inline
982 const baljsn::EncoderOptions& lhs,
983 const baljsn::EncoderOptions& rhs)
984{
985 return lhs.initialIndentLevel() == rhs.initialIndentLevel()
986 && lhs.spacesPerLevel() == rhs.spacesPerLevel()
987 && lhs.encodingStyle() == rhs.encodingStyle()
988 && lhs.encodeEmptyArrays() == rhs.encodeEmptyArrays()
989 && lhs.encodeNullElements() == rhs.encodeNullElements()
992 && lhs.maxFloatPrecision() == rhs.maxFloatPrecision()
993 && lhs.maxDoublePrecision() == rhs.maxDoublePrecision()
995}
996
997inline
999 const baljsn::EncoderOptions& lhs,
1000 const baljsn::EncoderOptions& rhs)
1001{
1002 return lhs.initialIndentLevel() != rhs.initialIndentLevel()
1003 || lhs.spacesPerLevel() != rhs.spacesPerLevel()
1004 || lhs.encodingStyle() != rhs.encodingStyle()
1005 || lhs.encodeEmptyArrays() != rhs.encodeEmptyArrays()
1006 || lhs.encodeNullElements() != rhs.encodeNullElements()
1009 || lhs.maxFloatPrecision() != rhs.maxFloatPrecision()
1010 || lhs.maxDoublePrecision() != rhs.maxDoublePrecision()
1012}
1013
1014inline
1015bsl::ostream& baljsn::operator<<(
1016 bsl::ostream& stream,
1017 const baljsn::EncoderOptions& rhs)
1018{
1019 return rhs.print(stream, 0, -1);
1020}
1021
1022
1023#endif
1024
1025// GENERATED BY BLP_BAS_CODEGEN_3.8.24 Fri Feb 17 12:35:40 2017
1026// USING bas_codegen.pl -m msg --package baljsn --noExternalization -E --noAggregateConversion baljsn.xsd
1027// SERVICE VERSION
1028// ----------------------------------------------------------------------------
1029// Copyright 2015 Bloomberg Finance L.P.
1030//
1031// Licensed under the Apache License, Version 2.0 (the "License");
1032// you may not use this file except in compliance with the License.
1033// You may obtain a copy of the License at
1034//
1035// http://www.apache.org/licenses/LICENSE-2.0
1036//
1037// Unless required by applicable law or agreed to in writing, software
1038// distributed under the License is distributed on an "AS IS" BASIS,
1039// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1040// See the License for the specific language governing permissions and
1041// limitations under the License.
1042// ----------------------------- END-OF-FILE ----------------------------------
1043
1044/** @} */
1045/** @} */
1046/** @} */
Definition baljsn_encoderoptions.h:262
static const int DEFAULT_INITIALIZER_DATETIME_FRACTIONAL_SECOND_PRECISION
Definition baljsn_encoderoptions.h:368
static const bdlat_AttributeInfo * lookupAttributeInfo(const char *name, int nameLength)
static const bdlat_AttributeInfo * lookupAttributeInfo(int id)
static const int DEFAULT_INITIALIZER_INITIAL_INDENT_LEVEL
Definition baljsn_encoderoptions.h:356
void setEncodingStyle(baljsn::EncodingStyle::Value value)
Definition baljsn_encoderoptions.h:742
static const int DEFAULT_INITIALIZER_MAX_DOUBLE_PRECISION
Definition baljsn_encoderoptions.h:372
static const baljsn::EncodingStyle::Value DEFAULT_INITIALIZER_ENCODING_STYLE
Definition baljsn_encoderoptions.h:360
void setMaxFloatPrecision(int value)
Definition baljsn_encoderoptions.h:782
int manipulateAttribute(MANIPULATOR &manipulator, int id)
Definition baljsn_encoderoptions.h:668
static const char CLASS_NAME[]
Definition baljsn_encoderoptions.h:354
static const bool DEFAULT_INITIALIZER_ENCODE_QUOTED_DECIMAL64
Definition baljsn_encoderoptions.h:374
static const bool DEFAULT_INITIALIZER_ENCODE_NULL_ELEMENTS
Definition baljsn_encoderoptions.h:364
~EncoderOptions()
Destroy this object.
static const bool DEFAULT_INITIALIZER_ENCODE_EMPTY_ARRAYS
Definition baljsn_encoderoptions.h:362
EncodingStyle
Definition baljsn_encoderoptions.h:314
@ BAEJSN_PRETTY
Definition baljsn_encoderoptions.h:319
@ e_COMPACT
Definition baljsn_encoderoptions.h:315
@ e_PRETTY
Definition baljsn_encoderoptions.h:316
@ BAEJSN_COMPACT
Definition baljsn_encoderoptions.h:318
bool encodeInfAndNaNAsStrings() const
Definition baljsn_encoderoptions.h:947
void setEncodeQuotedDecimal64(bool value)
Definition baljsn_encoderoptions.h:794
int maxFloatPrecision() const
Definition baljsn_encoderoptions.h:959
bool encodeNullElements() const
Definition baljsn_encoderoptions.h:941
static const bool DEFAULT_INITIALIZER_ENCODE_INF_AND_NA_N_AS_STRINGS
Definition baljsn_encoderoptions.h:366
void setInitialIndentLevel(int value)
Definition baljsn_encoderoptions.h:726
void setDatetimeFractionalSecondPrecision(int value)
Definition baljsn_encoderoptions.h:773
void setEncodeEmptyArrays(bool value)
Definition baljsn_encoderoptions.h:755
int maxDoublePrecision() const
Definition baljsn_encoderoptions.h:965
EncoderOptions()
Create an object of type EncoderOptions having the default value.
void setSpacesPerLevel(int value)
Definition baljsn_encoderoptions.h:734
EncoderOptions & operator=(const EncoderOptions &rhs)
Assign to this object the value of the specified rhs object.
static const int DEFAULT_INITIALIZER_SPACES_PER_LEVEL
Definition baljsn_encoderoptions.h:358
int datetimeFractionalSecondPrecision() const
Definition baljsn_encoderoptions.h:953
@ ATTRIBUTE_ID_ENCODE_EMPTY_ARRAYS
Definition baljsn_encoderoptions.h:327
@ ATTRIBUTE_ID_INITIAL_INDENT_LEVEL
Definition baljsn_encoderoptions.h:324
@ ATTRIBUTE_ID_DATETIME_FRACTIONAL_SECOND_PRECISION
Definition baljsn_encoderoptions.h:330
@ ATTRIBUTE_ID_MAX_DOUBLE_PRECISION
Definition baljsn_encoderoptions.h:332
@ ATTRIBUTE_ID_ENCODE_INF_AND_NA_N_AS_STRINGS
Definition baljsn_encoderoptions.h:329
@ ATTRIBUTE_ID_ENCODE_NULL_ELEMENTS
Definition baljsn_encoderoptions.h:328
@ ATTRIBUTE_ID_ENCODE_QUOTED_DECIMAL64
Definition baljsn_encoderoptions.h:333
@ ATTRIBUTE_ID_SPACES_PER_LEVEL
Definition baljsn_encoderoptions.h:325
@ ATTRIBUTE_ID_MAX_FLOAT_PRECISION
Definition baljsn_encoderoptions.h:331
@ ATTRIBUTE_ID_ENCODING_STYLE
Definition baljsn_encoderoptions.h:326
void setEncodeNullElements(bool value)
Definition baljsn_encoderoptions.h:761
baljsn::EncoderOptions::EncodingStyle encodingStyle() const
Definition baljsn_encoderoptions.h:929
@ ATTRIBUTE_INDEX_ENCODE_INF_AND_NA_N_AS_STRINGS
Definition baljsn_encoderoptions.h:346
@ ATTRIBUTE_INDEX_ENCODE_QUOTED_DECIMAL64
Definition baljsn_encoderoptions.h:350
@ ATTRIBUTE_INDEX_MAX_FLOAT_PRECISION
Definition baljsn_encoderoptions.h:348
@ ATTRIBUTE_INDEX_ENCODE_EMPTY_ARRAYS
Definition baljsn_encoderoptions.h:344
@ ATTRIBUTE_INDEX_ENCODING_STYLE
Definition baljsn_encoderoptions.h:343
@ ATTRIBUTE_INDEX_SPACES_PER_LEVEL
Definition baljsn_encoderoptions.h:342
@ ATTRIBUTE_INDEX_INITIAL_INDENT_LEVEL
Definition baljsn_encoderoptions.h:341
@ ATTRIBUTE_INDEX_ENCODE_NULL_ELEMENTS
Definition baljsn_encoderoptions.h:345
@ ATTRIBUTE_INDEX_MAX_DOUBLE_PRECISION
Definition baljsn_encoderoptions.h:349
@ ATTRIBUTE_INDEX_DATETIME_FRACTIONAL_SECOND_PRECISION
Definition baljsn_encoderoptions.h:347
@ NUM_ATTRIBUTES
Definition baljsn_encoderoptions.h:337
EncoderOptions(const EncoderOptions &original)
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
static const bdlat_AttributeInfo ATTRIBUTE_INFO_ARRAY[]
Definition baljsn_encoderoptions.h:376
int accessAttributes(ACCESSOR &accessor) const
Definition baljsn_encoderoptions.h:801
bool encodeQuotedDecimal64() const
Definition baljsn_encoderoptions.h:971
int initialIndentLevel() const
Definition baljsn_encoderoptions.h:917
static const int DEFAULT_INITIALIZER_MAX_FLOAT_PRECISION
Definition baljsn_encoderoptions.h:370
int accessAttribute(ACCESSOR &accessor, int id) const
Definition baljsn_encoderoptions.h:859
int spacesPerLevel() const
Definition baljsn_encoderoptions.h:923
bool encodeEmptyArrays() const
Definition baljsn_encoderoptions.h:935
int manipulateAttributes(MANIPULATOR &manipulator)
Definition baljsn_encoderoptions.h:610
void setEncodeInfAndNaNAsStrings(bool value)
Definition baljsn_encoderoptions.h:767
void setMaxDoublePrecision(int value)
Definition baljsn_encoderoptions.h:788
#define BDLAT_DECL_SEQUENCE_WITH_BITWISEMOVEABLE_TRAITS(ClassName)
Definition bdlat_typetraits.h:275
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition baljsn_datumdecoderoptions.h:113
bool operator==(const DatumDecoderOptions &lhs, const DatumDecoderOptions &rhs)
bsl::ostream & operator<<(bsl::ostream &stream, const DatumDecoderOptions &rhs)
bool operator!=(const DatumDecoderOptions &lhs, const DatumDecoderOptions &rhs)
Value
Definition baljsn_encodingstyle.h:78
@ e_COMPACT
Definition baljsn_encodingstyle.h:79
@ e_PRETTY
Definition baljsn_encodingstyle.h:80
Definition bdlat_attributeinfo.h:137
int d_id
Definition bdlat_attributeinfo.h:140