48class PrettyWriter :
public Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> {
51 typedef typename Base::Ch Ch;
65#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
66 PrettyWriter(PrettyWriter&& rhs) :
67 Base(std::forward<PrettyWriter>(rhs)), indentChar_(rhs.indentChar_), indentCharCount_(rhs.indentCharCount_), formatOptions_(rhs.formatOptions_) {}
95 bool Null() { PrettyPrefix(kNullType);
return Base::WriteNull(); }
96 bool Bool(
bool b) { PrettyPrefix(b ? kTrueType : kFalseType);
return Base::WriteBool(b); }
97 bool Int(
int i) { PrettyPrefix(kNumberType);
return Base::WriteInt(i); }
98 bool Uint(
unsigned u) { PrettyPrefix(kNumberType);
return Base::WriteUint(u); }
99 bool Int64(int64_t i64) { PrettyPrefix(kNumberType);
return Base::WriteInt64(i64); }
100 bool Uint64(uint64_t u64) { PrettyPrefix(kNumberType);
return Base::WriteUint64(u64); }
101 bool Double(
double d) { PrettyPrefix(kNumberType);
return Base::WriteDouble(d); }
103 bool RawNumber(
const Ch* str, SizeType length,
bool copy =
false) {
106 PrettyPrefix(kNumberType);
107 return Base::WriteString(str, length);
110 bool String(
const Ch* str, SizeType length,
bool copy =
false) {
113 PrettyPrefix(kStringType);
114 return Base::WriteString(str, length);
117#if RAPIDJSON_HAS_STDSTRING
118 bool String(
const std::basic_string<Ch>& str) {
119 return String(str.data(),
SizeType(str.size()));
124 PrettyPrefix(kObjectType);
125 new (Base::level_stack_.template Push<typename Base::Level>())
typename Base::Level(
false);
126 return Base::WriteStartObject();
129 bool Key(
const Ch* str, SizeType length,
bool copy =
false) {
return String(str, length, copy); }
131#if RAPIDJSON_HAS_STDSTRING
132 bool Key(
const std::basic_string<Ch>& str) {
133 return Key(str.data(),
SizeType(str.size()));
137 bool EndObject(SizeType memberCount = 0) {
139 RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >=
sizeof(
typename Base::Level));
140 RAPIDJSON_ASSERT(!Base::level_stack_.
template Top<typename Base::Level>()->inArray);
141 RAPIDJSON_ASSERT(0 == Base::level_stack_.
template Top<typename Base::Level>()->valueCount % 2);
143 bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
146 Base::os_->Put(
'\n');
149 bool ret = Base::WriteEndObject();
152 if (Base::level_stack_.Empty())
158 PrettyPrefix(kArrayType);
159 new (Base::level_stack_.template Push<typename Base::Level>())
typename Base::Level(
true);
160 return Base::WriteStartArray();
163 bool EndArray(SizeType memberCount = 0) {
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;
169 if (!empty && !(formatOptions_ & kFormatSingleLineArray)) {
170 Base::os_->Put(
'\n');
173 bool ret = Base::WriteEndArray();
176 if (Base::level_stack_.Empty())
187 bool String(
const Ch* str) {
return String(str, internal::StrLen(str)); }
188 bool Key(
const Ch* str) {
return Key(str, internal::StrLen(str)); }
204 return Base::WriteRawValue(
json, length);
210 if (Base::level_stack_.GetSize() != 0) {
213 if (
level->inArray) {
214 if (
level->valueCount > 0) {
216 if (formatOptions_ & kFormatSingleLineArray)
220 if (!(formatOptions_ & kFormatSingleLineArray)) {
221 Base::os_->Put(
'\n');
226 if (level->valueCount > 0) {
227 if (level->valueCount % 2 == 0) {
229 Base::os_->Put(
'\n');
237 Base::os_->Put(
'\n');
239 if (level->valueCount % 2 == 0)
242 if (!level->inArray && level->valueCount % 2 == 0)
248 Base::hasRoot_ =
true;
253 size_t count = (Base::level_stack_.GetSize() /
sizeof(
typename Base::Level)) * indentCharCount_;
254 PutN(*Base::os_,
static_cast<typename OutputStream::Ch
>(indentChar_), count);
258 unsigned indentCharCount_;
263 PrettyWriter(
const PrettyWriter&);
264 PrettyWriter& operator=(
const PrettyWriter&);