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).
Declared in <baljsn_simpleformatter.h>
class SimpleFormatter;
This class has an interface that's easier to use than that of baljsn::Formatter, and generates more correctly-formatted pretty output.
| Name | Description |
|---|---|
ArrayFormattingStyle | This enum lists all possible array formatting styles. |
| Name | Description |
|---|---|
SimpleFormatter [constructor] | Constructors |
~SimpleFormatter [destructor] | Destroy this object. Note that correct JSON has been generated if the isCompleteJSON() call returns true. |
addMemberName | 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. |
addNullValue | addNullValue overloads |
addValue | addValue overloads |
allocator | 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. |
closeArray | 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. |
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. |
isCompleteJSON | 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. |
isFormattingArray | 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' |
isFormattingObject | 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. |
isNameNeeded | 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. |
openArray | openArray overloads |
openObject | openObject overloads |
operator BloombergLP::bslmf::NestedTraitDeclaration<SimpleFormatter, UsesBslmaAllocator> | SimpleFormatter uses a bslma allocator. |