|
BDE 4.14.0 Production release
|
#include <baljsn_simpleformatter.h>
Public Types | |
| enum | ArrayFormattingStyle { e_REGULAR_ARRAY_FORMAT = 1 , e_EMPTY_ARRAY_FORMAT } |
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).
This class has an interface that's easier to use than that of baljsn::Formatter, and generates more correctly-formatted pretty output.
|
explicit |
|
explicit |
Create a SimpleFormatter object using the specified stream. Optionally specify encoderOptions to configure the output options
encoderOptions is not supplied, a default-constructed EncoderOptions object will be used. Note that the encodeEmptyArrays attribute in the encoderOptions is ignored. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. | baljsn::SimpleFormatter::SimpleFormatter | ( | const SimpleFormatter & | original, |
| bslma::Allocator * | basicAllocator | ||
| ) |
Create a SimpleFormatter object having the same value as the specified original object. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.
| baljsn::SimpleFormatter::~SimpleFormatter | ( | ) |
Destroy this object. Note that correct JSON has been generated if the isCompleteJSON() call returns true.
|
inline |
Print onto the stream supplied at construction the specified name in double-quotes, preceded, if necessary, by a comma, and followed by a :. The behavior is undefined unless isNameNeeded() is true. After this operation, isNameNeeded() will be false, and an immediately subsequent attempt to add a value (or open an object or array) should not provide a name.
|
inline |
Print onto the stream supplied at construction the value corresponding to a null element, preceded, if necessary, by a comma. The behavior is undefined unless isNameNeeded() is false.
|
inline |
Print onto the stream supplied at construction the value corresponding to a null element with the specified name, preceded, if necessary, by a comma. The behavior is undefined unless isNameNeeded() is true.
| int baljsn::SimpleFormatter::addValue | ( | const bsl::string_view & | name, |
| const TYPE & | value | ||
| ) |
Print onto the stream supplied at construction the specified name and the specified value, preceded, if necessary, by a comma, passing the optionally specified options through to the rendering routines. Return 0 on success and a non-zero value otherwise. The behavior is undefined unless isNameNeeded() is true.
| int baljsn::SimpleFormatter::addValue | ( | const TYPE & | value | ) |
Print onto the stream supplied at construction the specified value, preceded, if necessary, by a comma, passing the optionally specified options through to the rendering routines. Return 0 on success and a non-zero value otherwise. The behavior is undefined unless isNameNeeded() is false.
|
inline |
Return the allocator used by this object to supply memory. Note that if no allocator was supplied at construction the currently installed default allocator is used.
| baljsn::SimpleFormatter::BSLMF_NESTED_TRAIT_DECLARATION | ( | SimpleFormatter | , |
| bslma::UsesBslmaAllocator | |||
| ) |
| void baljsn::SimpleFormatter::closeArray | ( | ArrayFormattingStyle | formattingStyle = e_REGULAR_ARRAY_FORMAT | ) |
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 formattingStyle denoting if the array being closed should be formatted as an empty array. If formattingStyle is not specified then the array being closed is formatted as a regular array having elements. The behavior is undefined if isFormattingArray() is false. Note that the formatting (and as a consequence the formattingStyle) is relevant only if this formatter encodes in the pretty style and is ignored otherwise.
| void baljsn::SimpleFormatter::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). The behavior is undefined unless isNameNeeded() is true.
|
inline |
Return true if this SimpleFormatter has formatted a complete JSON object, where all open* calls have been balanced by their corresponding close* calls. Note that a default-constructed SimpleFormatter will return false - an empty string is not valid JSON.
|
inline |
Return true if this SimpleFormatter is currently formatting an array and false otherwise. It is formatting an array if the last open* method overload (openArray or openObject) called on this SimpleFormatter for which the corresponding close* method (respectively, closeArray or closeObject) was openArray. If isFormattingArray() is true, then isFormattingObject() is false. Note that both can be false, at the top-level initial scope before anything is added/opened or after the first open* call has been closed'
|
inline |
Return true if this SimpleFormatter is currently formatting an object scope and false otherwise. It is formatting an object scope if the last open* method overload (openArray or openObject) called on this SimpleFormatter for which the corresponding close* method (respectively, closeArray or closeObject) was openObject. If isFormattingObject() is true, then isFormattingArray() is false. Note that both can be false, at the top-level initial scope before anything is added/opened or after the first open* call has been closed' JSON.
|
inline |
Return true if a subsequent attempt to add a value must supply a name, and false otherwise. This will be true if isFormattingObject() is true, and addMemberName() was not the most recently called manipulator. That is, a name is needed if this formatter is currently in the context of formatting the members of a JSON object, and addMemberName has not been called to explicitly provide a name for the next member.
| void baljsn::SimpleFormatter::openArray | ( | ArrayFormattingStyle | formattingStyle = e_REGULAR_ARRAY_FORMAT | ) |
Print onto the stream supplied at construction the sequence of characters designating the start of an array (referred to as an "array" in JSON), preceded, if necessary, by a comma. Optionally specify formattingStyle denoting if the array being opened should be formatted as an empty array. If formattingStyle is not specified then the array being opened is formatted as a regular array having elements. The behavior is undefined unless isNameNeeded() is false. Note that the formatting (and as a consequence the formattingStyle) is relevant only if this formatter encodes in the pretty style and is ignored otherwise.
| void baljsn::SimpleFormatter::openArray | ( | const bsl::string_view & | name, |
| ArrayFormattingStyle | formattingStyle = e_REGULAR_ARRAY_FORMAT |
||
| ) |
Print onto the stream supplied at construction the sequence of characters designating the start of an array (referred to as an "array" in JSON) with the specified name, preceded, if necessary, by a comma. Optionally specify formattingStyle denoting if the array being opened should be formatted as an empty array. If formattingStyle is not specified then the array being opened is formatted as a regular array having elements. The behavior is undefined unless isNameNeeded() is true. Note that the formatting (and as a consequence the formattingStyle) is relevant only if this formatter encodes in the pretty style and is ignored otherwise.
| void baljsn::SimpleFormatter::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), preceded, if necessary, by a comma. The behavior is undefined unless isNameNeeded() is false.
| void baljsn::SimpleFormatter::openObject | ( | const bsl::string_view & | name | ) |
Print onto the stream supplied at construction the sequence of characters designating the start of an object (referred to as an "object" in JSON) with the specified name , preceded, if necessary, by a comma. The behavior is undefined unless isNameNeeded() is true.