BDE 4.14.0 Production release
Loading...
Searching...
No Matches
baljsn_encoderoptions

Detailed Description

Outline

Purpose

Provide an attribute class for specifying JSON encoding options.

Classes

See also
baljsn_encoder, baljsn_decoderoptions

Description

This component provides a single, simply constrained (value-semantic) attribute class, baljsn::EncoderOptions, that is used to specify options for encoding objects in the JSON format.

Attributes

Name Type Default Simple Constraints
------------------ ----------- ------- ------------------
encodingStyle EncodingStyle e_COMPACT none
initialIndentLevel int 0 >= 0
spacesPerLevel int 0 >= 0
encodeEmptyArrays bool false none
encodeNullElements bool false none
encodeInfAndNaNAsStrings
bool false none
encodeQuotedDecimal64
bool true none
datetimeFractionalSecondPrecision
int 3 >= 0 and <= 6
maxFloatPrecision int 0 >= 1 and <= 9 or 0
maxDoublePrecision int 0 >= 1 and <= 17 or 0

Implementation Note

This file was generated from a script and was subsequently modified to add documentation and to make other changes. The steps to generate and update this file can be found in the doc/generating_codec_options.txt file.

Usage

This section illustrates intended use of this component.

Example 1: Creating and Populating an Options Object

This component is designed to be used at a higher level to set the options for encoding objects in the JSON format. This example shows how to create and populate an options object.

First, we default-construct a baljsn::EncoderOptions object:

const int INITIAL_INDENT_LEVEL = 1;
const int SPACES_PER_LEVEL = 4;
const bool ENCODE_EMPTY_ARRAYS = true;
const bool ENCODE_NULL_ELEMENTS = true;
const bool ENCODE_INF_NAN_AS_STRINGS = true;
const int DATETIME_PRECISION = 6;
const int FLOAT_PRECISION = 3;
const int DOUBLE_PRECISION = 9;
const bool ENCODE_QUOTED_DECIMAL64 = false;
assert(0 == options.initialIndentLevel());
assert(0 == options.spacesPerLevel());
assert(false == options.encodeEmptyArrays());
assert(false == options.encodeNullElements());
assert(false == options.encodeInfAndNaNAsStrings());
assert(3 == options.datetimeFractionalSecondPrecision());
assert(0 == options.maxFloatPrecision());
assert(0 == options.maxDoublePrecision());
assert(true == options.encodeQuotedDecimal64());
Definition baljsn_encoderoptions.h:262
@ e_COMPACT
Definition baljsn_encoderoptions.h:315
bool encodeInfAndNaNAsStrings() const
Definition baljsn_encoderoptions.h:947
int maxFloatPrecision() const
Definition baljsn_encoderoptions.h:959
bool encodeNullElements() const
Definition baljsn_encoderoptions.h:941
int maxDoublePrecision() const
Definition baljsn_encoderoptions.h:965
int datetimeFractionalSecondPrecision() const
Definition baljsn_encoderoptions.h:953
baljsn::EncoderOptions::EncodingStyle encodingStyle() const
Definition baljsn_encoderoptions.h:929
bool encodeQuotedDecimal64() const
Definition baljsn_encoderoptions.h:971
int initialIndentLevel() const
Definition baljsn_encoderoptions.h:917
int spacesPerLevel() const
Definition baljsn_encoderoptions.h:923
bool encodeEmptyArrays() const
Definition baljsn_encoderoptions.h:935

Next, we populate that object to encode in a prett format using a pre-defined initial indent level and spaces per level:

options.setInitialIndentLevel(INITIAL_INDENT_LEVEL);
assert(INITIAL_INDENT_LEVEL == options.initialIndentLevel());
options.setSpacesPerLevel(SPACES_PER_LEVEL);
assert(SPACES_PER_LEVEL == options.spacesPerLevel());
options.setEncodeEmptyArrays(ENCODE_EMPTY_ARRAYS);
assert(ENCODE_EMPTY_ARRAYS == options.encodeEmptyArrays());
options.setEncodeNullElements(ENCODE_NULL_ELEMENTS);
assert(ENCODE_NULL_ELEMENTS == options.encodeNullElements());
options.setEncodeInfAndNaNAsStrings(ENCODE_INF_NAN_AS_STRINGS);
assert(ENCODE_INF_NAN_AS_STRINGS == options.encodeInfAndNaNAsStrings());
options.setDatetimeFractionalSecondPrecision(DATETIME_PRECISION);
assert(DATETIME_PRECISION == options.datetimeFractionalSecondPrecision());
options.setMaxFloatPrecision(FLOAT_PRECISION);
assert(FLOAT_PRECISION == options.maxFloatPrecision());
options.setMaxDoublePrecision(DOUBLE_PRECISION);
assert(DOUBLE_PRECISION == options.maxDoublePrecision());
options.setEncodeQuotedDecimal64(ENCODE_QUOTED_DECIMAL64);
ASSERT(ENCODE_QUOTED_DECIMAL64 == options.encodeQuotedDecimal64());
void setEncodingStyle(baljsn::EncodingStyle::Value value)
Definition baljsn_encoderoptions.h:742
void setMaxFloatPrecision(int value)
Definition baljsn_encoderoptions.h:782
@ e_PRETTY
Definition baljsn_encoderoptions.h:316
void setEncodeQuotedDecimal64(bool value)
Definition baljsn_encoderoptions.h:794
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
void setSpacesPerLevel(int value)
Definition baljsn_encoderoptions.h:734
void setEncodeNullElements(bool value)
Definition baljsn_encoderoptions.h:761
void setEncodeInfAndNaNAsStrings(bool value)
Definition baljsn_encoderoptions.h:767
void setMaxDoublePrecision(int value)
Definition baljsn_encoderoptions.h:788
@ e_PRETTY
Definition baljsn_encodingstyle.h:80