NGL  6.5
The NCCA Graphics Library
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator > Class Template Reference

JSON writer. More...

#include <writer.h>

+ Inheritance diagram for Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >:
+ Collaboration diagram for Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >:

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
See also
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 &)
 
Writeroperator= (const Writer &)
 

Detailed Description

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
class Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >

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
OutputStreamType of output stream.
SourceEncodingEncoding of source string.
TargetEncodingEncoding of output stream.
StackAllocatorType of allocator for allocating memory of stack.
Note
implements Handler concept

Definition at line 54 of file writer.h.

Member Typedef Documentation

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
typedef SourceEncoding::Ch Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Ch

Definition at line 56 of file writer.h.

Constructor & Destructor Documentation

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Writer ( OutputStream &  os,
StackAllocator *  stackAllocator = 0,
size_t  levelDepth = kDefaultLevelDepth 
)
inlineexplicit

Constructor.

Parameters
osOutput stream.
stackAllocatorUser supplied allocator. If it is null, it will create a private one.
levelDepthInitial capacity of stack.

Definition at line 64 of file writer.h.

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Writer ( StackAllocator *  allocator = 0,
size_t  levelDepth = kDefaultLevelDepth 
)
inlineexplicit

Definition at line 68 of file writer.h.

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Writer ( const Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator > &  )
private

Member Function Documentation

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Bool ( bool  b)
inline
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Double ( double  d)
inline

Writes the given double value to the stream.

Parameters
dThe value to be written.
Returns
Whether it is succeed.

Definition at line 120 of file writer.h.

References kNumberType, Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Prefix(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteDouble().

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::EndArray ( SizeType  elementCount = 0)
inline
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::EndObject ( SizeType  memberCount = 0)
inline
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Int ( int  i)
inline
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Int64 ( int64_t  i64)
inline
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::IsComplete ( ) const
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_.

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Key ( const Ch str,
SizeType  length,
bool  copy = false 
)
inline

Definition at line 140 of file writer.h.

References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::String().

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Key ( const Ch str)
inline

Definition at line 176 of file writer.h.

References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Key(), and internal::StrLen().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Null ( )
inline
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
Writer& Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::operator= ( const Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator > &  )
private
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
void Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Prefix ( Type  type)
inlineprotected
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
void Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Reset ( OutputStream &  os)
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
osNew output stream.
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_.

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::StartArray ( )
inline
template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::StartObject ( )
inline
template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::String ( const Ch str,
SizeType  length,
bool  copy = false 
)
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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::String ( const Ch str)
inline

Simpler but slower overload.

Definition at line 175 of file writer.h.

References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::String(), and internal::StrLen().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Uint ( unsigned  u)
inline
template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Uint64 ( uint64_t  u64)
inline
template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteBool ( bool  b)
inlineprotected

Definition at line 194 of file writer.h.

References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteDouble ( double  d)
inlineprotected

Definition at line 236 of file writer.h.

References internal::dtoa(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<>
bool Writer< StringBuffer >::WriteDouble ( double  d)
inlineprotected

Definition at line 382 of file writer.h.

References internal::dtoa(), Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, and RAPIDJSON_NAMESPACE_END.

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteEndArray ( )
inlineprotected

Definition at line 315 of file writer.h.

References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteEndObject ( )
inlineprotected

Definition at line 313 of file writer.h.

References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteInt ( int  i)
inlineprotected

Definition at line 204 of file writer.h.

References internal::i32toa(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<>
bool Writer< StringBuffer >::WriteInt ( int  i)
inlineprotected

Definition at line 350 of file writer.h.

References internal::i32toa(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteInt64 ( int64_t  i64)
inlineprotected

Definition at line 220 of file writer.h.

References internal::i64toa(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<>
bool Writer< StringBuffer >::WriteInt64 ( int64_t  i64)
inlineprotected

Definition at line 366 of file writer.h.

References internal::i64toa(), and Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteNull ( )
inlineprotected

Definition at line 190 of file writer.h.

References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteStartArray ( )
inlineprotected

Definition at line 314 of file writer.h.

References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteStartObject ( )
inlineprotected

Definition at line 312 of file writer.h.

References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_.

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteString ( const Ch str,
SizeType  length 
)
inlineprotected
template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteUint ( unsigned  u)
inlineprotected

Definition at line 212 of file writer.h.

References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, and internal::u32toa().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<>
bool Writer< StringBuffer >::WriteUint ( unsigned  u)
inlineprotected

Definition at line 358 of file writer.h.

References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, and internal::u32toa().

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteUint64 ( uint64_t  u64)
inlineprotected

Definition at line 228 of file writer.h.

References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, and internal::u64toa().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<>
bool Writer< StringBuffer >::WriteUint64 ( uint64_t  u)
inlineprotected

Definition at line 374 of file writer.h.

References Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_, and internal::u64toa().

+ Here is the call graph for this function:

Member Data Documentation

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::hasRoot_
protected

Definition at line 339 of file writer.h.

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
const size_t Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::kDefaultLevelDepth = 32
staticprotected

Definition at line 188 of file writer.h.

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
internal::Stack<StackAllocator> Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::level_stack_
protected

Definition at line 338 of file writer.h.

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
OutputStream* Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_
protected

Definition at line 337 of file writer.h.


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