NGL
6.5
The NCCA Graphics Library
|
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... | |
Implementation of Handler | |
| |
bool | Null () |
bool | Bool (bool b) |
bool | Int (int i) |
bool | Uint (unsigned u) |
bool | Int64 (int64_t i64) |
bool | Uint64 (uint64_t u64) |
bool | Double (double d) |
Writes the given double value to the stream. More... | |
bool | String (const Ch *str, SizeType length, bool copy=false) |
bool | StartObject () |
bool | Key (const Ch *str, SizeType length, bool copy=false) |
bool | EndObject (SizeType memberCount=0) |
bool | StartArray () |
bool | EndArray (SizeType elementCount=0) |
Convenience extensions | |
bool | String (const Ch *str) |
Simpler but slower overload. More... | |
bool | Key (const Ch *str) |
Protected Member Functions | |
bool | WriteNull () |
bool | WriteBool (bool b) |
bool | WriteInt (int i) |
bool | WriteUint (unsigned u) |
bool | WriteInt64 (int64_t i64) |
bool | WriteUint64 (uint64_t u64) |
bool | WriteDouble (double d) |
bool | WriteString (const Ch *str, SizeType length) |
bool | WriteStartObject () |
bool | WriteEndObject () |
bool | WriteStartArray () |
bool | WriteEndArray () |
void | Prefix (Type type) |
template<> | |
bool | WriteInt (int i) |
template<> | |
bool | WriteUint (unsigned u) |
template<> | |
bool | WriteInt64 (int64_t i64) |
template<> | |
bool | WriteUint64 (uint64_t u) |
template<> | |
bool | WriteDouble (double d) |
Protected Attributes | |
OutputStream * | os_ |
internal::Stack< StackAllocator > | level_stack_ |
bool | hasRoot_ |
Static Protected Attributes | |
static const size_t | kDefaultLevelDepth = 32 |
Private Member Functions | |
Writer (const Writer &) | |
Writer & | operator= (const Writer &) |
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().
OutputStream | Type of output stream. |
SourceEncoding | Encoding of source string. |
TargetEncoding | Encoding of output stream. |
StackAllocator | Type of allocator for allocating memory of stack. |
|
inlineexplicit |
|
inlineexplicit |
|
private |
|
inline |
Definition at line 109 of file writer.h.
References kFalseType, kTrueType, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Prefix(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteBool().
|
inline |
Writes the given double
value to the stream.
d | The value to be written. |
Definition at line 120 of file writer.h.
References kNumberType, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Prefix(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteDouble().
|
inline |
Definition at line 159 of file writer.h.
References internal::Stack< Allocator >::Empty(), internal::Stack< Allocator >::GetSize(), Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::level_stack_, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, RAPIDJSON_ASSERT, void(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteEndArray().
|
inline |
Definition at line 142 of file writer.h.
References internal::Stack< Allocator >::Empty(), internal::Stack< Allocator >::GetSize(), Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::level_stack_, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, RAPIDJSON_ASSERT, void(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteEndObject().
|
inline |
Definition at line 110 of file writer.h.
References kNumberType, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Prefix(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteInt().
|
inline |
Definition at line 112 of file writer.h.
References kNumberType, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Prefix(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteInt64().
|
inline |
Checks whether the output is a complete JSON.
A complete JSON has a complete root object or array.
Definition at line 99 of file writer.h.
References internal::Stack< Allocator >::Empty(), Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::hasRoot_, and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::level_stack_.
|
inline |
Definition at line 140 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::String().
|
inline |
Definition at line 176 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Key(), and internal::StrLen().
|
inline |
Definition at line 108 of file writer.h.
References kNullType, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Prefix(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteNull().
|
private |
|
inlineprotected |
Definition at line 317 of file writer.h.
References internal::Stack< Allocator >::GetSize(), Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::hasRoot_, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Level::inArray, kStringType, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::level_stack_, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, RAPIDJSON_ASSERT, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Level::valueCount, and void().
|
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.
os | New output stream. Writer<OutputStream> writer(os1); writer.StartObject(); // ... writer.EndObject(); writer.Reset(os2); writer.StartObject(); // ... writer.EndObject(); |
Definition at line 89 of file writer.h.
References internal::Stack< Allocator >::Clear(), Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::hasRoot_, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::level_stack_, and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.
|
inline |
Definition at line 153 of file writer.h.
References kArrayType, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::level_stack_, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Prefix(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteStartArray().
|
inline |
Definition at line 134 of file writer.h.
References kObjectType, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::level_stack_, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Prefix(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteStartObject().
|
inline |
Definition at line 122 of file writer.h.
References kStringType, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Prefix(), SizeType, void(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteString().
|
inline |
Simpler but slower overload.
Definition at line 175 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::String(), and internal::StrLen().
|
inline |
Definition at line 111 of file writer.h.
References kNumberType, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Prefix(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteUint().
|
inline |
Definition at line 113 of file writer.h.
References kNumberType, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Prefix(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteUint64().
|
inlineprotected |
Definition at line 194 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.
|
inlineprotected |
Definition at line 236 of file writer.h.
References internal::dtoa(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.
|
inlineprotected |
Definition at line 382 of file writer.h.
References internal::dtoa(), Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, and RAPIDJSON_NAMESPACE_END.
|
inlineprotected |
Definition at line 315 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.
|
inlineprotected |
Definition at line 313 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.
|
inlineprotected |
Definition at line 204 of file writer.h.
References internal::i32toa(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.
|
inlineprotected |
Definition at line 350 of file writer.h.
References internal::i32toa(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.
|
inlineprotected |
Definition at line 220 of file writer.h.
References internal::i64toa(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.
|
inlineprotected |
Definition at line 366 of file writer.h.
References internal::i64toa(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.
|
inlineprotected |
Definition at line 190 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.
|
inlineprotected |
Definition at line 314 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.
|
inlineprotected |
Definition at line 312 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.
|
inlineprotected |
Definition at line 244 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, GenericStringStream< Encoding >::Peek(), RAPIDJSON_ASSERT, GenericStringStream< Encoding >::Take(), GenericStringStream< Encoding >::Tell(), and Z16.
|
inlineprotected |
Definition at line 212 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, and internal::u32toa().
|
inlineprotected |
Definition at line 358 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, and internal::u32toa().
|
inlineprotected |
Definition at line 228 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, and internal::u64toa().
|
inlineprotected |
Definition at line 374 of file writer.h.
References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, and internal::u64toa().
|
protected |
|
staticprotected |
|
protected |
|
protected |