Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags > Class Template Reference#
JSON writer. More...
#include <writer.h>
Classes | |
struct | Level |
Information for each nested level. More... | |
Public Types | |
typedef SourceEncoding::Ch | Ch |
Public Member Functions | |
Writer (OutputStream &os, StackAllocator *stackAllocator=0, size_t levelDepth=kDefaultLevelDepth) | |
Constructor. More... | |
Writer (StackAllocator *allocator=0, size_t levelDepth=kDefaultLevelDepth) | |
void | Reset (OutputStream &os) |
Reset the writer with a new stream. More... | |
bool | IsComplete () const |
Checks whether the output is a complete JSON. More... | |
int | GetMaxDecimalPlaces () const |
void | SetMaxDecimalPlaces (int maxDecimalPlaces) |
Sets the maximum number of decimal places for double output. More... | |
Implementation of Handler | |
| |
bool | Null () |
Writes the given double value to the stream. More... | |
bool | Bool (bool b) |
Writes the given double value to the stream. More... | |
bool | Int (int i) |
Writes the given double value to the stream. More... | |
bool | Uint (unsigned u) |
Writes the given double value to the stream. More... | |
bool | Int64 (int64_t i64) |
Writes the given double value to the stream. More... | |
bool | Uint64 (uint64_t u64) |
Writes the given double value to the stream. More... | |
bool | Double (double d) |
Writes the given double value to the stream. More... | |
bool | RawNumber (const Ch *str, SizeType length, bool copy=false) |
Writes the given double value to the stream. More... | |
bool | String (const Ch *str, SizeType length, bool copy=false) |
Writes the given double value to the stream. More... | |
bool | StartObject () |
Writes the given double value to the stream. More... | |
bool | Key (const Ch *str, SizeType length, bool copy=false) |
Writes the given double value to the stream. More... | |
bool | EndObject (SizeType memberCount=0) |
Writes the given double value to the stream. More... | |
bool | StartArray () |
Writes the given double value to the stream. More... | |
bool | EndArray (SizeType elementCount=0) |
Writes the given double value to the stream. More... | |
Static Public Attributes | |
static const int | kDefaultMaxDecimalPlaces = 324 |
Protected Member Functions | |
bool | WriteInt (int i) |
bool | WriteUint (unsigned u) |
bool | WriteInt64 (int64_t i64) |
bool | WriteUint64 (uint64_t u) |
bool | WriteDouble (double d) |
Convenience extensions | |
static const size_t | kDefaultLevelDepth = 32 |
Simpler but slower overload. More... | |
OutputStream * | os_ |
Simpler but slower overload. More... | |
internal::Stack< StackAllocator > | level_stack_ |
Simpler but slower overload. More... | |
int | maxDecimalPlaces_ |
Simpler but slower overload. More... | |
bool | hasRoot_ |
Simpler but slower overload. More... | |
bool | String (const Ch *const &str) |
Simpler but slower overload. More... | |
bool | Key (const Ch *const &str) |
Simpler but slower overload. More... | |
bool | RawValue (const Ch *json, size_t length, Type type) |
Write a raw JSON value. More... | |
void | Flush () |
Flush the output stream. More... | |
bool | WriteNull () |
Simpler but slower overload. More... | |
bool | WriteBool (bool b) |
Simpler but slower overload. More... | |
bool | WriteInt (int i) |
Simpler but slower overload. More... | |
bool | WriteUint (unsigned u) |
Simpler but slower overload. More... | |
bool | WriteInt64 (int64_t i64) |
Simpler but slower overload. More... | |
bool | WriteUint64 (uint64_t u64) |
Simpler but slower overload. More... | |
bool | WriteDouble (double d) |
Simpler but slower overload. More... | |
bool | WriteString (const Ch *str, SizeType length) |
Simpler but slower overload. More... | |
bool | ScanWriteUnescapedString (GenericStringStream< SourceEncoding > &is, size_t length) |
Simpler but slower overload. More... | |
bool | WriteStartObject () |
Simpler but slower overload. More... | |
bool | WriteEndObject () |
Simpler but slower overload. More... | |
bool | WriteStartArray () |
Simpler but slower overload. More... | |
bool | WriteEndArray () |
Simpler but slower overload. More... | |
bool | WriteRawValue (const Ch *json, size_t length) |
Simpler but slower overload. More... | |
void | Prefix (Type type) |
Simpler but slower overload. More... | |
bool | EndValue (bool ret) |
Simpler but slower overload. More... | |
Detailed Description
template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
class Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >
JSON writer.
Writer implements the concept Handler. It generates JSON text by events to an output os.
User may programmatically calls the functions of a writer to generate JSON text.
On the other side, a writer can also be passed to objects that generates events,
for example Reader::Parse() and Document::Accept().
- Template Parameters
-
OutputStream Type of output stream. SourceEncoding Encoding of source string. TargetEncoding Encoding of output stream. StackAllocator Type of allocator for allocating memory of stack.
- Note
- implements Handler concept
Member Typedef Documentation
◆ Ch
typedef SourceEncoding::Ch Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Ch |
Constructor & Destructor Documentation
◆ Writer() [1/2]
|
inlineexplicit |
Constructor.
- Parameters
-
os Output stream. stackAllocator User supplied allocator. If it is null, it will create a private one. levelDepth Initial capacity of stack.
◆ Writer() [2/2]
|
inlineexplicit |
Member Function Documentation
◆ Bool()
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ Double()
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ EndArray()
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ EndObject()
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ EndValue()
|
inlineprotected |
Simpler but slower overload.
◆ Flush()
|
inline |
Flush the output stream.
Allows the user to flush the output stream immediately.
◆ GetMaxDecimalPlaces()
|
inline |
◆ Int()
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ Int64()
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ IsComplete()
|
inline |
Checks whether the output is a complete JSON.
A complete JSON has a complete root object or array.
◆ Key() [1/2]
|
inline |
Simpler but slower overload.
◆ Key() [2/2]
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ Null()
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ Prefix()
|
inlineprotected |
Simpler but slower overload.
◆ RawNumber()
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ RawValue()
|
inline |
Write a raw JSON value.
For user to write a stringified JSON as a value.
- Parameters
-
json A well-formed JSON value. It should not contain null character within [0, length - 1] range. length Length of the json. type Type of the root of json.
◆ Reset()
|
inline |
Reset the writer with a new stream.
This function reset the writer with a new stream and default settings, in order to make a Writer object reusable for output multiple JSONs.
- Parameters
-
os New output stream. Writer<OutputStream> writer(os1);writer.StartObject();// ...writer.EndObject();writer.Reset(os2);writer.StartObject();// ...writer.EndObject();
◆ ScanWriteUnescapedString()
|
inlineprotected |
Simpler but slower overload.
◆ SetMaxDecimalPlaces()
|
inline |
Sets the maximum number of decimal places for double output.
This setting truncates the output with specified number of decimal places.
For example,
The default setting does not truncate any decimal places. You can restore to this setting by calling
◆ StartArray()
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ StartObject()
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ String() [1/2]
|
inline |
Simpler but slower overload.
◆ String() [2/2]
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ Uint()
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ Uint64()
|
inline |
Writes the given double
value to the stream.
- Parameters
-
d The value to be written.
- Returns
- Whether it is succeed.
◆ WriteBool()
|
inlineprotected |
Simpler but slower overload.
◆ WriteDouble() [1/2]
|
inlineprotected |
Simpler but slower overload.
◆ WriteDouble() [2/2]
|
inlineprotected |
◆ WriteEndArray()
|
inlineprotected |
Simpler but slower overload.
◆ WriteEndObject()
|
inlineprotected |
Simpler but slower overload.
◆ WriteInt() [1/2]
|
inlineprotected |
Simpler but slower overload.
◆ WriteInt() [2/2]
|
inlineprotected |
◆ WriteInt64() [1/2]
|
inlineprotected |
Simpler but slower overload.
◆ WriteInt64() [2/2]
|
inlineprotected |
◆ WriteNull()
|
inlineprotected |
Simpler but slower overload.
◆ WriteRawValue()
|
inlineprotected |
Simpler but slower overload.
◆ WriteStartArray()
|
inlineprotected |
Simpler but slower overload.
◆ WriteStartObject()
|
inlineprotected |
Simpler but slower overload.
◆ WriteString()
|
inlineprotected |
Simpler but slower overload.
◆ WriteUint() [1/2]
|
inlineprotected |
Simpler but slower overload.
◆ WriteUint() [2/2]
|
inlineprotected |
◆ WriteUint64() [1/2]
|
inlineprotected |
◆ WriteUint64() [2/2]
|
inlineprotected |
Simpler but slower overload.
Member Data Documentation
◆ hasRoot_
|
protected |
Simpler but slower overload.
◆ kDefaultLevelDepth
|
static |
Simpler but slower overload.
◆ kDefaultMaxDecimalPlaces
|
static |
◆ level_stack_
|
protected |
Simpler but slower overload.
◆ maxDecimalPlaces_
|
protected |
Simpler but slower overload.
◆ os_
|
protected |
Simpler but slower overload.
The documentation for this class was generated from the following files: