TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator > Class Template Reference

Writer with indentation and spacing. More...

#include <prettywriter.h>

Public Types

typedef Writer< OutputStream,
SourceEncoding, TargetEncoding,
StackAllocator > 
Base
 
typedef Base::Ch Ch
 
- Public Types inherited from Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >
typedef SourceEncoding::Ch Ch
 

Public Member Functions

 PrettyWriter (OutputStream &os, StackAllocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth)
 Constructor. More...
 
PrettyWriterSetIndent (Ch indentChar, unsigned indentCharCount)
 Set custom indentation. 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)
 
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 memberCount=0)
 
Convenience extensions
bool String (const Ch *str)
 Simpler but slower overload. More...
 
bool Key (const Ch *str)
 
- Public Member Functions inherited from Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >
 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...
 
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)
 
bool String (const Ch *str)
 Simpler but slower overload. More...
 
bool Key (const Ch *str)
 

Protected Member Functions

void PrettyPrefix (Type type)
 
void WriteIndent ()
 
- Protected Member Functions inherited from Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >
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

Ch indentChar_
 
unsigned indentCharCount_
 
- Protected Attributes inherited from Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >
OutputStream * os_
 
internal::Stack< StackAllocator > level_stack_
 
bool hasRoot_
 

Private Member Functions

 PrettyWriter (const PrettyWriter &)
 
PrettyWriteroperator= (const PrettyWriter &)
 

Additional Inherited Members

- Static Protected Attributes inherited from Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >
static const size_t kDefaultLevelDepth = 32
 

Detailed Description

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

Writer with indentation and spacing.

Template Parameters
OutputStreamType of ouptut os.
SourceEncodingEncoding of source string.
TargetEncodingEncoding of output stream.
StackAllocatorType of allocator for allocating memory of stack.

Member Typedef Documentation

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

Constructor & Destructor Documentation

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::PrettyWriter ( OutputStream &  os,
StackAllocator *  allocator = 0,
size_t  levelDepth = Base::kDefaultLevelDepth 
)
inline

Constructor.

Parameters
osOutput stream.
allocatorUser supplied allocator. If it is null, it will create a private one.
levelDepthInitial capacity of stack.
45  :
46  Base(os, allocator, levelDepth), indentChar_(' '), indentCharCount_(4) {}
Ch indentChar_
Definition: prettywriter.h:192
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator > Base
Definition: prettywriter.h:37
unsigned indentCharCount_
Definition: prettywriter.h:193
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::PrettyWriter ( const PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator > &  )
private

Member Function Documentation

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Bool ( bool  b)
inline
66 { PrettyPrefix(b ? kTrueType : kFalseType); return Base::WriteBool(b); }
false
Definition: rapidjson.h:644
bool WriteBool(bool b)
Definition: writer.h:194
void PrettyPrefix(Type type)
Definition: prettywriter.h:146
true
Definition: rapidjson.h:645

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Double ( double  d)
inline
bool WriteDouble(double d)
Definition: writer.h:236
number
Definition: rapidjson.h:649
void PrettyPrefix(Type type)
Definition: prettywriter.h:146

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::EndArray ( SizeType  memberCount = 0)
inline
117  {
118  (void)memberCount;
119  RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level));
120  RAPIDJSON_ASSERT(Base::level_stack_.template Top<typename Base::Level>()->inArray);
121  bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
122 
123  if (!empty) {
124  Base::os_->Put('\n');
125  WriteIndent();
126  }
127  bool ret = Base::WriteEndArray();
128  (void)ret;
129  RAPIDJSON_ASSERT(ret == true);
130  if (Base::level_stack_.Empty()) // end of json text
131  Base::os_->Flush();
132  return true;
133  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
bool WriteEndArray()
Definition: writer.h:315
void WriteIndent()
Definition: prettywriter.h:187
OutputStream * os_
Definition: writer.h:337

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::EndObject ( SizeType  memberCount = 0)
inline
93  {
94  (void)memberCount;
95  RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level));
96  RAPIDJSON_ASSERT(!Base::level_stack_.template Top<typename Base::Level>()->inArray);
97  bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
98 
99  if (!empty) {
100  Base::os_->Put('\n');
101  WriteIndent();
102  }
103  bool ret = Base::WriteEndObject();
104  (void)ret;
105  RAPIDJSON_ASSERT(ret == true);
106  if (Base::level_stack_.Empty()) // end of json text
107  Base::os_->Flush();
108  return true;
109  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
void WriteIndent()
Definition: prettywriter.h:187
bool WriteEndObject()
Definition: writer.h:313
OutputStream * os_
Definition: writer.h:337

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Int ( int  i)
inline
bool WriteInt(int i)
Definition: writer.h:204
number
Definition: rapidjson.h:649
void PrettyPrefix(Type type)
Definition: prettywriter.h:146

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Int64 ( int64_t  i64)
inline
69 { PrettyPrefix(kNumberType); return Base::WriteInt64(i64); }
number
Definition: rapidjson.h:649
void PrettyPrefix(Type type)
Definition: prettywriter.h:146
bool WriteInt64(int64_t i64)
Definition: writer.h:220

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Key ( const Ch str,
SizeType  length,
bool  copy = false 
)
inline
91 { return String(str, length, copy); }
bool String(const Ch *str, SizeType length, bool copy=false)
Definition: prettywriter.h:73
float length(float v)
Definition: vectorMath.h:208

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Key ( const Ch str)
inline
142 { return Key(str, internal::StrLen(str)); }
bool Key(const Ch *str, SizeType length, bool copy=false)
Definition: prettywriter.h:91
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:30

