DeepCover Embedded Security in IoT: Public-key Secured Data Paths

Dependencies:   MaximInterface

Embed: (wiki syntax)

« Back to documentation index

PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags > Class Template Reference

PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags > Class Template Reference

Writer with indentation and spacing. More...

#include <prettywriter.h>

Inherits Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >.

Public Member Functions

 PrettyWriter (OutputStream &os, StackAllocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth)
 Constructor.
PrettyWriterSetIndent (Ch indentChar, unsigned indentCharCount)
 Set custom indentation.
PrettyWriterSetFormatOptions (PrettyFormatOptions options)
 Set pretty writer formatting options.
bool RawValue (const Ch *json, size_t length, Type type)
 Write a raw JSON value.
void Reset (OutputStream &os)
 Reset the writer with a new stream.
bool IsComplete () const
 Checks whether the output is a complete JSON.
void SetMaxDecimalPlaces (int maxDecimalPlaces)
 Sets the maximum number of decimal places for double output.
bool RawValue (const Ch *json, size_t length, Type type)
 Write a raw JSON value.
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 String (const std::basic_string< Ch > &str)
bool StartObject ()
bool Key (const Ch *str, SizeType length, bool copy=false)
bool Key (const std::basic_string< Ch > &str)
bool EndObject (SizeType memberCount=0)
bool StartArray ()
bool EndArray (SizeType memberCount=0)
Convenience extensions
bool String (const Ch *str)
 Simpler but slower overload.
bool Key (const Ch *str)
Implementation of Handler
See also:
Handler
bool RawNumber (const Ch *str, SizeType length, bool copy=false)
bool String (const Ch *str, SizeType length, bool copy=false)
bool String (const std::basic_string< Ch > &str)
bool Key (const Ch *str, SizeType length, bool copy=false)
Convenience extensions
bool String (const Ch *str)
 Simpler but slower overload.
bool Key (const Ch *str)

Detailed Description

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

Writer with indentation and spacing.

Template Parameters:
OutputStreamType of ouptut os.
SourceEncodingEncoding of source string.
TargetEncodingEncoding of output stream.
StackAllocatorType of allocator for allocating memory of stack.

Definition at line 48 of file prettywriter.h.


Constructor & Destructor Documentation

PrettyWriter ( OutputStream &  os,
StackAllocator *  allocator = 0,
size_t  levelDepth = Base::kDefaultLevelDepth 
) [explicit]

Constructor.

Parameters:
osOutput stream.
allocatorUser supplied allocator. If it is null, it will create a private one.
levelDepthInitial capacity of stack.

Definition at line 58 of file prettywriter.h.


Member Function Documentation

bool Double ( double  d )

Writes the given double value to the stream.

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

Reimplemented from Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >.

Definition at line 101 of file prettywriter.h.

bool IsComplete (  ) const [inherited]

Checks whether the output is a complete JSON.

A complete JSON has a complete root object or array.

Definition at line 142 of file writer.h.

bool RawValue ( const Ch *  json,
size_t  length,
Type  type 
) [inherited]

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 262 of file 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:
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.
Note:
When using PrettyWriter::RawValue(), the result json may not be indented correctly.

Definition at line 199 of file prettywriter.h.

void Reset ( OutputStream &  os ) [inherited]

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<OutputStream> writer(os1);
        writer.StartObject();
        // ...
        writer.EndObject();

        writer.Reset(os2);
        writer.StartObject();
        // ...
        writer.EndObject();

Definition at line 132 of file writer.h.

PrettyWriter& SetFormatOptions ( PrettyFormatOptions  options )

Set pretty writer formatting options.

Parameters:
optionsFormatting options.

Definition at line 85 of file prettywriter.h.

PrettyWriter& SetIndent ( Ch  indentChar,
unsigned  indentCharCount 
)

Set custom indentation.

Parameters:
indentCharCharacter for indentation. Must be whitespace character (' ', '\t', '\n', '\r').
indentCharCountNumber of indent characters for each indentation level.
Note:
The default indentation is 4 spaces.

Definition at line 75 of file prettywriter.h.

void SetMaxDecimalPlaces ( int  maxDecimalPlaces ) [inherited]

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

bool String ( const Ch *  str ) [inherited]

Simpler but slower overload.

Definition at line 249 of file writer.h.

bool String ( const Ch *  str )

Simpler but slower overload.

Definition at line 185 of file prettywriter.h.