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

Detailed Description

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
------------------ ----------- ------- ------------------
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(0 == options.initialIndentLevel());
assert(4 == options.spacesPerLevel());
assert(false == options.sortMembers());
assert(bdljsn::WriteStyle::e_COMPACT == options.style());
Definition bdljsn_writeoptions.h:134
int initialIndentLevel() const
Return the initialIndentLevel attribute of this object.
Definition bdljsn_writeoptions.h:333
bool sortMembers() const
Return the sortMembers attribute of this object.
Definition bdljsn_writeoptions.h:339
int spacesPerLevel() const
Return the spacesPerLevel attribute of this object.
Definition bdljsn_writeoptions.h:345
bdljsn::WriteStyle::Enum style() const
Return the style attribute of this object.
Definition bdljsn_writeoptions.h:351
@ e_COMPACT
Definition bdljsn_writestyle.h:130

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:316
WriteOptions & setInitialIndentLevel(int value)
Definition bdljsn_writeoptions.h:300