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

Detailed Description

Provide options for writing a JSON document.

Outline

Purpose

Provide options for writing a JSON document.

Classes

See also
bdljsn_jsonutil, bdljsn_json

Description

This component provides a single, simply constrained (value-semantic) attribute class, bdljsn::WriteOptions, that is used to specify options for writing a JSON document (see bdljsn_jsonutil ).

Attributes

Name Type Default Simple Constraints
------------------ ----------- ------- ------------------
escapeForwardSlash bool true none
initialIndentLevel int 0 >= 0
sortMembers bool false none
spacesPerLevel int 4 >= 0
style WriteStyle e_COMPACT none

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

First, we default-construct a bdljsn::WriteOptions object:

const int INITIAL_INDENT_LEVEL = 1;
const int SPACES_PER_LEVEL = 4;
assert(true == options.escapeForwardSlash());
assert(0 == options.initialIndentLevel());
assert(4 == options.spacesPerLevel());
assert(false == options.sortMembers());
assert(bdljsn::WriteStyle::e_COMPACT == options.style());
Definition bdljsn_writeoptions.h:138
int initialIndentLevel() const
Return the initialIndentLevel attribute of this object.
Definition bdljsn_writeoptions.h:367
bool escapeForwardSlash() const
Return the escapeForwardSlash attribute of this object.
Definition bdljsn_writeoptions.h:361
bool sortMembers() const
Return the sortMembers attribute of this object.
Definition bdljsn_writeoptions.h:373
int spacesPerLevel() const
Return the spacesPerLevel attribute of this object.
Definition bdljsn_writeoptions.h:379
bdljsn::WriteStyle::Enum style() const
Return the style attribute of this object.
Definition bdljsn_writeoptions.h:385
@ e_COMPACT
Definition bdljsn_writestyle.h:132

Finally, we populate that object 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());
WriteOptions & setSpacesPerLevel(int value)
Definition bdljsn_writeoptions.h:344
WriteOptions & setInitialIndentLevel(int value)
Definition bdljsn_writeoptions.h:328