cesium-native 0.43.0
Loading...
Searching...
No Matches
CesiumJsonWriter::PrettyJsonWriter Class Reference

Implementation of JsonWriter that "pretty-prints" JSON to the output, formatted with new lines and indentation. More...

#include <CesiumJsonWriter/PrettyJsonWriter.h>

Inheritance diagram for CesiumJsonWriter::PrettyJsonWriter:
CesiumJsonWriter::JsonWriter

Public Member Functions

bool Null () override
 Writes a null value to the output.
 
bool Bool (bool b) override
 Writes a boolean value to the output.
 
bool Int (int i) override
 Writes a signed integer value to the output.
 
bool Uint (unsigned int i) override
 Writes an unsigned integer value to the output.
 
bool Uint64 (std::uint64_t i) override
 Writes an unsigned 64-bit integer value to the output.
 
bool Int64 (std::int64_t i) override
 Writes an signed 64-bit integer value to the output.
 
bool Double (double d) override
 Writes a 64-bit floating point value to the output.
 
bool RawNumber (const char *str, unsigned int length, bool copy) override
 Writes the given string as a number to the output without any kind of special handling.
 
bool Key (std::string_view string) override
 Writes the given string as an object key to the output.
 
bool String (std::string_view string) override
 Writes the given string as a value to the output.
 
bool StartObject () override
 Writes the start of a JSON object to the output.
 
bool EndObject () override
 Writes the end of a JSON object to the output.
 
bool StartArray () override
 Writes the start of a JSON array to the output.
 
bool EndArray () override
 Writes the end of a JSON array to the output.
 
void Primitive (std::int32_t value) override
 Writes the given primitive to the output. This is a convenience function for Int.
 
void Primitive (std::uint32_t value) override
 Writes the given primitive to the output. This is a convenience function for Uint.
 
void Primitive (std::int64_t value) override
 Writes the given primitive to the output. This is a convenience function for Int64.
 
void Primitive (std::uint64_t value) override
 Writes the given primitive to the output. This is a convenience function for Uint64.
 
void Primitive (float value) override
 Writes the given primitive to the output. This is a convenience function for Double.
 
void Primitive (double value) override
 Writes the given primitive to the output. This is a convenience function for Double.
 
void Primitive (std::nullptr_t value) override
 Writes the given primitive to the output. This is a convenience function for Null.
 
void Primitive (std::string_view string) override
 Writes the given primitive to the output. This is a convenience function for String.
 
void KeyPrimitive (std::string_view keyName, std::int32_t value) override
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Int.
 
void KeyPrimitive (std::string_view keyName, std::uint32_t value) override
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Uint.
 
void KeyPrimitive (std::string_view keyName, std::int64_t value) override
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Int64.
 
void KeyPrimitive (std::string_view keyName, std::uint64_t value) override
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Uint64.
 
void KeyPrimitive (std::string_view keyName, std::string_view value) override
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by String.
 
void KeyPrimitive (std::string_view keyName, float value) override
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Double.
 
void KeyPrimitive (std::string_view keyName, double value) override
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Double.
 
void KeyPrimitive (std::string_view keyName, std::nullptr_t value) override
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Null.
 
void KeyArray (std::string_view keyName, std::function< void(void)> insideArray) override
 Writes an array to the output with the given key and calls the provided callback to write values inside of the array. This is a convenience function for calling Key followed by StartArray followed by the values you wish to write and ending with EndArray.
 
void KeyObject (std::string_view keyName, std::function< void(void)> insideObject) override
 Writes an object to the output with the given key and calls the provided callback to write values inside of the object. This is a convenience function for calling Key followed by StartObject followed by the values you wish to write and ending with EndObject.
 
std::string toString () override
 Obtains the written output as a string.
 
std::string_view toStringView () override
 Obtains the written output as a string_view.
 
std::vector< std::byte > toBytes () override
 Obtains the written output as a buffer of bytes.
 
- Public Member Functions inherited from CesiumJsonWriter::JsonWriter
template<typename ErrorStr >
void emplaceError (ErrorStr &&error)
 Emplaces a new error into the internal error buffer.
 
template<typename WarningStr >
void emplaceWarning (WarningStr &&warning)
 Emplaces a new warning into the internal warning buffer.
 
const std::vector< std::string > & getErrors () const
 Obtains the current error buffer.
 
const std::vector< std::string > & getWarnings () const
 Obtains the current warning buffer.
 

Detailed Description

Implementation of JsonWriter that "pretty-prints" JSON to the output, formatted with new lines and indentation.

Definition at line 20 of file PrettyJsonWriter.h.

Constructor & Destructor Documentation

◆ ~PrettyJsonWriter()

CesiumJsonWriter::PrettyJsonWriter::~PrettyJsonWriter ( )
inline

Definition at line 26 of file PrettyJsonWriter.h.

Member Function Documentation

◆ Bool()

bool CesiumJsonWriter::PrettyJsonWriter::Bool ( bool b)
overridevirtual

Writes a boolean value to the output.

Parameters
bThe boolean value to write.
Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Double()

bool CesiumJsonWriter::PrettyJsonWriter::Double ( double d)
overridevirtual

Writes a 64-bit floating point value to the output.

Parameters
dThe double value to write.
Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ EndArray()

bool CesiumJsonWriter::PrettyJsonWriter::EndArray ( )
overridevirtual

Writes the end of a JSON array to the output.

Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ EndObject()

bool CesiumJsonWriter::PrettyJsonWriter::EndObject ( )
overridevirtual

Writes the end of a JSON object to the output.

Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Int()

bool CesiumJsonWriter::PrettyJsonWriter::Int ( int i)
overridevirtual

Writes a signed integer value to the output.

Parameters
iThe integer value to write.
Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Int64()

bool CesiumJsonWriter::PrettyJsonWriter::Int64 ( std::int64_t i)
overridevirtual

Writes an signed 64-bit integer value to the output.

Parameters
iThe integer value to write.
Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Key()

bool CesiumJsonWriter::PrettyJsonWriter::Key ( std::string_view string)
overridevirtual

Writes the given string as an object key to the output.

Parameters
stringThe key to write.
Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ KeyArray()

void CesiumJsonWriter::PrettyJsonWriter::KeyArray ( std::string_view keyName,
std::function< void(void)> insideArray )
overridevirtual

Writes an array to the output with the given key and calls the provided callback to write values inside of the array. This is a convenience function for calling Key followed by StartArray followed by the values you wish to write and ending with EndArray.

Parameters
keyNameThe key to write to the output.
insideArrayThe callback to run, after StartArray but before EndArray.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ KeyObject()

void CesiumJsonWriter::PrettyJsonWriter::KeyObject ( std::string_view keyName,
std::function< void(void)> insideObject )
overridevirtual

Writes an object to the output with the given key and calls the provided callback to write values inside of the object. This is a convenience function for calling Key followed by StartObject followed by the values you wish to write and ending with EndObject.

Parameters
keyNameThe key to write to the output.
insideObjectThe callback to run, after StartObject but before EndObject.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ KeyPrimitive() [1/8]

void CesiumJsonWriter::PrettyJsonWriter::KeyPrimitive ( std::string_view keyName,
double value )
overridevirtual

Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Double.

Parameters
keyNameThe key to write to the output.
valueThe primitive value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ KeyPrimitive() [2/8]

void CesiumJsonWriter::PrettyJsonWriter::KeyPrimitive ( std::string_view keyName,
float value )
overridevirtual

Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Double.

Parameters
keyNameThe key to write to the output.
valueThe primitive value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ KeyPrimitive() [3/8]

void CesiumJsonWriter::PrettyJsonWriter::KeyPrimitive ( std::string_view keyName,
std::int32_t value )
overridevirtual

Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Int.

Parameters
keyNameThe key to write to the output.
valueThe primitive value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ KeyPrimitive() [4/8]

void CesiumJsonWriter::PrettyJsonWriter::KeyPrimitive ( std::string_view keyName,
std::int64_t value )
overridevirtual

Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Int64.

Parameters
keyNameThe key to write to the output.
valueThe primitive value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ KeyPrimitive() [5/8]

void CesiumJsonWriter::PrettyJsonWriter::KeyPrimitive ( std::string_view keyName,
std::nullptr_t value )
overridevirtual

Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Null.

Parameters
keyNameThe key to write to the output.
valueThe primitive value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ KeyPrimitive() [6/8]

void CesiumJsonWriter::PrettyJsonWriter::KeyPrimitive ( std::string_view keyName,
std::string_view value )
overridevirtual

Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by String.

Parameters
keyNameThe key to write to the output.
valueThe primitive value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ KeyPrimitive() [7/8]

