Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags > Class Template Reference

JSON writer. More...

#include <writer.h>

Collaboration diagram for Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >:

Classes

struct  Level
 Information for each nested level. More...
 

Public Types

typedef SourceEncoding::Ch Ch
 

Public Member Functions

 Writer (OutputStream &os, StackAllocator *stackAllocator=0, size_t levelDepth=kDefaultLevelDepth)
 Constructor.
 
 Writer (StackAllocator *allocator=0, size_t levelDepth=kDefaultLevelDepth)
 
void Reset (OutputStream &os)
 Reset the writer with a new stream.
 
bool IsComplete () const
 Checks whether the output is a complete JSON.
 
int GetMaxDecimalPlaces () const
 
void SetMaxDecimalPlaces (int maxDecimalPlaces)
 Sets the maximum number of decimal places for double output.
 
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)
 Writes the given double value to the stream.
 
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 elementCount=0)
 

Static Public Attributes

static const int kDefaultMaxDecimalPlaces = 324
 

Protected Member Functions

bool WriteInt (int i)
 
bool WriteUint (unsigned u)
 
bool WriteInt64 (int64_t i64)
 
bool WriteUint64 (uint64_t u)
 
bool WriteDouble (double d)
 

Convenience extensions

static const size_t kDefaultLevelDepth = 32
 
OutputStream * os_
 
internal::Stack< StackAllocator > level_stack_
 
int maxDecimalPlaces_
 
bool hasRoot_
 
bool String (const Ch *const &str)
 Simpler but slower overload.
 
bool Key (const Ch *const &str)
 
bool RawValue (const Ch *json, size_t length, Type type)
 Write a raw JSON value.
 
void Flush ()
 Flush the output stream.
 
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 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)
 

Detailed Description

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

Writer implements the concept Handler. It generates JSON text by events to an output os.

User may programmatically calls the functions of a writer to generate JSON text.

On the other side, a writer can also be passed to objects that generates events,

for example Reader::Parse() and Document::Accept().

Template Parameters
OutputStreamType of output stream.
SourceEncodingEncoding of source string.
TargetEncodingEncoding of output stream.
StackAllocatorType of allocator for allocating memory of stack.
Note
implements Handler concept

Definition at line 89 of file writer.h.

Member Typedef Documentation

◆ Ch

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
SourceEncoding::Ch Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Ch

Definition at line 91 of file writer.h.

Constructor & Destructor Documentation

◆ Writer() [1/2]

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Writer ( OutputStream & os,
StackAllocator * stackAllocator = 0,
size_t levelDepth = kDefaultLevelDepth )
inlineexplicit
Parameters
osOutput stream.
stackAllocatorUser supplied allocator. If it is null, it will create a private one.
levelDepthInitial capacity of stack.

Definition at line 101 of file writer.h.

101 :
102 os_(&os), level_stack_(stackAllocator, levelDepth * sizeof(Level)), maxDecimalPlaces_(kDefaultMaxDecimalPlaces), hasRoot_(false) {}
OutputStream * os_
Definition writer.h:499
int maxDecimalPlaces_
Definition writer.h:501
internal::Stack< StackAllocator > level_stack_
Definition writer.h:500
static const int kDefaultMaxDecimalPlaces
Definition writer.h:93
bool hasRoot_
Definition writer.h:502
os_t os

◆ Writer() [2/2]

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Writer ( StackAllocator * allocator = 0,
size_t levelDepth = kDefaultLevelDepth )
inlineexplicit

Definition at line 105 of file writer.h.

105 :
106 os_(0), level_stack_(allocator, levelDepth * sizeof(Level)), maxDecimalPlaces_(kDefaultMaxDecimalPlaces), hasRoot_(false) {}

Member Function Documentation

◆ Bool()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Bool ( bool b)
inline

Definition at line 182 of file writer.h.

182{ Prefix(b ? kTrueType : kFalseType); return EndValue(WriteBool(b)); }
void Prefix(Type type)
Definition writer.h:472
bool WriteBool(bool b)
Definition writer.h:300
bool EndValue(bool ret)
Definition writer.h:493
@ kFalseType
false
Definition rapidjson.h:646
@ kTrueType
true
Definition rapidjson.h:647
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Double()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Double ( double d)
inline
Parameters
dThe value to be written.
Returns
Whether it is succeed.

Definition at line 193 of file writer.h.

193{ Prefix(kNumberType); return EndValue(WriteDouble(d)); }
bool WriteDouble(double d)
Definition writer.h:348
@ kNumberType
number
Definition rapidjson.h:651
Here is the call graph for this function:
Here is the caller graph for this function:

◆ EndArray()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::EndArray ( SizeType elementCount = 0)
inline

Definition at line 245 of file writer.h.

245 {
246 (void)elementCount;
247 RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
248 RAPIDJSON_ASSERT(level_stack_.template Top<Level>()->inArray);
249 level_stack_.template Pop<Level>(1);
250 return EndValue(WriteEndArray());
251 }
bool WriteEndArray()
Definition writer.h:457
size_t GetSize() const
Definition stack.h:178
#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:

◆ EndObject()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::EndObject ( SizeType memberCount = 0)
inline

Definition at line 230 of file writer.h.

230 {
231 (void)memberCount;
232 RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); // not inside an Object
233 RAPIDJSON_ASSERT(!level_stack_.template Top<Level>()->inArray); // currently inside an Array, not Object
234 RAPIDJSON_ASSERT(0 == level_stack_.template Top<Level>()->valueCount % 2); // Object has a Key without a Value
235 level_stack_.template Pop<Level>(1);
236 return EndValue(WriteEndObject());
237 }
bool WriteEndObject()
Definition writer.h:455
Here is the call graph for this function:
Here is the caller graph for this function:

◆ EndValue()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::EndValue ( bool ret)
inlineprotected

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 }
void Flush()
Flush the output stream.
Definition writer.h:281
bool Empty() const
Definition stack.h:177
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition rapidjson.h:476
CK_RV ret
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Flush()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
void Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Flush ( )
inline

Allows the user to flush the output stream immediately.

Definition at line 281 of file writer.h.

281 {
282 os_->Flush();
283 }
Here is the caller graph for this function:

◆ GetMaxDecimalPlaces()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
int Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::GetMaxDecimalPlaces ( ) const
inline

Definition at line 147 of file writer.h.

147 {
148 return maxDecimalPlaces_;
149 }

◆ Int()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Int ( int i)
inline

Definition at line 183 of file writer.h.

183{ Prefix(kNumberType); return EndValue(WriteInt(i)); }
bool WriteInt(int i)
Definition writer.h:312
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Int64()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Int64 ( int64_t i64)
inline

Definition at line 185 of file writer.h.

185{ Prefix(kNumberType); return EndValue(WriteInt64(i64)); }
bool WriteInt64(int64_t i64)
Definition writer.h:330
Here is the call graph for this function:

◆ IsComplete()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::IsComplete ( ) const
inline

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 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Key() [1/2]

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Key ( const Ch *const & str)
inline

Definition at line 259 of file writer.h.

259{ return Key(str, internal::StrLen(str)); }
bool Key(const Ch *str, SizeType length, bool copy=false)
Definition writer.h:221
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() [2/2]

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Key ( const Ch * str,
SizeType length,
bool copy = false )
inline

Definition at line 221 of file writer.h.

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

◆ Null()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Null ( )
inline

Definition at line 181 of file writer.h.

181{ Prefix(kNullType); return EndValue(WriteNull()); }
bool WriteNull()
Definition writer.h:295
@ kNullType
null
Definition rapidjson.h:645
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Prefix()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
void Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Prefix ( Type type)
inlineprotected

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 }
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition rapidjson.h:463
uint32_t level
Type of a channel package.
Definition levels.hpp:37
@ kStringType
string
Definition rapidjson.h:650
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RawNumber()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::RawNumber ( const Ch * str,
SizeType length,
bool copy = false )
inline

Definition at line 195 of file writer.h.

195 {
196 RAPIDJSON_ASSERT(str != 0);
197 (void)copy;
199 return EndValue(WriteString(str, length));
200 }
bool WriteString(const Ch *str, SizeType length)
Definition writer.h:376
Here is the call graph for this function:

◆ RawValue()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::RawValue ( const Ch * json,
size_t length,
Type type )
inline

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.

Definition at line 271 of file writer.h.

271 {
272 RAPIDJSON_ASSERT(json != 0);
273 Prefix(type);
274 return EndValue(WriteRawValue(json, length));
275 }
bool WriteRawValue(const Ch *json, size_t length)
Definition writer.h:459
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Reset()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
void Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Reset ( OutputStream & os)
inline

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();
JSON writer.
Definition writer.h:89

Definition at line 133 of file writer.h.

133 {
134 os_ = &os;
135 hasRoot_ = false;
137 }
void Clear()
Definition stack.h:99
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScanWriteUnescapedString()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::ScanWriteUnescapedString ( GenericStringStream< SourceEncoding > & is,
size_t length )
inlineprotected

Definition at line 450 of file writer.h.

450 {
451 return RAPIDJSON_LIKELY(is.Tell() < length);
452 }
Here is the caller graph for this function:

◆ SetMaxDecimalPlaces()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
void Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::SetMaxDecimalPlaces ( int maxDecimalPlaces)
inline

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 }

◆ StartArray()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::StartArray ( )
inline

Definition at line 239 of file writer.h.

239 {
241 new (level_stack_.template Push<Level>()) Level(true);
242 return WriteStartArray();
243 }
bool WriteStartArray()
Definition writer.h:456
@ kArrayType
array
Definition rapidjson.h:649
Here is the call graph for this function:
Here is the caller graph for this function:

◆ StartObject()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::StartObject ( )
inline

Definition at line 215 of file writer.h.

215 {
217 new (level_stack_.template Push<Level>()) Level(false);
218 return WriteStartObject();
219 }
bool WriteStartObject()
Definition writer.h:454
@ kObjectType
object
Definition rapidjson.h:648
Here is the call graph for this function:
Here is the caller graph for this function:

◆ String() [1/2]

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::String ( const Ch *const & str)
inline

