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

Detailed Description

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:169
bool strictTypes() const
Return the "StrictTypes" attribute of this object.
Definition baljsn_datumencoderoptions.h:370
int initialIndentLevel() const
Return the "InitialIndentLevel" attribute of this object.
Definition baljsn_datumencoderoptions.h:358
baljsn::EncodingStyle::Value encodingStyle() const
Return the "EncodingStyle" attribute of this object.
Definition baljsn_datumencoderoptions.h:352
int spacesPerLevel() const
Return the "SpacesPerLevel" attribute of this object.
Definition baljsn_datumencoderoptions.h:364
bool encodeQuotedDecimal64() const
Definition baljsn_datumencoderoptions.h:376
@ e_COMPACT
Definition baljsn_encodingstyle.h:79

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:317
void setEncodeQuotedDecimal64(bool value)
Definition baljsn_datumencoderoptions.h:345
void setSpacesPerLevel(int value)
Definition baljsn_datumencoderoptions.h:331
void setStrictTypes(bool value)
Definition baljsn_datumencoderoptions.h:339
void setInitialIndentLevel(int value)
Definition baljsn_datumencoderoptions.h:323
@ e_PRETTY
Definition baljsn_encodingstyle.h:80