void CesiumJsonWriter::PrettyJsonWriter::KeyPrimitive ( std::string_view keyName,
std::uint32_t value )
overridevirtual

Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Uint.

Parameters
keyNameThe key to write to the output.
valueThe primitive value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ KeyPrimitive() [8/8]

void CesiumJsonWriter::PrettyJsonWriter::KeyPrimitive ( std::string_view keyName,
std::uint64_t value )
overridevirtual

Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Uint64.

Parameters
keyNameThe key to write to the output.
valueThe primitive value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Null()

bool CesiumJsonWriter::PrettyJsonWriter::Null ( )
overridevirtual

Writes a null value to the output.

Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Primitive() [1/8]

void CesiumJsonWriter::PrettyJsonWriter::Primitive ( double value)
overridevirtual

Writes the given primitive to the output. This is a convenience function for Double.

Parameters
valueThe double value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Primitive() [2/8]

void CesiumJsonWriter::PrettyJsonWriter::Primitive ( float value)
overridevirtual

Writes the given primitive to the output. This is a convenience function for Double.

Parameters
valueThe float value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Primitive() [3/8]

void CesiumJsonWriter::PrettyJsonWriter::Primitive ( std::int32_t value)
overridevirtual

Writes the given primitive to the output. This is a convenience function for Int.

Parameters
valueThe int32_t value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Primitive() [4/8]

void CesiumJsonWriter::PrettyJsonWriter::Primitive ( std::int64_t value)
overridevirtual

Writes the given primitive to the output. This is a convenience function for Int64.

Parameters
valueThe int64_t value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Primitive() [5/8]

void CesiumJsonWriter::PrettyJsonWriter::Primitive ( std::nullptr_t value)
overridevirtual

Writes the given primitive to the output. This is a convenience function for Null.

Parameters
valueThe null value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Primitive() [6/8]

void CesiumJsonWriter::PrettyJsonWriter::Primitive ( std::string_view string)
overridevirtual

Writes the given primitive to the output. This is a convenience function for String.

Parameters
stringThe string value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Primitive() [7/8]

void CesiumJsonWriter::PrettyJsonWriter::Primitive ( std::uint32_t value)
overridevirtual

Writes the given primitive to the output. This is a convenience function for Uint.

Parameters
valueThe uint32_t value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Primitive() [8/8]

void CesiumJsonWriter::PrettyJsonWriter::Primitive ( std::uint64_t value)
overridevirtual

Writes the given primitive to the output. This is a convenience function for Uint64.

Parameters
valueThe uint64_t value to write.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ RawNumber()

bool CesiumJsonWriter::PrettyJsonWriter::RawNumber ( const char * str,
unsigned int length,
bool copy )
overridevirtual

Writes the given string as a number to the output without any kind of special handling.

Parameters
strThe raw number to write directly to the output.
lengthThe length of the string.
copyIf true, the string will be copied.
Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ StartArray()

bool CesiumJsonWriter::PrettyJsonWriter::StartArray ( )
overridevirtual

Writes the start of a JSON array to the output.

Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ StartObject()

bool CesiumJsonWriter::PrettyJsonWriter::StartObject ( )
overridevirtual

Writes the start of a JSON object to the output.

Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ String()

bool CesiumJsonWriter::PrettyJsonWriter::String ( std::string_view string)
overridevirtual

Writes the given string as a value to the output.

Parameters
stringThe string to write.
Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ toBytes()

std::vector< std::byte > CesiumJsonWriter::PrettyJsonWriter::toBytes ( )
overridevirtual

Obtains the written output as a buffer of bytes.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ toString()

std::string CesiumJsonWriter::PrettyJsonWriter::toString ( )
overridevirtual

Obtains the written output as a string.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ toStringView()

std::string_view CesiumJsonWriter::PrettyJsonWriter::toStringView ( )
overridevirtual

Obtains the written output as a string_view.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Uint()

bool CesiumJsonWriter::PrettyJsonWriter::Uint ( unsigned int i)
overridevirtual

Writes an unsigned integer value to the output.

Parameters
iThe integer value to write.
Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.

◆ Uint64()

bool CesiumJsonWriter::PrettyJsonWriter::Uint64 ( std::uint64_t i)
overridevirtual

Writes an unsigned 64-bit integer value to the output.

Parameters
iThe integer value to write.
Returns
True if the write was successful.

Reimplemented from CesiumJsonWriter::JsonWriter.


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