IN2OSM  1.0.1
PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >

Writer with indentation and spacing. More...

#include <fwd.h>

Inheritance diagram for PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >:
Inheritance graph
Collaboration diagram for PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >:
Collaboration graph

Public Types

typedef Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags > Base
 
typedef Base::Ch Ch
 

Public Member Functions

 PrettyWriter (OutputStream &os, StackAllocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth)
 Constructor. More...
 
 PrettyWriter (StackAllocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth)
 
PrettyWriterSetIndent (Ch indentChar, unsigned indentCharCount)
 Set custom indentation. More...
 
PrettyWriterSetFormatOptions (PrettyFormatOptions options)
 Set pretty writer formatting options. More...
 
bool RawValue (const Ch *json, size_t length, Type type)
 Write a raw JSON value. More...
 
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...
 
void Flush ()
 Flush the output stream. 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 RawNumber (const Ch *str, SizeType length, bool copy=false)
 
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)
 
Convenience extensions
bool String (const Ch *const &str)
 Simpler but slower overload. More...
 
bool Key (const Ch *const &str)
 

Static Public Attributes

static const int kDefaultMaxDecimalPlaces = 324
 

Protected Member Functions

void PrettyPrefix (Type type)
 
void WriteIndent ()
 
bool WriteNull ()
 
bool WriteBool (bool b)
 
bool WriteInt (int i)
 
template<>
bool WriteInt (int i)
 
bool WriteUint (unsigned u)
 
template<>
bool WriteUint (unsigned u)
 
bool WriteInt64 (int64_t i64)
 
template<>
bool WriteInt64 (int64_t i64)
 
bool WriteUint64 (uint64_t u64)
 
template<>
bool WriteUint64 (uint64_t u)
 
bool WriteDouble (double d)
 
template<>
bool WriteDouble (double d)
 
bool WriteString (const Ch *str, SizeType length)
 
bool ScanWriteUnescapedString (GenericStringStream< SourceEncoding > &is, size_t length)
 
bool WriteStartObject ()
 
bool WriteEndObject ()
 
bool WriteStartArray ()
 
bool WriteEndArray ()
 
bool WriteRawValue (const Ch *json, size_t length)
 
void Prefix (Type type)
 
bool EndValue (bool ret)
 

Protected Attributes

Ch indentChar_
 
unsigned indentCharCount_
 
PrettyFormatOptions formatOptions_
 
OutputStream * os_
 
internal::Stack< StackAllocator > level_stack_
 
int maxDecimalPlaces_
 
bool hasRoot_
 

Static Protected Attributes

static const size_t kDefaultLevelDepth = 32
 

Private Member Functions

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

Detailed Description

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

Writer with indentation and spacing.

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

Definition at line 100 of file fwd.h.

Member Typedef Documentation

◆ Base

typedef Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> Base

Definition at line 50 of file prettywriter.h.

◆ Ch

typedef Base::Ch Ch

Definition at line 51 of file prettywriter.h.

Constructor & Destructor Documentation

◆ PrettyWriter() [1/3]

PrettyWriter ( OutputStream &  os,
StackAllocator *  allocator = 0,
size_t  levelDepth = Base::kDefaultLevelDepth 
)
inlineexplicit

Constructor.

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

Definition at line 58 of file prettywriter.h.

58  :
59  Base(os, allocator, levelDepth), indentChar_(' '), indentCharCount_(4), formatOptions_(kFormatDefault) {}
PrettyFormatOptions formatOptions_
Definition: prettywriter.h:259
unsigned indentCharCount_
Definition: prettywriter.h:258
Default pretty formatting.
Definition: prettywriter.h:36
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags > Base
Definition: prettywriter.h:50
Here is the caller graph for this function:

◆ PrettyWriter() [2/3]

PrettyWriter ( StackAllocator *  allocator = 0,
size_t  levelDepth = Base::kDefaultLevelDepth 
)
inlineexplicit

Definition at line 62 of file prettywriter.h.

62  :
63  Base(allocator, levelDepth), indentChar_(' '), indentCharCount_(4) {}
unsigned indentCharCount_
Definition: prettywriter.h:258
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags > Base
Definition: prettywriter.h:50
Here is the call graph for this function:

◆ PrettyWriter() [3/3]

PrettyWriter ( const PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags > &  )
private

Member Function Documentation

◆ Bool()

bool Bool ( bool  b)
inline

Definition at line 96 of file prettywriter.h.

false
Definition: rapidjson.h:644
bool WriteBool(bool b)
Definition: writer.h:300
void PrettyPrefix(Type type)
Definition: prettywriter.h:208
bool EndValue(bool ret)
Definition: writer.h:493
true
Definition: rapidjson.h:645
Here is the call graph for this function:

