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

#include <baljsn_jsonformatter.h>

Detailed Description

This class implements a formatter mechanism that assembles a (potentially complicated) bdljsn::Json object according to the invocations of the formatter's manipulators.

See baljsn_jsonformatter

Public Types

typedef bsl::allocator< char > allocator_type
 

Public Member Functions

void dumpStack ()
 
 JsonFormatter (bdljsn::Json *json, const allocator_type &allocator=allocator_type())
 
 ~JsonFormatter ()=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
 
allocator_type get_allocator () const
 

Public Attributes

allocator_type d_allocator
 
bsl::stack< Status > d_stack
 

Member Typedef Documentation

◆ allocator_type

Constructor & Destructor Documentation

◆ JsonFormatter()

baljsn::JsonFormatter::JsonFormatter ( bdljsn::Json json,
const allocator_type allocator = allocator_type() 
)
inline

Create a JsonFormatter object that modifies the specified json object in accordance with subsequent calls the formatter manipulators. Optionally specify an allocator (e.g., the address of a bslma::Allocator object) to supply memory; otherwise, the default allocator is used.

Precondition
The behavior is undefined unless json->isNull().

◆ ~JsonFormatter()

baljsn::JsonFormatter::~JsonFormatter ( )
default

Destroy this object.

Member Function Documentation

◆ addArrayElementSeparator()

void baljsn::JsonFormatter::addArrayElementSeparator ( )
inline

No-op.

◆ closeArray()

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

Indicate that there are no more elements to be added to the current array. The specified formatAsEmptyArray is ignored; arrays are unconditionally formatted.

◆ closeMember()

void baljsn::JsonFormatter::closeMember ( )

Indicate that there are no more members to be added to the current object.

◆ closeObject()

void baljsn::JsonFormatter::closeObject ( )

Indicate that there are no more members to be added to the current object.

◆ dumpStack()

void baljsn::JsonFormatter::dumpStack ( )

Print the internal stack of Status objects to standard output in lifo order. Each line of output consists of:

Note
Note that this function is provided for debugging only.

◆ get_allocator()

JsonFormatter::allocator_type baljsn::JsonFormatter::get_allocator ( ) const
inline

Return the allocator used by this object to supply memory.

Note
Note that if no allocator was supplied at construction the default allocator in effect at construction is used.

◆ nestingDepth()

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

No-op. Return 0.

◆ openArray()

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

Create a new array. Subsequently created elements will land in this array (in order of creation) until closeArray is called. The elements can be created by putValue/putNullValue/openObject/openArray. The specified formatAsEmptyArray is ignored; arrays are unconditionally formatted.

◆ openMember()

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

Create a new object member having the specified name. Return 0 on success and a non-zero value otherwise. An error is returned if name contains a non-UTF8 character.

◆ openObject()

void baljsn::JsonFormatter::openObject ( )

Create a new object (set of name/value pairs also know as "members"). Note subsequently created members will land in this object until closeObject is called.

◆ putNullValue()

int baljsn::JsonFormatter::putNullValue ( )

Set the value of the current array element or object value – depending on the context – to bdljsn::JsonNull. Return 0 on success and a non-zero value otherwise. An error is returned when putNullValue is called in an unexpected context.

◆ putValue()

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

Set the value of the current scalar, array element, or object value – depending on the context – to the specified value of (template parameter) TYPE. The specified options is ignored except:

  • encodeInfAndNaNAsStrings when TYPE is a floating point type.
  • datetimeFractionalSecondPrecision when TYPE features a datetime or time attribute. Return 0 on success and a non-zero value otherwise. Errors are returned if value is disallowed for bdljsn::Json objects:
  • value is a string type and contains a non-UTF8 character.
  • value is a floating point type, is INF or NaN, and false == encodeInfAndNanAsStrings.

Member Data Documentation

◆ d_allocator

allocator_type baljsn::JsonFormatter::d_allocator

◆ d_stack

bsl::stack<Status> baljsn::JsonFormatter::d_stack

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