+ 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 PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Null ( )
inline
void PrettyPrefix(Type type)
Definition: prettywriter.h:146
bool WriteNull()
Definition: writer.h:190
null
Definition: rapidjson.h:643

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
PrettyWriter& PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::operator= ( const PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator > &  )
private
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
void PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::PrettyPrefix ( Type  type)
inlineprotected
146  {
147  (void)type;
148  if (Base::level_stack_.GetSize() != 0) { // this value is not at root
149  typename Base::Level* level = Base::level_stack_.template Top<typename Base::Level>();
150 
151  if (level->inArray) {
152  if (level->valueCount > 0) {
153  Base::os_->Put(','); // add comma if it is not the first element in array
154  Base::os_->Put('\n');
155  }
156  else
157  Base::os_->Put('\n');
158  WriteIndent();
159  }
160  else { // in object
161  if (level->valueCount > 0) {
162  if (level->valueCount % 2 == 0) {
163  Base::os_->Put(',');
164  Base::os_->Put('\n');
165  }
166  else {
167  Base::os_->Put(':');
168  Base::os_->Put(' ');
169  }
170  }
171  else
172  Base::os_->Put('\n');
173 
174  if (level->valueCount % 2 == 0)
175  WriteIndent();
176  }
177  if (!level->inArray && level->valueCount % 2 == 0)
178  RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
179  level->valueCount++;
180  }
181  else {
182  RAPIDJSON_ASSERT(!Base::hasRoot_); // Should only has one and only one root.
183  Base::hasRoot_ = true;
184  }
185  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
void WriteIndent()
Definition: prettywriter.h:187
string
Definition: rapidjson.h:648
bool hasRoot_
Definition: writer.h:339
OutputStream * os_
Definition: writer.h:337

+ 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>
PrettyWriter& PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::SetIndent ( Ch  indentChar,
unsigned  indentCharCount 
)
inline

Set custom indentation.

Parameters
indentCharCharacter for indentation. Must be whitespace character (' ', '\t', '\n', '\r').
indentCharCountNumber of indent characters for each indentation level.
Note
The default indentation is 4 spaces.
53  {
54  RAPIDJSON_ASSERT(indentChar == ' ' || indentChar == '\t' || indentChar == '\n' || indentChar == '\r');
55  indentChar_ = indentChar;
56  indentCharCount_ = indentCharCount;
57  return *this;
58  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
Ch indentChar_
Definition: prettywriter.h:192
unsigned indentCharCount_
Definition: prettywriter.h:193
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::StartArray ( )
inline
111  {
113  new (Base::level_stack_.template Push<typename Base::Level>()) typename Base::Level(true);
114  return Base::WriteStartArray();
115  }
array
Definition: rapidjson.h:647
bool WriteStartArray()
Definition: writer.h:314
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
void PrettyPrefix(Type type)
Definition: prettywriter.h:146

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::StartObject ( )
inline
85  {
87  new (Base::level_stack_.template Push<typename Base::Level>()) typename Base::Level(false);
88  return Base::WriteStartObject();
89  }
object
Definition: rapidjson.h:646
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
bool WriteStartObject()
Definition: writer.h:312
void PrettyPrefix(Type type)
Definition: prettywriter.h:146

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::String ( const Ch str,
SizeType  length,
bool  copy = false 
)
inline
73  {
74  (void)copy;
76  return Base::WriteString(str, length);
77  }
string
Definition: rapidjson.h:648
bool WriteString(const Ch *str, SizeType length)
Definition: writer.h:244
void PrettyPrefix(Type type)
Definition: prettywriter.h:146
float length(float v)
Definition: vectorMath.h:208

+ 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 PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::String ( const Ch str)
inline

Simpler but slower overload.

141 { return String(str, internal::StrLen(str)); }
bool String(const Ch *str, SizeType length, bool copy=false)
Definition: prettywriter.h:73
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:30

+ 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 PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Uint ( unsigned  u)
inline
number
Definition: rapidjson.h:649
void PrettyPrefix(Type type)
Definition: prettywriter.h:146
bool WriteUint(unsigned u)
Definition: writer.h:212

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Uint64 ( uint64_t  u64)
inline
number
Definition: rapidjson.h:649
void PrettyPrefix(Type type)
Definition: prettywriter.h:146
bool WriteUint64(uint64_t u64)
Definition: writer.h:228

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
void PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteIndent ( )
inlineprotected
187  {
188  size_t count = (Base::level_stack_.GetSize() / sizeof(typename Base::Level)) * indentCharCount_;
189  PutN(*Base::os_, indentChar_, count);
190  }
void PutN(FileWriteStream &stream, char c, size_t n)
Implement specialized version of PutN() with memset() for better performance.
Definition: filewritestream.h:85
Ch indentChar_
Definition: prettywriter.h:192
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
size_t GetSize() const
Definition: stack.h:129
OutputStream * os_
Definition: writer.h:337
unsigned indentCharCount_
Definition: prettywriter.h:193

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
Ch PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::indentChar_
protected
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
unsigned PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::indentCharCount_
protected

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