◆ Double()

bool Double ( double  d)
inline

Definition at line 101 of file prettywriter.h.

void PrettyPrefix(Type type)
Definition: prettywriter.h:208
number
Definition: rapidjson.h:649
bool EndValue(bool ret)
Definition: writer.h:493
bool WriteDouble(double d)
Definition: writer.h:348
Here is the call graph for this function:

◆ EndArray()

bool EndArray ( SizeType  memberCount = 0)
inline

Definition at line 163 of file prettywriter.h.

163  {
164  (void)memberCount;
165  RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level));
166  RAPIDJSON_ASSERT(Base::level_stack_.template Top<typename Base::Level>()->inArray);
167  bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
168 
169  if (!empty && !(formatOptions_ & kFormatSingleLineArray)) {
170  Base::os_->Put('\n');
171  WriteIndent();
172  }
173  bool ret = Base::EndValue(Base::WriteEndArray());
174  (void)ret;
175  RAPIDJSON_ASSERT(ret == true);
176  if (Base::level_stack_.Empty()) // end of json text
177  Base::Flush();
178  return true;
179  }
PrettyFormatOptions formatOptions_
Definition: prettywriter.h:259
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:500
bool WriteEndArray()
Definition: writer.h:457
OutputStream * os_
Definition: writer.h:499
bool EndValue(bool ret)
Definition: writer.h:493
Format arrays on a single line.
Definition: prettywriter.h:37
void WriteIndent()
Definition: prettywriter.h:252
void Flush()
Flush the output stream.
Definition: writer.h:281
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Here is the call graph for this function:

◆ EndObject()

bool EndObject ( SizeType  memberCount = 0)
inline

Definition at line 137 of file prettywriter.h.

137  {
138  (void)memberCount;
139  RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level)); // not inside an Object
140  RAPIDJSON_ASSERT(!Base::level_stack_.template Top<typename Base::Level>()->inArray); // currently inside an Array, not Object
141  RAPIDJSON_ASSERT(0 == Base::level_stack_.template Top<typename Base::Level>()->valueCount % 2); // Object has a Key without a Value
142 
143  bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
144 
145  if (!empty) {
146  Base::os_->Put('\n');
147  WriteIndent();
148  }
149  bool ret = Base::EndValue(Base::WriteEndObject());
150  (void)ret;
151  RAPIDJSON_ASSERT(ret == true);
152  if (Base::level_stack_.Empty()) // end of json text
153  Base::Flush();
154  return true;
155  }
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:500
OutputStream * os_
Definition: writer.h:499
bool EndValue(bool ret)
Definition: writer.h:493
void WriteIndent()
Definition: prettywriter.h:252
void Flush()
Flush the output stream.
Definition: writer.h:281
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
bool WriteEndObject()
Definition: writer.h:455
Here is the call graph for this function:

◆ EndValue()

bool EndValue ( bool  ret)
inlineprotectedinherited

Definition at line 493 of file writer.h.

493  {
494  if (RAPIDJSON_UNLIKELY(level_stack_.Empty())) // end of json text
495  Flush();
496  return ret;
497  }
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:500
bool Empty() const
Definition: stack.h:176
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:476
void Flush()
Flush the output stream.
Definition: writer.h:281
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Flush()

void Flush ( )
inlineinherited

Flush the output stream.

Allows the user to flush the output stream immediately.

Definition at line 281 of file writer.h.

281  {
282  os_->Flush();
283  }
OutputStream * os_
Definition: writer.h:499
Here is the caller graph for this function:

◆ GetMaxDecimalPlaces()

int GetMaxDecimalPlaces ( ) const
inlineinherited

Definition at line 147 of file writer.h.

147  {
148  return maxDecimalPlaces_;
149  }
int maxDecimalPlaces_
Definition: writer.h:501

◆ Int()

bool Int ( int  i)
inline

Definition at line 97 of file prettywriter.h.

void PrettyPrefix(Type type)
Definition: prettywriter.h:208
number
Definition: rapidjson.h:649
bool EndValue(bool ret)
Definition: writer.h:493
bool WriteInt(int i)
Definition: writer.h:312
Here is the call graph for this function:

◆ Int64()

bool Int64 ( int64_t  i64)
inline

Definition at line 99 of file prettywriter.h.

void PrettyPrefix(Type type)
Definition: prettywriter.h:208
number
Definition: rapidjson.h:649
bool WriteInt64(int64_t i64)
Definition: writer.h:330
bool EndValue(bool ret)
Definition: writer.h:493
Here is the call graph for this function:

◆ IsComplete()

bool IsComplete ( ) const
inlineinherited

Checks whether the output is a complete JSON.

A complete JSON has a complete root object or array.

Definition at line 143 of file writer.h.

143  {
144  return hasRoot_ && level_stack_.Empty();
145  }
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:500
bool Empty() const
Definition: stack.h:176
bool hasRoot_
Definition: writer.h:502
Here is the call graph for this function:

◆ Key() [1/3]

bool Key ( const Ch str,
SizeType  length,
bool  copy = false 
)
inline

Definition at line 129 of file prettywriter.h.

129 { return String(str, length, copy); }
bool String(const Ch *str, SizeType length, bool copy=false)
Definition: prettywriter.h:110
Here is the call graph for this function:

◆ Key() [2/3]

bool Key ( const Ch str)
inline

Definition at line 188 of file prettywriter.h.

188 { return Key(str, internal::StrLen(str)); }
bool Key(const Ch *str, SizeType length, bool copy=false)
Definition: prettywriter.h:129
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:31
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Key() [3/3]

bool Key ( const Ch *const &  str)
inlineinherited

Definition at line 259 of file writer.h.

259 { return Key(str, internal::StrLen(str)); }
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:31
bool Key(const Ch *str, SizeType length, bool copy=false)
Definition: writer.h:221
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Null()

bool Null ( )
inline

Definition at line 95 of file prettywriter.h.

bool WriteNull()
Definition: writer.h:295
void PrettyPrefix(Type type)
Definition: prettywriter.h:208
bool EndValue(bool ret)
Definition: writer.h:493
null
Definition: rapidjson.h:643
Here is the call graph for this function:

◆ operator=()

PrettyWriter& operator= ( const PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags > &  )
private

◆ Prefix()

void Prefix ( Type  type)
inlineprotectedinherited

Definition at line 472 of file writer.h.

472  {
473  (void)type;
474  if (RAPIDJSON_LIKELY(level_stack_.GetSize() != 0)) { // this value is not at root
475  Level* level = level_stack_.template Top<Level>();
476  if (level->valueCount > 0) {
477  if (level->inArray)
478  os_->Put(','); // add comma if it is not the first element in array
479  else // in object
480  os_->Put((level->valueCount % 2 == 0) ? ',' : ':');
481  }
482  if (!level->inArray && level->valueCount % 2 == 0)
483  RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
484  level->valueCount++;
485  }
486  else {
487  RAPIDJSON_ASSERT(!hasRoot_); // Should only has one and only one root.
488  hasRoot_ = true;
489  }
490  }
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:500
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition: rapidjson.h:463
string
Definition: rapidjson.h:648
OutputStream * os_
Definition: writer.h:499
size_t GetSize() const
Definition: stack.h:177
bool hasRoot_
Definition: writer.h:502
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Definition: IMDF_UNIT.h:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrettyPrefix()

void PrettyPrefix ( Type  type)
inlineprotected

Definition at line 208 of file prettywriter.h.

208  {
209  (void)type;
210  if (Base::level_stack_.GetSize() != 0) { // this value is not at root
211  typename Base::Level* level = Base::level_stack_.template Top<typename Base::Level>();
212 
213  if (level->inArray) {
214  if (level->valueCount > 0) {
215  Base::os_->Put(','); // add comma if it is not the first element in array
217  Base::os_->Put(' ');
218  }
219 
220  if (!(formatOptions_ & kFormatSingleLineArray)) {
221  Base::os_->Put('\n');
222  WriteIndent();
223  }
224  }
225  else { // in object
226  if (level->valueCount > 0) {
227  if (level->valueCount % 2 == 0) {
228  Base::os_->Put(',');
229  Base::os_->Put('\n');
230  }
231  else {
232  Base::os_->Put(':');
233  Base::os_->Put(' ');
234  }
235  }
236  else
237  Base::os_->Put('\n');
238 
239  if (level->valueCount % 2 == 0)
240  WriteIndent();
241  }
242  if (!level->inArray && level->valueCount % 2 == 0)
243  RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
244  level->valueCount++;
245  }
246  else {
247  RAPIDJSON_ASSERT(!Base::hasRoot_); // Should only has one and only one root.
248  Base::hasRoot_ = true;
249  }
250  }
PrettyFormatOptions formatOptions_
Definition: prettywriter.h:259
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:500
string
Definition: rapidjson.h:648
OutputStream * os_
Definition: writer.h:499
bool hasRoot_
Definition: writer.h:502
Format arrays on a single line.
Definition: prettywriter.h:37
void WriteIndent()
Definition: prettywriter.h:252
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Definition: IMDF_UNIT.h:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RawNumber()

