Electroneum
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 >

JSON writer.

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>
typedef 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

Constructor.

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.

◆ 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.

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

◆ 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

Writes the given double value to the stream.

Parameters
dThe value to be written.
Returns
Whether it is succeed.

Definition at line 193 of file writer.h.

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 {
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 }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:411
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 {
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 }
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 494 of file writer.h.

494 {
495 if (RAPIDJSON_UNLIKELY(level_stack_.Empty())) // end of json text
496 Flush();
497 return ret;
498 }
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition rapidjson.h:481
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

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 }
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.

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

◆ 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

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 }
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
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 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.

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

473 {
474 (void)type;
475 if (RAPIDJSON_LIKELY(level_stack_.GetSize() != 0)) { // this value is not at root
476 Level* level = level_stack_.template Top<Level>();
477 if (level->valueCount > 0) {
478 if (level->inArray)
479 os_->Put(','); // add comma if it is not the first element in array
480 else // in object
481 os_->Put((level->valueCount % 2 == 0) ? ',' : ':');
482 }
483 if (!level->inArray && level->valueCount % 2 == 0)
484 RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
485 level->valueCount++;
486 }
487 else {
488 RAPIDJSON_ASSERT(!hasRoot_); // Should only has one and only one root.
489 hasRoot_ = true;
490 }
491 }
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition rapidjson.h:468
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 }

◆ 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

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.

Definition at line 271 of file writer.h.

271 {
273 Prefix(type);
275 }
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

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();
Writer(OutputStream &os, StackAllocator *stackAllocator=0, size_t levelDepth=kDefaultLevelDepth)
Constructor.
Definition writer.h:101

Definition at line 133 of file writer.h.

133 {
134 os_ = &os;
135 hasRoot_ = false;
136 level_stack_.Clear();
137 }
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

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 {
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.

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.

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

Simpler but slower overload.

Definition at line 258 of file writer.h.

258{ return String(str, internal::StrLen(str)); }
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 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.

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

◆ 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 caller graph for this function:

◆ WriteDouble() [1/2]

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

Definition at line 546 of file writer.h.

546 {
548 // Note: This code path can only be reached if (RAPIDJSON_WRITE_DEFAULT_FLAGS & kWriteNanAndInfFlag).
550 return false;
551 if (internal::Double(d).IsNan()) {
552 PutReserve(*os_, 3);
553 PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
554 return true;
555 }
556 if (internal::Double(d).Sign()) {
557 PutReserve(*os_, 9);
558 PutUnsafe(*os_, '-');
559 }
560 else
561 PutReserve(*os_, 8);
562 PutUnsafe(*os_, 'I'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'f');
563 PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y');
564 return true;
565 }
566
567 char *buffer = os_->Push(25);
569 os_->Pop(static_cast<size_t>(25 - (end - buffer)));
570 return true;
571}
char * dtoa(double value, char *buffer, int maxDecimalPlaces=324)
Definition dtoa.h:216

◆ WriteDouble() [2/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 {
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];
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 }
Here is the caller 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]

bool Writer< StringBuffer >::WriteInt ( int i)
inlineprotected

Definition at line 514 of file writer.h.

514 {
515 char *buffer = os_->Push(11);
516 const char* end = internal::i32toa(i, buffer);
517 os_->Pop(static_cast<size_t>(11 - (end - buffer)));
518 return true;
519}
char * i32toa(int32_t value, char *buffer)
Definition itoa.h:115

◆ WriteInt() [2/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 }
Here is the caller graph for this function:

◆ WriteInt64() [1/2]

bool Writer< StringBuffer >::WriteInt64 ( int64_t i64)
inlineprotected

Definition at line 530 of file writer.h.

530 {
531 char *buffer = os_->Push(21);
532 const char* end = internal::i64toa(i64, buffer);
533 os_->Pop(static_cast<size_t>(21 - (end - buffer)));
534 return true;
535}
char * i64toa(int64_t value, char *buffer)
Definition itoa.h:295

◆ WriteInt64() [2/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 }
Here is the caller 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 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.

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
391 PutReserve(*os_, 2 + length * 6); // "\uxxxx..."
392 else
393 PutReserve(*os_, 2 + length * 12); // "\uxxxx\uyyyy..."
394
395 PutUnsafe(*os_, '\"');
398 const Ch c = is.Peek();
399 if (!TargetEncoding::supportUnicode && static_cast<unsigned>(c) >= 0x80) {
400 // Unicode escaping
401 unsigned 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 }
444 return false;
445 }
446 PutUnsafe(*os_, '\"');
447 return true;
448 }
bool ScanWriteUnescapedString(GenericStringStream< SourceEncoding > &is, size_t length)
Definition writer.h:450
Here is the caller graph for this function:

◆ WriteUint() [1/2]

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

Definition at line 522 of file writer.h.

522 {
523 char *buffer = os_->Push(10);
524 const char* end = internal::u32toa(u, buffer);
525 os_->Pop(static_cast<size_t>(10 - (end - buffer)));
526 return true;
527}
char * u32toa(uint32_t value, char *buffer)
Definition itoa.h:39

◆ WriteUint() [2/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 }
Here is the caller graph for this function:

◆ WriteUint64() [1/2]

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

Definition at line 538 of file writer.h.

538 {
539 char *buffer = os_->Push(20);
540 const char* end = internal::u64toa(u, buffer);
541 os_->Pop(static_cast<size_t>(20 - (end - buffer)));
542 return true;
543}
char * u64toa(uint64_t value, char *buffer)
Definition itoa.h:126

◆ 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 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 503 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 501 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 502 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 500 of file writer.h.


The documentation for this class was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/external/rapidjson/include/rapidjson/fwd.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/external/rapidjson/include/rapidjson/writer.h