15 #ifndef RAPIDJSON_PRETTYWRITER_H_ 16 #define RAPIDJSON_PRETTYWRITER_H_ 22 RAPIDJSON_DIAG_OFF(effc++)
25 #if defined(__clang__) 27 RAPIDJSON_DIAG_OFF(c++98-compat)
47 template<
typename OutputStream,
typename SourceEncoding = UTF8<>,
typename TargetEncoding = UTF8<>,
typename StackAllocator = CrtAllocator,
unsigned writeFlags = kWriteDefaultFlags>
48 class PrettyWriter :
public Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> {
65 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 76 RAPIDJSON_ASSERT(indentChar ==
' ' || indentChar ==
'\t' || indentChar ==
'\n' || indentChar ==
'\r');
117 #if RAPIDJSON_HAS_STDSTRING 118 bool String(
const std::basic_string<Ch>& str) {
125 new (
Base::level_stack_.template Push<typename Base::Level>())
typename Base::Level(
false);
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) {
143 bool empty =
Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
159 new (
Base::level_stack_.template Push<typename Base::Level>())
typename Base::Level(
true);
167 bool empty =
Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
211 typename Base::Level* level =
Base::level_stack_.template Top<typename Base::Level>();
213 if (level->inArray) {
214 if (level->valueCount > 0) {
226 if (level->valueCount > 0) {
227 if (level->valueCount % 2 == 0) {
239 if (level->valueCount % 2 == 0)
242 if (!level->inArray && level->valueCount % 2 == 0)
269 #if defined(__clang__) 277 #endif // RAPIDJSON_RAPIDJSON_H_ PrettyFormatOptions
Combination of PrettyWriter format flags.
unsigned indentCharCount_
bool RawValue(const Ch *json, size_t length, Type type)
Write a raw JSON value.
void Flush()
Flush the output stream.
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
#define RAPIDJSON_ASSERT(x)
Assertion.
PrettyFormatOptions formatOptions_
bool WriteInt64(int64_t i64)
void PrettyPrefix(Type type)
PrettyWriter & SetIndent(Ch indentChar, unsigned indentCharCount)
Set custom indentation.
bool String(const Ch *str)
Simpler but slower overload.
bool WriteUint64(uint64_t u64)
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
static const size_t kDefaultLevelDepth
void PutN(FileWriteStream &stream, char c, size_t n)
Implement specialized version of PutN() with memset() for better performance.
bool Key(const Ch *str, SizeType length, bool copy=false)
bool WriteRawValue(const Ch *json, size_t length)
PrettyWriter & operator=(const PrettyWriter &)
PrettyWriter(StackAllocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth)
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Default pretty formatting.
bool RawNumber(const Ch *str, SizeType length, bool copy=false)
bool WriteUint(unsigned u)
bool EndObject(SizeType memberCount=0)
unsigned __int64 uint64_t
bool WriteString(const Ch *str, SizeType length)
bool EndArray(SizeType memberCount=0)
PrettyWriter(OutputStream &os, StackAllocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth)
Constructor.
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
bool String(const Ch *str, SizeType length, bool copy=false)
internal::Stack< StackAllocator > level_stack_
bool WriteDouble(double d)
Format arrays on a single line.
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags > Base
PrettyWriter & SetFormatOptions(PrettyFormatOptions options)
Set pretty writer formatting options.
bool Uint64(uint64_t u64)
Writer with indentation and spacing.