bool RawNumber ( const Ch str,
SizeType  length,
bool  copy = false 
)
inline

Definition at line 103 of file prettywriter.h.

103  {
104  RAPIDJSON_ASSERT(str != 0);
105  (void)copy;
107  return Base::EndValue(Base::WriteString(str, length));
108  }
bool WriteString(const Ch *str, SizeType length)
Definition: writer.h:376
void PrettyPrefix(Type type)
Definition: prettywriter.h:208
number
Definition: rapidjson.h:649
bool EndValue(bool ret)
Definition: writer.h:493
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Here is the call graph for this function:

◆ RawValue()

bool RawValue ( const Ch json,
size_t  length,
Type  type 
)
inline

Write a raw JSON value.

For user to write a stringified JSON as a value.

Parameters
jsonA well-formed JSON value. It should not contain null character within [0, length - 1] range.
lengthLength of the json.
typeType of the root of json.
Note
When using PrettyWriter::RawValue(), the result json may not be indented correctly.

Definition at line 201 of file prettywriter.h.

201  {
202  RAPIDJSON_ASSERT(json != 0);
203  PrettyPrefix(type);
204  return Base::EndValue(Base::WriteRawValue(json, length));
205  }
void PrettyPrefix(Type type)
Definition: prettywriter.h:208
bool EndValue(bool ret)
Definition: writer.h:493
bool WriteRawValue(const Ch *json, size_t length)
Definition: writer.h:459
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Here is the call graph for this function:

◆ Reset()

void Reset ( OutputStream &  os)
inlineinherited

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 133 of file writer.h.

133  {
134  os_ = &os;
135  hasRoot_ = false;
137  }
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:500
void Clear()
Definition: stack.h:98
OutputStream * os_
Definition: writer.h:499
bool hasRoot_
Definition: writer.h:502
Here is the call graph for this function:

◆ ScanWriteUnescapedString()

bool ScanWriteUnescapedString ( GenericStringStream< SourceEncoding > &  is,
size_t  length 
)
inlineprotectedinherited

Definition at line 450 of file writer.h.

450  {
451  return RAPIDJSON_LIKELY(is.Tell() < length);
452  }
size_t Tell() const
Definition: stream.h:161
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition: rapidjson.h:463
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetFormatOptions()

PrettyWriter& SetFormatOptions ( PrettyFormatOptions  options)
inline

Set pretty writer formatting options.

Parameters
optionsFormatting options.

Definition at line 85 of file prettywriter.h.

85  {
86  formatOptions_ = options;
87  return *this;
88  }
PrettyFormatOptions formatOptions_
Definition: prettywriter.h:259

◆ SetIndent()

PrettyWriter& 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.

Definition at line 75 of file prettywriter.h.

75  {
76  RAPIDJSON_ASSERT(indentChar == ' ' || indentChar == '\t' || indentChar == '\n' || indentChar == '\r');
77  indentChar_ = indentChar;
78  indentCharCount_ = indentCharCount;
79  return *this;
80  }
unsigned indentCharCount_
Definition: prettywriter.h:258
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406

◆ SetMaxDecimalPlaces()

void SetMaxDecimalPlaces ( int  maxDecimalPlaces)
inlineinherited

Sets the maximum number of decimal places for double output.

This setting truncates the output with specified number of decimal places.

For example,

writer.SetMaxDecimalPlaces(3);
writer.StartArray();
writer.Double(0.12345); // "0.123"
writer.Double(0.0001); // "0.0"
writer.Double(1.234567890123456e30); // "1.234567890123456e30" (do not truncate significand for positive exponent)
writer.Double(1.23e-4); // "0.0" (do truncate significand for negative exponent)
writer.EndArray();

The default setting does not truncate any decimal places. You can restore to this setting by calling

writer.SetMaxDecimalPlaces(Writer::kDefaultMaxDecimalPlaces);

Definition at line 172 of file writer.h.

172  {
173  maxDecimalPlaces_ = maxDecimalPlaces;
174  }
int maxDecimalPlaces_
Definition: writer.h:501

◆ StartArray()

bool StartArray ( )
inline

Definition at line 157 of file prettywriter.h.

157  {
159  new (Base::level_stack_.template Push<typename Base::Level>()) typename Base::Level(true);
160  return Base::WriteStartArray();
161  }
array
Definition: rapidjson.h:647
bool WriteStartArray()
Definition: writer.h:456
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:500
void PrettyPrefix(Type type)
Definition: prettywriter.h:208
Here is the call graph for this function:

◆ StartObject()

bool StartObject ( )
inline

Definition at line 123 of file prettywriter.h.

