template <typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
class Writer
Defined at line 90 of file ../../third_party/rapidjson/include/rapidjson/writer.h
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
Public Members
static const int kDefaultMaxDecimalPlaces
static const size_t kDefaultLevelDepth
Protected Members
OutputStream * os_
internal::Stack<StackAllocator> level_stack_
int maxDecimalPlaces_
bool hasRoot_
Public Methods
void Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> (OutputStream & os, StackAllocator * stackAllocator, size_t levelDepth)
Constructor
Parameters
Defined at line 101 of file ../../third_party/rapidjson/include/rapidjson/writer.h
void Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> (StackAllocator * allocator, size_t levelDepth)
Defined at line 105 of file ../../third_party/rapidjson/include/rapidjson/writer.h
void Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> (Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> && rhs)
Defined at line 110 of file ../../third_party/rapidjson/include/rapidjson/writer.h
void Reset (OutputStream & os)
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
Code
Writer<OutputStream> writer(os1);
writer.StartObject();
// ...
writer.EndObject();
writer.Reset(os2);
writer.StartObject();
// ...
writer.EndObject();
Defined at line 134 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool IsComplete ()
Checks whether the output is a complete JSON.
A complete JSON has a complete root object or array.
Defined at line 144 of file ../../third_party/rapidjson/include/rapidjson/writer.h
int GetMaxDecimalPlaces ()
Defined at line 148 of file ../../third_party/rapidjson/include/rapidjson/writer.h
void SetMaxDecimalPlaces (int maxDecimalPlaces)
Sets the maximum number of decimal places for double output.
This setting truncates the output with specified number of decimal places.
For example,
The default setting does not truncate any decimal places. You can restore to this setting by calling
Code
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();
writer.SetMaxDecimalPlaces(Writer::kDefaultMaxDecimalPlaces);
Defined at line 173 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool Null ()
@
{
Defined at line 182 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool Bool (bool b)
Defined at line 183 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool Int (int i)
Defined at line 184 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool Uint (unsigned int u)
Defined at line 185 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool Int64 (int64_t i64)
Defined at line 186 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool Uint64 (uint64_t u64)
Defined at line 187 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool Double (double d)
Writes the given
value to the stream
Parameters
Returns
Whether it is succeed.
Defined at line 194 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool RawNumber (const Ch * str, SizeType length, bool copy)
Defined at line 196 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool String (const Ch * str, SizeType length, bool copy)
Defined at line 203 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool String (const std::basic_string<Ch> & str)
Defined at line 211 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool StartObject ()
Defined at line 216 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool Key (const Ch * str, SizeType length, bool copy)
Defined at line 222 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool Key (const std::basic_string<Ch> & str)
Defined at line 225 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool EndObject (SizeType memberCount)
Defined at line 231 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool StartArray ()
Defined at line 240 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool EndArray (SizeType elementCount)
Defined at line 246 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool String (const Ch *const & str)
Simpler but slower overload.
Defined at line 259 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool Key (const Ch *const & str)
Defined at line 260 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool RawValue (const Ch * json, size_t length, Type type)
Write a raw JSON value.
For user to write a stringified JSON as a value.
Parameters
Defined at line 272 of file ../../third_party/rapidjson/include/rapidjson/writer.h
void Flush ()
Flush the output stream.
Allows the user to flush the output stream immediately.
Defined at line 282 of file ../../third_party/rapidjson/include/rapidjson/writer.h
Protected Methods
bool WriteNull ()
Defined at line 296 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool WriteBool (bool b)
Defined at line 301 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool WriteInt (int i)
Defined at line 313 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool WriteUint (unsigned int u)
Defined at line 322 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool WriteInt64 (int64_t i64)
Defined at line 331 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool WriteUint64 (uint64_t u64)
Defined at line 340 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool WriteDouble (double d)
Defined at line 349 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool WriteString (const Ch * str, SizeType length)
Defined at line 377 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool ScanWriteUnescapedString (GenericStringStream<SourceEncoding> & is, size_t length)
Defined at line 451 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool WriteStartObject ()
Defined at line 455 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool WriteEndObject ()
Defined at line 456 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool WriteStartArray ()
Defined at line 457 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool WriteEndArray ()
Defined at line 458 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool WriteRawValue (const Ch * json, size_t length)
Defined at line 460 of file ../../third_party/rapidjson/include/rapidjson/writer.h
void Prefix (Type type)
Defined at line 473 of file ../../third_party/rapidjson/include/rapidjson/writer.h
bool EndValue (bool ret)
Flush the value if it is the top level one.
Defined at line 494 of file ../../third_party/rapidjson/include/rapidjson/writer.h