BDE 4.39.x Production Release
Loading...
Searching...
No Matches
baljsn_datumencoderoptions

Detailed Description

Provide an attribute class for specifying Datum<->JSON options.

Outline

Purpose

Provide an attribute class for specifying Datum<->JSON options.

Classes

See also
baljsn_datumutil

Description

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

Attributes

Name Type Default Simple Constraints
------------------ ----------- ------- ------------------
strictTypes bool false none
encodingStyle EncodingStyle e_COMPACT none
encodeQuotedDecimal64
bool true none
initialIndentLevel int 0 >= 0
spacesPerLevel int 0 >= 0

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 Datum objects in the JSON format. This example shows how to create and populate an options object.

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

const bool STRICT_TYPES = true;
const int INITIAL_INDENT_LEVEL = 1;
const int SPACES_PER_LEVEL = 4;
const bool ENCODE_QUOTED_DECIMAL64 = false;
assert(false == options.strictTypes());
assert(0 == options.initialIndentLevel());
assert(0 == options.spacesPerLevel());
assert(true == options.encodeQuotedDecimal64());
Definition baljsn_datumencoderoptions.h:170
bool strictTypes() const
Return the "StrictTypes" attribute of this object.
Definition baljsn_datumencoderoptions.h:374
int initialIndentLevel() const
Return the "InitialIndentLevel" attribute of this object.
Definition baljsn_datumencoderoptions.h:362
baljsn::EncodingStyle::Value encodingStyle() const
Return the "EncodingStyle" attribute of this object.
Definition baljsn_datumencoderoptions.h:356
int spacesPerLevel() const
Return the "SpacesPerLevel" attribute of this object.
Definition baljsn_datumencoderoptions.h:368
bool encodeQuotedDecimal64() const
Definition baljsn_datumencoderoptions.h:380
@ e_COMPACT
Definition baljsn_encodingstyle.h:81

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

options.setStrictTypes(STRICT_TYPES);
assert(true == options.strictTypes());
options.setEncodeQuotedDecimal64(ENCODE_QUOTED_DECIMAL64);
ASSERT(ENCODE_QUOTED_DECIMAL64 == options.encodeQuotedDecimal64());
options.setInitialIndentLevel(INITIAL_INDENT_LEVEL);
assert(INITIAL_INDENT_LEVEL == options.initialIndentLevel());
options.setSpacesPerLevel(SPACES_PER_LEVEL);
assert(SPACES_PER_LEVEL == options.spacesPerLevel());
void setEncodingStyle(baljsn::EncodingStyle::Value value)
Definition baljsn_datumencoderoptions.h:321
void setEncodeQuotedDecimal64(bool value)
Definition baljsn_datumencoderoptions.h:349
void setSpacesPerLevel(int value)
Definition baljsn_datumencoderoptions.h:335
void setStrictTypes(bool value)
Definition baljsn_datumencoderoptions.h:343
void setInitialIndentLevel(int value)
Definition baljsn_datumencoderoptions.h:327
@ e_PRETTY
Definition baljsn_encodingstyle.h:82