123  {
125  new (Base::level_stack_.template Push<typename Base::Level>()) typename Base::Level(false);
126  return Base::WriteStartObject();
127  }
object
Definition: rapidjson.h:646
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:500
bool WriteStartObject()
Definition: writer.h:454
void PrettyPrefix(Type type)
Definition: prettywriter.h:208
Here is the call graph for this function:

◆ String() [1/3]

bool String ( const Ch str,
SizeType  length,
bool  copy = false 
)
inline

Definition at line 110 of file prettywriter.h.

110  {
111  RAPIDJSON_ASSERT(str != 0);
112  (void)copy;
114  return Base::EndValue(Base::WriteString(str, length));
115  }
string
Definition: rapidjson.h:648
bool WriteString(const Ch *str, SizeType length)
Definition: writer.h:376
void PrettyPrefix(Type type)
Definition: prettywriter.h:208
bool EndValue(bool ret)
Definition: writer.h:493
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Here is the call graph for this function:
Here is the caller graph for this function:

◆ String() [2/3]

bool String ( const Ch str)
inline

Simpler but slower overload.

Definition at line 187 of file prettywriter.h.

187 { return String(str, internal::StrLen(str)); }
bool String(const Ch *str, SizeType length, bool copy=false)
Definition: prettywriter.h:110
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:31
Here is the call graph for this function:
Here is the caller graph for this function:

◆ String() [3/3]

bool String ( const Ch *const &  str)
inlineinherited

Simpler but slower overload.

Definition at line 258 of file writer.h.

258 { return String(str, internal::StrLen(str)); }
bool String(const Ch *str, SizeType length, bool copy=false)
Definition: writer.h:202
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:31
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Uint()

bool Uint ( unsigned  u)
inline

Definition at line 98 of file prettywriter.h.

void PrettyPrefix(Type type)
Definition: prettywriter.h:208
number
Definition: rapidjson.h:649
bool EndValue(bool ret)
Definition: writer.h:493
bool WriteUint(unsigned u)
Definition: writer.h:321
Here is the call graph for this function:

◆ Uint64()

bool Uint64 ( uint64_t  u64)
inline

Definition at line 100 of file prettywriter.h.

bool WriteUint64(uint64_t u64)
Definition: writer.h:339
void PrettyPrefix(Type type)
Definition: prettywriter.h:208
number
Definition: rapidjson.h:649
bool EndValue(bool ret)
Definition: writer.h:493
Here is the call graph for this function:

◆ WriteBool()

bool WriteBool ( bool  b)
inlineprotectedinherited

Definition at line 300 of file writer.h.

300  {
301  if (b) {
302  PutReserve(*os_, 4);
303  PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'r'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'e');
304  }
305  else {
306  PutReserve(*os_, 5);
307  PutUnsafe(*os_, 'f'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 's'); PutUnsafe(*os_, 'e');
308  }
309  return true;
310  }
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition: stream.h:84
OutputStream * os_
Definition: writer.h:499
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition: stream.h:91
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteDouble() [1/2]

bool WriteDouble ( double  d)
inlineprotectedinherited

Definition at line 348 of file writer.h.

348  {
349  if (internal::Double(d).IsNanOrInf()) {
350  if (!(writeFlags & kWriteNanAndInfFlag))
351  return false;
352  if (internal::Double(d).IsNan()) {
353  PutReserve(*os_, 3);
354  PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
355  return true;
356  }
357  if (internal::Double(d).Sign()) {
358  PutReserve(*os_, 9);
359  PutUnsafe(*os_, '-');
360  }
361  else
362  PutReserve(*os_, 8);
363  PutUnsafe(*os_, 'I'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'f');
364  PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y');
365  return true;
366  }
367 
368  char buffer[25];
369  char* end = internal::dtoa(d, buffer, maxDecimalPlaces_);
370  PutReserve(*os_, static_cast<size_t>(end - buffer));
371  for (char* p = buffer; p != end; ++p)
372  PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
373  return true;
374  }
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition: stream.h:84
OutputStream * os_
Definition: writer.h:499
int maxDecimalPlaces_
Definition: writer.h:501
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition: stream.h:91
Allow writing of Infinity, -Infinity and NaN.
Definition: writer.h:68
char * dtoa(double value, char *buffer, int maxDecimalPlaces=324)
Definition: dtoa.h:216
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteDouble() [2/2]

bool WriteDouble ( double  d)
inlineprotectedinherited

Definition at line 545 of file writer.h.

545  {
546  if (internal::Double(d).IsNanOrInf()) {
547  // Note: This code path can only be reached if (RAPIDJSON_WRITE_DEFAULT_FLAGS & kWriteNanAndInfFlag).
549  return false;
550  if (internal::Double(d).IsNan()) {
551  PutReserve(*os_, 3);
552  PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
553  return true;
554  }
555  if (internal::Double(d).Sign()) {
556  PutReserve(*os_, 9);
557  PutUnsafe(*os_, '-');
558  }
559  else
560  PutReserve(*os_, 8);
561  PutUnsafe(*os_, 'I'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'f');
562  PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y');
563  return true;
564  }
565 
566  char *buffer = os_->Push(25);
567  char* end = internal::dtoa(d, buffer, maxDecimalPlaces_);
568  os_->Pop(static_cast<size_t>(25 - (end - buffer)));
569  return true;
570 }
Default write flags. Can be customized by defining RAPIDJSON_WRITE_DEFAULT_FLAGS. ...
Definition: writer.h:69
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition: stream.h:84
OutputStream * os_
Definition: writer.h:499
int maxDecimalPlaces_
Definition: writer.h:501
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition: stream.h:91
Allow writing of Infinity, -Infinity and NaN.
Definition: writer.h:68
char * dtoa(double value, char *buffer, int maxDecimalPlaces=324)
Definition: dtoa.h:216
Here is the call graph for this function:

◆ WriteEndArray()

bool WriteEndArray ( )
inlineprotectedinherited

Definition at line 457 of file writer.h.

457 { os_->Put(']'); return true; }
OutputStream * os_
Definition: writer.h:499
Here is the caller graph for this function:

◆ WriteEndObject()

bool WriteEndObject ( )
inlineprotectedinherited

Definition at line 455 of file writer.h.

455 { os_->Put('}'); return true; }
OutputStream * os_
Definition: writer.h:499
Here is the caller graph for this function:

◆ WriteIndent()

void WriteIndent ( )
inlineprotected

Definition at line 252 of file prettywriter.h.

252  {
253  size_t count = (Base::level_stack_.GetSize() / sizeof(typename Base::Level)) * indentCharCount_;
254  PutN(*Base::os_, static_cast<typename OutputStream::Ch>(indentChar_), count);
255  }
void PutN(FileWriteStream &stream, char c, size_t n)
Implement specialized version of PutN() with memset() for better performance.
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:500
unsigned indentCharCount_
Definition: prettywriter.h:258
OutputStream * os_
Definition: writer.h:499
size_t GetSize() const
Definition: stack.h:177
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteInt() [1/2]

bool WriteInt ( int  i)
inlineprotectedinherited

Definition at line 312 of file writer.h.

312  {
313  char buffer[11];
314  const char* end = internal::i32toa(i, buffer);
315  PutReserve(*os_, static_cast<size_t>(end - buffer));
316  for (const char* p = buffer; p != end; ++p)
317  PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
318  return true;
319  }
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition: stream.h:84
OutputStream * os_
Definition: writer.h:499
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition: stream.h:91
char * i32toa(int32_t value, char *buffer)
Definition: itoa.h:115
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteInt() [2/2]

bool WriteInt ( int  i)
inlineprotectedinherited

Definition at line 513 of file writer.h.

513  {
514  char *buffer = os_->Push(11);
515  const char* end = internal::i32toa(i, buffer);
516  os_->Pop(static_cast<size_t>(11 - (end - buffer)));
517  return true;
518 }
OutputStream * os_
Definition: writer.h:499
char * i32toa(int32_t value, char *buffer)
Definition: itoa.h:115
Here is the call graph for this function:

◆ WriteInt64() [1/2]

bool WriteInt64 ( int64_t  i64)
inlineprotectedinherited

Definition at line 330 of file writer.h.

330  {
331  char buffer[21];
332  const char* end = internal::i64toa(i64, buffer);
333  PutReserve(*os_, static_cast<size_t>(end - buffer));
334  for (const char* p = buffer; p != end; ++p)
335  PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
336  return true;
337  }
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition: stream.h:84
OutputStream * os_
Definition: writer.h:499
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition: stream.h:91
char * i64toa(int64_t value, char *buffer)
Definition: itoa.h:294
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteInt64() [2/2]

bool WriteInt64 ( int64_t  i64)
inlineprotectedinherited

Definition at line 529 of file writer.h.

529  {
530  char *buffer = os_->Push(21);
531  const char* end = internal::i64toa(i64, buffer);
532  os_->Pop(static_cast<size_t>(21 - (end - buffer)));
533  return true;
534 }
OutputStream * os_
Definition: writer.h:499
char * i64toa(int64_t value, char *buffer)
Definition: itoa.h:294
Here is the call graph for this function:

◆ WriteNull()

bool WriteNull ( )
inlineprotectedinherited

Definition at line 295 of file writer.h.

295  {
296  PutReserve(*os_, 4);
297  PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 'l'); return true;
298  }
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition: stream.h:84
OutputStream * os_
Definition: writer.h:499
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition: stream.h:91
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteRawValue()

bool WriteRawValue ( const Ch json,
size_t  length 
)
inlineprotectedinherited

Definition at line 459 of file writer.h.

459  {
460  PutReserve(*os_, length);
462  while (RAPIDJSON_LIKELY(is.Tell() < length)) {
463  RAPIDJSON_ASSERT(is.Peek() != '\0');
464  if (RAPIDJSON_UNLIKELY(!(writeFlags & kWriteValidateEncodingFlag ?
467  return false;
468  }
469  return true;
470  }
Validate encoding of JSON strings.
Definition: writer.h:67
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition: rapidjson.h:463
Encoding conversion.
Definition: encodings.h:658
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition: stream.h:84
Read-only string stream.
Definition: fwd.h:47
OutputStream * os_
Definition: writer.h:499
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:476
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteStartArray()

bool WriteStartArray ( )
inlineprotectedinherited

Definition at line 456 of file writer.h.

456 { os_->Put('['); return true; }
OutputStream * os_
Definition: writer.h:499
Here is the caller graph for this function:

◆ WriteStartObject()

bool WriteStartObject ( )
inlineprotectedinherited

Definition at line 454 of file writer.h.

454 { os_->Put('{'); return true; }
OutputStream * os_
Definition: writer.h:499
Here is the caller graph for this function:

◆ WriteString()

bool WriteString ( const Ch str,
SizeType  length 
)
inlineprotectedinherited

Definition at line 376 of file writer.h.

376  {
377  static const typename OutputStream::Ch hexDigits[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
378  static const char escape[256] = {
379 #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
380  //0 1 2 3 4 5 6 7 8 9 A B C D E F
381  'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'b', 't', 'n', 'u', 'f', 'r', 'u', 'u', // 00
382  'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', // 10
383  0, 0, '"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20
384  Z16, Z16, // 30~4F
385  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, // 50
386  Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16 // 60~FF
387 #undef Z16
388  };
389 
390  if (TargetEncoding::supportUnicode)
391  PutReserve(*os_, 2 + length * 6); // "\uxxxx..."
392  else
393  PutReserve(*os_, 2 + length * 12); // "\uxxxx\uyyyy..."
394 
395  PutUnsafe(*os_, '\"');
397  while (ScanWriteUnescapedString(is, length)) {
398  const Ch c = is.Peek();
399  if (!TargetEncoding::supportUnicode && static_cast<unsigned>(c) >= 0x80) {
400  // Unicode escaping
401  unsigned codepoint;
402  if (RAPIDJSON_UNLIKELY(!SourceEncoding::Decode(is, &codepoint)))
403  return false;
404  PutUnsafe(*os_, '\\');
405  PutUnsafe(*os_, 'u');
406  if (codepoint <= 0xD7FF || (codepoint >= 0xE000 && codepoint <= 0xFFFF)) {
407  PutUnsafe(*os_, hexDigits[(codepoint >> 12) & 15]);
408  PutUnsafe(*os_, hexDigits[(codepoint >> 8) & 15]);
409  PutUnsafe(*os_, hexDigits[(codepoint >> 4) & 15]);
410  PutUnsafe(*os_, hexDigits[(codepoint ) & 15]);
411  }
412  else {
413  RAPIDJSON_ASSERT(codepoint >= 0x010000 && codepoint <= 0x10FFFF);
414  // Surrogate pair
415  unsigned s = codepoint - 0x010000;
416  unsigned lead = (s >> 10) + 0xD800;
417  unsigned trail = (s & 0x3FF) + 0xDC00;
418  PutUnsafe(*os_, hexDigits[(lead >> 12) & 15]);
419  PutUnsafe(*os_, hexDigits[(lead >> 8) & 15]);
420  PutUnsafe(*os_, hexDigits[(lead >> 4) & 15]);
421  PutUnsafe(*os_, hexDigits[(lead ) & 15]);
422  PutUnsafe(*os_, '\\');
423  PutUnsafe(*os_, 'u');
424  PutUnsafe(*os_, hexDigits[(trail >> 12) & 15]);
425  PutUnsafe(*os_, hexDigits[(trail >> 8) & 15]);
426  PutUnsafe(*os_, hexDigits[(trail >> 4) & 15]);
427  PutUnsafe(*os_, hexDigits[(trail ) & 15]);
428  }
429  }
430  else if ((sizeof(Ch) == 1 || static_cast<unsigned>(c) < 256) && RAPIDJSON_UNLIKELY(escape[static_cast<unsigned char>(c)])) {
431  is.Take();
432  PutUnsafe(*os_, '\\');
433  PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(escape[static_cast<unsigned char>(c)]));
434  if (escape[static_cast<unsigned char>(c)] == 'u') {
435  PutUnsafe(*os_, '0');
436  PutUnsafe(*os_, '0');
437  PutUnsafe(*os_, hexDigits[static_cast<unsigned char>(c) >> 4]);
438  PutUnsafe(*os_, hexDigits[static_cast<unsigned char>(c) & 0xF]);
439  }
440  }
441  else if (RAPIDJSON_UNLIKELY(!(writeFlags & kWriteValidateEncodingFlag ?
444  return false;
445  }
446  PutUnsafe(*os_, '\"');
447  return true;
448  }
Validate encoding of JSON strings.
Definition: writer.h:67
Encoding conversion.
Definition: encodings.h:658
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition: stream.h:84
Read-only string stream.
Definition: fwd.h:47
OutputStream * os_
Definition: writer.h:499
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:476
bool ScanWriteUnescapedString(GenericStringStream< SourceEncoding > &is, size_t length)
Definition: writer.h:450
#define Z16
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition: stream.h:91
SourceEncoding::Ch Ch
Definition: writer.h:91
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteUint() [1/2]

bool WriteUint ( unsigned  u)
inlineprotectedinherited

Definition at line 321 of file writer.h.

321  {
322  char buffer[10];
323  const char* end = internal::u32toa(u, buffer);
324  PutReserve(*os_, static_cast<size_t>(end - buffer));
325  for (const char* p = buffer; p != end; ++p)
326  PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
327  return true;
328  }
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition: stream.h:84
OutputStream * os_
Definition: writer.h:499
char * u32toa(uint32_t value, char *buffer)
Definition: itoa.h:39
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition: stream.h:91
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteUint() [2/2]

bool WriteUint ( unsigned  u)
inlineprotectedinherited

Definition at line 521 of file writer.h.

521  {
522  char *buffer = os_->Push(10);
523  const char* end = internal::u32toa(u, buffer);
524  os_->Pop(static_cast<size_t>(10 - (end - buffer)));
525  return true;
526 }
OutputStream * os_
Definition: writer.h:499
char * u32toa(uint32_t value, char *buffer)
Definition: itoa.h:39
Here is the call graph for this function:

◆ WriteUint64() [1/2]

bool WriteUint64 ( uint64_t  u64)
inlineprotectedinherited

Definition at line 339 of file writer.h.

339  {
340  char buffer[20];
341  char* end = internal::u64toa(u64, buffer);
342  PutReserve(*os_, static_cast<size_t>(end - buffer));
343  for (char* p = buffer; p != end; ++p)
344  PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
345  return true;
346  }
char * u64toa(uint64_t value, char *buffer)
Definition: itoa.h:126
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition: stream.h:84
OutputStream * os_
Definition: writer.h:499
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition: stream.h:91
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteUint64() [2/2]

bool WriteUint64 ( uint64_t  u)
inlineprotectedinherited

Definition at line 537 of file writer.h.

537  {
538  char *buffer = os_->Push(20);
539  const char* end = internal::u64toa(u, buffer);
540  os_->Pop(static_cast<size_t>(20 - (end - buffer)));
541  return true;
542 }
char * u64toa(uint64_t value, char *buffer)
Definition: itoa.h:126
OutputStream * os_
Definition: writer.h:499
Here is the call graph for this function:

Member Data Documentation

◆ formatOptions_

PrettyFormatOptions formatOptions_
protected

Definition at line 259 of file prettywriter.h.

◆ hasRoot_

bool hasRoot_
protectedinherited

Definition at line 502 of file writer.h.

◆ indentChar_

Ch indentChar_
protected

Definition at line 257 of file prettywriter.h.

◆ indentCharCount_

unsigned indentCharCount_
protected

Definition at line 258 of file prettywriter.h.

◆ kDefaultLevelDepth

const size_t kDefaultLevelDepth = 32
staticprotectedinherited

Definition at line 293 of file writer.h.

◆ kDefaultMaxDecimalPlaces

const int kDefaultMaxDecimalPlaces = 324
staticinherited

Definition at line 93 of file writer.h.

◆ level_stack_

internal::Stack<StackAllocator> level_stack_
protectedinherited

Definition at line 500 of file writer.h.

◆ maxDecimalPlaces_

int maxDecimalPlaces_
protectedinherited

Definition at line 501 of file writer.h.

◆ os_

OutputStream* os_
protectedinherited

Definition at line 499 of file writer.h.


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