Definition at line 258 of file writer.h.

258{ return String(str, internal::StrLen(str)); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ String() [2/2]

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::String ( const Ch * str,
SizeType length,
bool copy = false )
inline

Definition at line 202 of file writer.h.

202 {
203 RAPIDJSON_ASSERT(str != 0);
204 (void)copy;
206 return EndValue(WriteString(str, length));
207 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Uint()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Uint ( unsigned u)
inline

Definition at line 184 of file writer.h.

184{ Prefix(kNumberType); return EndValue(WriteUint(u)); }
bool WriteUint(unsigned u)
Definition writer.h:321
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Uint64()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::Uint64 ( uint64_t u64)
inline

Definition at line 186 of file writer.h.

186{ Prefix(kNumberType); return EndValue(WriteUint64(u64)); }
bool WriteUint64(uint64_t u64)
Definition writer.h:339
Here is the call graph for this function:

◆ WriteBool()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::WriteBool ( bool b)
inlineprotected

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 PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition stream.h:91
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition stream.h:84
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteDouble() [1/2]

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::WriteDouble ( double d)
inlineprotected

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 }
const mie::Vuint & p
Definition bn.cpp:27
char * dtoa(double value, char *buffer, int maxDecimalPlaces=324)
Definition dtoa.h:216
@ kWriteNanAndInfFlag
Allow writing of Infinity, -Infinity and NaN.
Definition writer.h:68
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteDouble() [2/2]

bool Writer< StringBuffer >::WriteDouble ( double d)
inlineprotected

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}
@ kWriteDefaultFlags
Default write flags. Can be customized by defining RAPIDJSON_WRITE_DEFAULT_FLAGS.
Definition writer.h:69
Here is the call graph for this function:

◆ WriteEndArray()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::WriteEndArray ( )
inlineprotected

Definition at line 457 of file writer.h.

457{ os_->Put(']'); return true; }
Here is the caller graph for this function:

◆ WriteEndObject()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::WriteEndObject ( )
inlineprotected

Definition at line 455 of file writer.h.

455{ os_->Put('}'); return true; }
Here is the caller graph for this function:

◆ WriteInt() [1/2]

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::WriteInt ( int i)
inlineprotected

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 }
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 Writer< StringBuffer >::WriteInt ( int i)
inlineprotected

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}
Here is the call graph for this function:

◆ WriteInt64() [1/2]

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::WriteInt64 ( int64_t i64)
inlineprotected

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 }
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 Writer< StringBuffer >::WriteInt64 ( int64_t i64)
inlineprotected

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}
Here is the call graph for this function:

◆ WriteNull()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::WriteNull ( )
inlineprotected

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 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteRawValue()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::WriteRawValue ( const Ch * json,
size_t length )
inlineprotected

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');
467 return false;
468 }
469 return true;
470 }
Read-only string stream.
Definition stream.h:154
Encoding conversion.
Definition encodings.h:658
@ kWriteValidateEncodingFlag
Validate encoding of JSON strings.
Definition writer.h:67
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteStartArray()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::WriteStartArray ( )
inlineprotected

Definition at line 456 of file writer.h.

456{ os_->Put('['); return true; }
Here is the caller graph for this function:

◆ WriteStartObject()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::WriteStartObject ( )
inlineprotected

Definition at line 454 of file writer.h.

454{ os_->Put('{'); return true; }
Here is the caller graph for this function:

◆ WriteString()

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::WriteString ( const Ch * str,
SizeType length )
inlineprotected

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 }
SourceEncoding::Ch Ch
Definition writer.h:91
bool ScanWriteUnescapedString(GenericStringStream< SourceEncoding > &is, size_t length)
Definition writer.h:450
#define Z16
char * s
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteUint() [1/2]

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::WriteUint ( unsigned u)
inlineprotected

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 }
char * u32toa(uint32_t value, char *buffer)
Definition itoa.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteUint() [2/2]

bool Writer< StringBuffer >::WriteUint ( unsigned u)
inlineprotected

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}
Here is the call graph for this function:

◆ WriteUint64() [1/2]

bool Writer< StringBuffer >::WriteUint64 ( uint64_t u)
inlineprotected

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
Here is the call graph for this function:

◆ WriteUint64() [2/2]

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::WriteUint64 ( uint64_t u64)
inlineprotected

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 }
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ hasRoot_

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::hasRoot_
protected

Definition at line 502 of file writer.h.

◆ kDefaultLevelDepth

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
const size_t Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::kDefaultLevelDepth = 32
staticprotected

Definition at line 293 of file writer.h.

◆ kDefaultMaxDecimalPlaces

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
const int Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::kDefaultMaxDecimalPlaces = 324
static

Definition at line 93 of file writer.h.

◆ level_stack_

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
internal::Stack<StackAllocator> Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::level_stack_
protected

Definition at line 500 of file writer.h.

◆ maxDecimalPlaces_

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
int Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::maxDecimalPlaces_
protected

Definition at line 501 of file writer.h.

◆ os_

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
OutputStream* Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >::os_
protected

Definition at line 499 of file writer.h.


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