BDE 4.39.x Production Release
Loading...
Searching...
No Matches
baljsn::Formatter Class Reference

#include <baljsn_formatter.h>

Detailed Description

This class implements a formatter providing operations for rendering JSON text elements to an output stream (supplied at construction) according to a set of formatting options (also supplied at construction).

See baljsn_formatter

Public Member Functions

 Formatter (bsl::ostream &stream, bool usePrettyStyle=false, int initialIndentLevel=0, int spacesPerLevel=0, bslma::Allocator *basicAllocator=0)
 
 Formatter (bsl::ostream &stream, bool usePrettyStyle, int initialIndentLevel, int spacesPerLevel, bool escapeForwardSlash, bslma::Allocator *basicAllocator=0)
 
 ~Formatter ()=default
 
void openObject ()
 
void closeObject ()
 
void openArray (bool formatAsEmptyArray=false)
 
void closeArray (bool formatAsEmptyArray=false)
 
int openMember (const bsl::string_view &name)
 
int putNullValue ()
 
template<class TYPE >
int putValue (const TYPE &value, const EncoderOptions *options=0)
 
void closeMember ()
 
void addArrayElementSeparator ()
 
int nestingDepth () const
 

Constructor & Destructor Documentation

◆ Formatter() [1/2]

baljsn::Formatter::Formatter ( bsl::ostream &  stream,
bool  usePrettyStyle = false,
int  initialIndentLevel = 0,
int  spacesPerLevel = 0,
bslma::Allocator basicAllocator = 0 
)

Create a Formatter object using the specified stream. Optionally specify usePrettyStyle to inform the formatter whether the pretty encoding style should be used when writing data. If usePrettyStyle is not specified then the data is written in a compact style. If usePrettyStyle is specified, additionally specify initialIndentLevel and spacesPerLevel to provide the initial indentation level and spaces per level at which the data should be formatted. If initialIndentLevel or spacesPerLevel is not specified then an initial value of 0 is used for both parameters. If usePrettyStyle is false then initialIndentLevel and spacesPerLevel are both ignored. Optionally specify escapeForwardSlash. If escapeForwardSlash is specified as false, / characters will be formatted as-is, otherwise, they will be rendered with a leading backslash, as "\\/". Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ Formatter() [2/2]

baljsn::Formatter::Formatter ( bsl::ostream &  stream,
bool  usePrettyStyle,
int  initialIndentLevel,
int  spacesPerLevel,
bool  escapeForwardSlash,
bslma::Allocator basicAllocator = 0 
)

◆ ~Formatter()

baljsn::Formatter::~Formatter ( )
default

Destroy this object.

Member Function Documentation

◆ addArrayElementSeparator()

void baljsn::Formatter::addArrayElementSeparator ( )

Print onto the stream supplied at construction the sequence of characters designating an array element separator (i.e., ,).

Precondition
The behavior is undefined unless this Formatter is currently formatting a member.

◆ closeArray()

void baljsn::Formatter::closeArray ( bool  formatAsEmptyArray = false)

Print onto the stream supplied at construction the sequence of characters designating the end of an array (referred to as an "array" in JSON). Optionally specify formatAsEmptyArray denoting if the array being closed should be formatted as an empty array. If formatAsEmptyArray is not specified then the array being closed is formatted as an array having elements.

Precondition
The behavior is undefined unless this Formatter is currently formatting an array.
Note
Note that the formatting (and as a consequence the formatAsEmptyArray) is relevant only if this formatter encodes in the pretty style and is ignored otherwise.

◆ closeMember()

void baljsn::Formatter::closeMember ( )

Print onto the stream supplied at construction the sequence of characters designating the end of an member (referred to as a "name/value pair" in JSON).

Precondition
The behavior is undefined unless this Formatter is currently formatting a member.

◆ closeObject()

void baljsn::Formatter::closeObject ( )

Print onto the stream supplied at construction the sequence of characters designating the end of an object (referred to as an "object" in JSON).

Precondition
The behavior is undefined unless this Formatter is currently formatting an object.

◆ nestingDepth()

int baljsn::Formatter::nestingDepth ( ) const
inline

Return the number of currently open nested objects or arrays.

◆ openArray()

void baljsn::Formatter::openArray ( bool  formatAsEmptyArray = false)

Print onto the stream supplied at construction the sequence of characters designating the start of an array (referred to as an "array" in JSON). Optionally specify formatAsEmptyArray denoting if the array being opened should be formatted as an empty array. If formatAsEmptyArray is not specified then the array being opened is formatted as an array having elements.

Note
Note that the formatting (and as a consequence the formatAsEmptyArray) is relevant only if this formatter encodes in the pretty style and is ignored otherwise.

◆ openMember()

int baljsn::Formatter::openMember ( const bsl::string_view name)

Print onto the stream supplied at construction the sequence of characters designating the start of a member (referred to as a "name/value pair" in JSON) having the specified name. Return 0 on success and a non-zero value otherwise.

◆ openObject()

void baljsn::Formatter::openObject ( )

Print onto the stream supplied at construction the sequence of characters designating the start of an object (referred to as an "object" in JSON).

◆ putNullValue()

int baljsn::Formatter::putNullValue ( )
inline

Print onto the stream supplied at construction the value corresponding to a null element. Return 0 on success and a non-zero value otherwise.

◆ putValue()

template<class TYPE >
int baljsn::Formatter::putValue ( const TYPE &  value,
const EncoderOptions options = 0 
)

Print onto the stream supplied at construction the specified value. Optionally specify options according which value should be encoded. Return 0 on success and a non-zero value otherwise.


The documentation for this class was generated from the following file: