rapidjson::PrettyWriter< Stream, Encoding, Allocator > Class Template Reference

Writer with indentation and spacing. More...

#include <prettywriter.h>

+ Inheritance diagram for rapidjson::PrettyWriter< Stream, Encoding, Allocator >:

Public Types

typedef Writer< Stream, Encoding, AllocatorBase
 
typedef Base::Ch Ch
 
- Public Types inherited from rapidjson::Writer< Stream, UTF8<>, MemoryPoolAllocator<> >
typedef Encoding::Ch Ch
 

Public Member Functions

 PrettyWriter (Stream &stream, int precision=20, Allocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth)
 Constructor. More...
 
PrettyWriterSetIndent (Ch indentChar, unsigned indentCharCount)
 Set custom indentation. More...
 
PrettyWriterNull_ ()
 
PrettyWriterBool_ (bool b)
 
PrettyWriterInt (int i)
 
PrettyWriterUint (unsigned u)
 
PrettyWriterInt64 (int64_t i64)
 
PrettyWriterUint64 (uint64_t u64)
 
PrettyWriterDouble (double d)
 
PrettyWriterString (const Ch *str, SizeType length, bool copy=false)
 
PrettyWriterStartObject ()
 
PrettyWriterEndObject (SizeType memberCount=0)
 
PrettyWriterStartArray ()
 
PrettyWriterEndArray (SizeType memberCount=0)
 
PrettyWriterString (const Ch *str)
 Simpler but slower overload. More...
 
- Public Member Functions inherited from rapidjson::Writer< Stream, UTF8<>, MemoryPoolAllocator<> >
 Writer (Stream &stream, int precision=20, MemoryPoolAllocator<> *allocator=0, size_t levelDepth=kDefaultLevelDepth)
 
WriterNull_ ()
 
WriterBool_ (bool b)
 
WriterInt (int i)
 
WriterUint (unsigned u)
 
WriterInt64 (int64_t i64)
 
WriterUint64 (uint64_t u64)
 
WriterDouble (double d)
 
WriterLongDouble (long double d)
 
WriterLongLong (long long d)
 
WriterULongLong (unsigned long long d)
 
WriterString (const Ch *str, SizeType length, bool copy=false)
 
WriterString (const Ch *str)
 Simpler but slower overload. More...
 
WriterStartObject ()
 
WriterEndObject (SizeType memberCount=0)
 
WriterStartArray ()
 
WriterEndArray (SizeType elementCount=0)
 

Protected Member Functions

void PrettyPrefix (Type type)
 
void WriteIndent ()
 
- Protected Member Functions inherited from rapidjson::Writer< Stream, UTF8<>, MemoryPoolAllocator<> >
void WriteNull_ ()
 
void WriteBool_ (bool b)
 
void WriteInt (int i)
 
void WriteUint (unsigned u)
 
void WriteInt64 (int64_t i64)
 
void WriteUint64 (uint64_t u64)
 
std::enable_if< to_int(std::numeric_limits< Ch >::max())< to_int(256), bool >::type characterOk(Ch) { return true;} template< class Ch > typename std::enable_if< to_int(std::numeric_limits< Ch >::max()) >=to_int(256), bool >::type characterOk (Ch c)
 
void WriteDouble (double d)
 
void WriteLongDouble (long double d)
 
void WriteLongLong (long long d)
 
void WriteULongLong (unsigned long long d)
 
void WriteString (const Ch *str, SizeType length)
 
void WriteStartObject ()
 
void WriteEndObject ()
 
void WriteStartArray ()
 
void WriteEndArray ()
 
void Prefix (Type type)
 

Protected Attributes

Ch indentChar_
 
unsigned indentCharCount_
 
- Protected Attributes inherited from rapidjson::Writer< Stream, UTF8<>, MemoryPoolAllocator<> >
char double_format [32]
 
char long_double_format [32]
 
Streamstream_
 
internal::Stack< MemoryPoolAllocator<> > level_stack_
 

Additional Inherited Members

- Static Protected Member Functions inherited from rapidjson::Writer< Stream, UTF8<>, MemoryPoolAllocator<> >
static constexpr int to_int (T t)
 
- Static Protected Attributes inherited from rapidjson::Writer< Stream, UTF8<>, MemoryPoolAllocator<> >
static const size_t kDefaultLevelDepth
 

Detailed Description

template<typename Stream, typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
class rapidjson::PrettyWriter< Stream, Encoding, Allocator >

Writer with indentation and spacing.

Template Parameters
StreamType of ouptut stream.
EncodingEncoding of both source strings and output.
AllocatorType of allocator for allocating memory of stack.

Member Typedef Documentation

◆ Base

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
typedef Writer<Stream, Encoding, Allocator> rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Base

◆ Ch

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
typedef Base::Ch rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Ch

Constructor & Destructor Documentation

◆ PrettyWriter()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
rapidjson::PrettyWriter< Stream, Encoding, Allocator >::PrettyWriter ( Stream stream,
int  precision = 20,
Allocator allocator = 0,
size_t  levelDepth = Base::kDefaultLevelDepth 
)
inline

Constructor.

Parameters
streamOutput stream.
allocatorUser supplied allocator. If it is null, it will create a private one.
levelDepthInitial capacity of
50  :
51  Base(stream, precision, allocator, levelDepth), indentChar_(' '), indentCharCount_(4) {}
Writer< Stream, Encoding, Allocator > Base
Definition: prettywriter.h:42
unsigned indentCharCount_
Definition: prettywriter.h:176
Ch indentChar_
Definition: prettywriter.h:175

Member Function Documentation

◆ Bool_()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Bool_ ( bool  b)
inline
69 { PrettyPrefix(b ? kTrueType : kFalseType); Base::WriteBool_(b); return *this; }
void PrettyPrefix(Type type)
Definition: prettywriter.h:131
void WriteBool_(bool b)
Definition: writer.h:151
@ kTrueType
true
Definition: rapidjson.h:541
@ kFalseType
false
Definition: rapidjson.h:540

References rapidjson::kFalseType, rapidjson::kTrueType, rapidjson::PrettyWriter< Stream, Encoding, Allocator >::PrettyPrefix(), and rapidjson::Writer< Stream, Encoding, Allocator >::WriteBool_().

◆ Double()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Double ( double  d)
inline

◆ EndArray()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::EndArray ( SizeType  memberCount = 0)
inline
111  {
112  (void)memberCount;
113  RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level));
114  RAPIDJSON_ASSERT(Base::level_stack_.template Top<typename Base::Level>()->inArray);
115  bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
116 
117  if (!empty) {
118  Base::stream_.Put('\n');
119  WriteIndent();
120  }
122  return *this;
123  }
void WriteIndent()
Definition: prettywriter.h:170
internal::Stack< Allocator > level_stack_
Definition: writer.h:342
Stream & stream_
Definition: writer.h:341
void WriteEndArray()
Definition: writer.h:321
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:105

References rapidjson::Writer< Stream, Encoding, Allocator >::level_stack_, RAPIDJSON_ASSERT, rapidjson::Writer< Stream, Encoding, Allocator >::stream_, rapidjson::Writer< Stream, Encoding, Allocator >::WriteEndArray(), and rapidjson::PrettyWriter< Stream, Encoding, Allocator >::WriteIndent().

◆ EndObject()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::EndObject ( SizeType  memberCount = 0)
inline
90  {
91  (void)memberCount;
92  RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level));
93  RAPIDJSON_ASSERT(!Base::level_stack_.template Top<typename Base::Level>()->inArray);
94  bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
95 
96  if (!empty) {
97  Base::stream_.Put('\n');
98  WriteIndent();
99  }
101  return *this;
102  }
void WriteEndObject()
Definition: writer.h:319

References rapidjson::Writer< Stream, Encoding, Allocator >::level_stack_, RAPIDJSON_ASSERT, rapidjson::Writer< Stream, Encoding, Allocator >::stream_, rapidjson::Writer< Stream, Encoding, Allocator >::WriteEndObject(), and rapidjson::PrettyWriter< Stream, Encoding, Allocator >::WriteIndent().

◆ Int()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Int ( int  i)
inline

◆ Int64()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Int64 ( int64_t  i64)
inline

◆ Null_()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Null_ ( )
inline

◆ PrettyPrefix()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
void rapidjson::PrettyWriter< Stream, Encoding, Allocator >::PrettyPrefix ( Type  type)
inlineprotected
131  {
132  (void)type;
133  if (Base::level_stack_.GetSize() != 0) { // this value is not at root
134  typename Base::Level* level = Base::level_stack_.template Top<typename Base::Level>();
135 
136  if (level->inArray) {
137  if (level->valueCount > 0) {
138  Base::stream_.Put(','); // add comma if it is not the first element in array
139  Base::stream_.Put('\n');
140  }
141  else
142  Base::stream_.Put('\n');
143  WriteIndent();
144  }
145  else { // in object
146  if (level->valueCount > 0) {
147  if (level->valueCount % 2 == 0) {
148  Base::stream_.Put(',');
149  Base::stream_.Put('\n');
150  }
151  else {
152  Base::stream_.Put(':');
153  Base::stream_.Put(' ');
154  }
155  }
156  else
157  Base::stream_.Put('\n');
158 
159  if (level->valueCount % 2 == 0)
160  WriteIndent();
161  }
162  if (!level->inArray && level->valueCount % 2 == 0)
163  RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
164  level->valueCount++;
165  }
166  else
167  RAPIDJSON_ASSERT(type == kObjectType || type == kArrayType);
168  }
@ kArrayType
array
Definition: rapidjson.h:543
@ kObjectType
object
Definition: rapidjson.h:542
@ kStringType
string
Definition: rapidjson.h:544

References rapidjson::Writer< Stream, Encoding, Allocator >::Level::inArray, rapidjson::kArrayType, rapidjson::kObjectType, rapidjson::kStringType, rapidjson::Writer< Stream, Encoding, Allocator >::level_stack_, RAPIDJSON_ASSERT, rapidjson::Writer< Stream, Encoding, Allocator >::stream_, rapidjson::Writer< Stream, Encoding, Allocator >::Level::valueCount, and rapidjson::PrettyWriter< Stream, Encoding, Allocator >::WriteIndent().

Referenced by rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Bool_(), rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Double(), rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Int(), rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Int64(), rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Null_(), rapidjson::PrettyWriter< Stream, Encoding, Allocator >::StartArray(), rapidjson::PrettyWriter< Stream, Encoding, Allocator >::StartObject(), rapidjson::PrettyWriter< Stream, Encoding, Allocator >::String(), rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Uint(), and rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Uint64().

◆ SetIndent()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::SetIndent ( Ch  indentChar,
unsigned  indentCharCount 
)
inline

Set custom indentation.

Parameters
indentCharCharacter for indentation. Must be whitespace character (' ', '\t', '
', '\r').
indentCharCountNumber of indent characters for each indentation level.
Note
The default indentation is 4 spaces.
58  {
59  RAPIDJSON_ASSERT(indentChar == ' ' || indentChar == '\t' || indentChar == '\n' || indentChar == '\r');
60  indentChar_ = indentChar;
61  indentCharCount_ = indentCharCount;
62  return *this;
63  }

References rapidjson::PrettyWriter< Stream, Encoding, Allocator >::indentChar_, rapidjson::PrettyWriter< Stream, Encoding, Allocator >::indentCharCount_, and RAPIDJSON_ASSERT.

◆ StartArray()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::StartArray ( )
inline

◆ StartObject()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::StartObject ( )
inline

◆ String() [1/2]

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::String ( const Ch str)
inline

Simpler but slower overload.

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

References rapidjson::PrettyWriter< Stream, Encoding, Allocator >::String(), and rapidjson::internal::StrLen().

Referenced by rapidjson::PrettyWriter< Stream, Encoding, Allocator >::String().

◆ String() [2/2]

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::String ( const Ch str,
SizeType  length,
bool  copy = false 
)
inline
76  {
77  (void)copy;
79  Base::WriteString(str, length);
80  return *this;
81  }
void WriteString(const Ch *str, SizeType length)
Definition: writer.h:285

References rapidjson::kStringType, rapidjson::PrettyWriter< Stream, Encoding, Allocator >::PrettyPrefix(), and rapidjson::Writer< Stream, Encoding, Allocator >::WriteString().

◆ Uint()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Uint ( unsigned  u)
inline

◆ Uint64()

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
PrettyWriter& rapidjson::PrettyWriter< Stream, Encoding, Allocator >::Uint64 ( uint64_t  u64)
inline

◆ WriteIndent()

Member Data Documentation

◆ indentChar_

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
Ch rapidjson::PrettyWriter< Stream, Encoding, Allocator >::indentChar_
protected

◆ indentCharCount_

template<typename Stream , typename Encoding = UTF8<>, typename Allocator = MemoryPoolAllocator<>>
unsigned rapidjson::PrettyWriter< Stream, Encoding, Allocator >::indentCharCount_
protected

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