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

Wrapper around rapidjson::Writer for writing objects to JSON. More...

#include <CesiumJsonWriter/JsonWriter.h>

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

Public Member Functions

virtual bool Null ()
 Writes a null value to the output.
 
virtual bool Bool (bool b)
 Writes a boolean value to the output.
 
virtual bool Int (int i)
 Writes a signed integer value to the output.
 
virtual bool Uint (unsigned int i)
 Writes an unsigned integer value to the output.
 
virtual bool Uint64 (std::uint64_t i)
 Writes an unsigned 64-bit integer value to the output.
 
virtual bool Int64 (std::int64_t i)
 Writes an signed 64-bit integer value to the output.
 
virtual bool Double (double d)
 Writes a 64-bit floating point value to the output.
 
virtual bool RawNumber (const char *str, unsigned int length, bool copy)
 Writes the given string as a number to the output without any kind of special handling.
 
virtual bool Key (std::string_view string)
 Writes the given string as an object key to the output.
 
virtual bool String (std::string_view string)
 Writes the given string as a value to the output.
 
virtual bool StartObject ()
 Writes the start of a JSON object to the output.
 
virtual bool EndObject ()
 Writes the end of a JSON object to the output.
 
virtual bool StartArray ()
 Writes the start of a JSON array to the output.
 
virtual bool EndArray ()
 Writes the end of a JSON array to the output.
 
virtual void Primitive (std::int32_t value)
 Writes the given primitive to the output. This is a convenience function for Int.
 
virtual void Primitive (std::uint32_t value)
 Writes the given primitive to the output. This is a convenience function for Uint.
 
virtual void Primitive (std::int64_t value)
 Writes the given primitive to the output. This is a convenience function for Int64.
 
virtual void Primitive (std::uint64_t value)
 Writes the given primitive to the output. This is a convenience function for Uint64.
 
virtual void Primitive (float value)
 Writes the given primitive to the output. This is a convenience function for Double.
 
virtual void Primitive (double value)
 Writes the given primitive to the output. This is a convenience function for Double.
 
virtual void Primitive (std::nullptr_t value)
 Writes the given primitive to the output. This is a convenience function for Null.
 
virtual void Primitive (std::string_view string)
 Writes the given primitive to the output. This is a convenience function for String.
 
virtual void KeyPrimitive (std::string_view keyName, std::int32_t value)
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Int.
 
virtual void KeyPrimitive (std::string_view keyName, std::uint32_t value)
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Uint.
 
virtual void KeyPrimitive (std::string_view keyName, std::int64_t value)
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Int64.
 
virtual void KeyPrimitive (std::string_view keyName, std::uint64_t value)
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Uint64.
 
virtual void KeyPrimitive (std::string_view keyName, std::string_view value)
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by String.
 
virtual void KeyPrimitive (std::string_view keyName, float value)
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Double.
 
virtual void KeyPrimitive (std::string_view keyName, double value)
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Double.
 
virtual void KeyPrimitive (std::string_view keyName, std::nullptr_t value)
 Writes the given key and its corresponding value primitive to the output. This is a convenience function for calling Key followed by Null.
 
virtual void KeyArray (std::string_view keyName, std::function< void(void)> insideArray)
 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.
 
virtual void KeyObject (std::string_view keyName, std::function< void(void)> insideObject)
 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.
 
virtual std::string toString ()
 Obtains the written output as a string.
 
virtual std::string_view toStringView ()
 Obtains the written output as a string_view.
 
virtual std::vector< std::byte > toBytes ()
 Obtains the written output as a buffer of bytes.
 
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

Wrapper around rapidjson::Writer for writing objects to JSON.

Definition at line 18 of file JsonWriter.h.

Constructor & Destructor Documentation

◆ ~JsonWriter()

virtual CesiumJsonWriter::JsonWriter::~JsonWriter ( )
inlinevirtual

Definition at line 21 of file JsonWriter.h.

Member Function Documentation

◆ Bool()

virtual bool CesiumJsonWriter::JsonWriter::Bool ( bool b)
virtual

Writes a boolean value to the output.

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

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ Double()

virtual bool CesiumJsonWriter::JsonWriter::Double ( double d)
virtual

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

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

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ emplaceError()

template<typename ErrorStr >
void CesiumJsonWriter::JsonWriter::emplaceError ( ErrorStr && error)
inline

Emplaces a new error into the internal error buffer.

Definition at line 268 of file JsonWriter.h.

◆ emplaceWarning()

template<typename WarningStr >
void CesiumJsonWriter::JsonWriter::emplaceWarning ( WarningStr && warning)
inline

Emplaces a new warning into the internal warning buffer.

Definition at line 275 of file JsonWriter.h.

◆ EndArray()

virtual bool CesiumJsonWriter::JsonWriter::EndArray ( )
virtual

Writes the end of a JSON array to the output.

Returns
True if the write was successful.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ EndObject()

virtual bool CesiumJsonWriter::JsonWriter::EndObject ( )
virtual

Writes the end of a JSON object to the output.

Returns
True if the write was successful.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ getErrors()

const std::vector< std::string > & CesiumJsonWriter::JsonWriter::getErrors ( ) const
inline

Obtains the current error buffer.

Definition at line 282 of file JsonWriter.h.

◆ getWarnings()

const std::vector< std::string > & CesiumJsonWriter::JsonWriter::getWarnings ( ) const
inline

Obtains the current warning buffer.

Definition at line 286 of file JsonWriter.h.

◆ Int()

virtual bool CesiumJsonWriter::JsonWriter::Int ( int i)
virtual

Writes a signed integer value to the output.

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

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ Int64()

virtual bool CesiumJsonWriter::JsonWriter::Int64 ( std::int64_t i)
virtual

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

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

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ Key()

virtual bool CesiumJsonWriter::JsonWriter::Key ( std::string_view string)
virtual

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

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

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ KeyArray()

virtual void CesiumJsonWriter::JsonWriter::KeyArray ( std::string_view keyName,
std::function< void(void)> insideArray )
virtual

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 in CesiumJsonWriter::PrettyJsonWriter.

◆ KeyObject()

virtual void CesiumJsonWriter::JsonWriter::KeyObject ( std::string_view keyName,
std::function< void(void)> insideObject )
virtual

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 in CesiumJsonWriter::PrettyJsonWriter.

◆ KeyPrimitive() [1/8]

virtual void CesiumJsonWriter::JsonWriter::KeyPrimitive ( std::string_view keyName,
double value )
virtual

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 in CesiumJsonWriter::PrettyJsonWriter.

◆ KeyPrimitive() [2/8]

virtual void CesiumJsonWriter::JsonWriter::KeyPrimitive ( std::string_view keyName,
float value )
virtual

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 in CesiumJsonWriter::PrettyJsonWriter.

◆ KeyPrimitive() [3/8]

virtual void CesiumJsonWriter::JsonWriter::KeyPrimitive ( std::string_view keyName,
std::int32_t value )
virtual

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 in CesiumJsonWriter::PrettyJsonWriter.

◆ KeyPrimitive() [4/8]

virtual void CesiumJsonWriter::JsonWriter::KeyPrimitive ( std::string_view keyName,
std::int64_t value )
virtual

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 in CesiumJsonWriter::PrettyJsonWriter.

◆ KeyPrimitive() [5/8]

virtual void CesiumJsonWriter::JsonWriter::KeyPrimitive ( std::string_view keyName,
std::nullptr_t value )
virtual

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 in CesiumJsonWriter::PrettyJsonWriter.

◆ KeyPrimitive() [6/8]

virtual void CesiumJsonWriter::JsonWriter::KeyPrimitive ( std::string_view keyName,
std::string_view value )
virtual

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 in CesiumJsonWriter::PrettyJsonWriter.

◆ KeyPrimitive() [7/8]

virtual void CesiumJsonWriter::JsonWriter::KeyPrimitive ( std::string_view keyName,
std::uint32_t value )
virtual

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 in CesiumJsonWriter::PrettyJsonWriter.

◆ KeyPrimitive() [8/8]

virtual void CesiumJsonWriter::JsonWriter::KeyPrimitive ( std::string_view keyName,
std::uint64_t value )
virtual

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 in CesiumJsonWriter::PrettyJsonWriter.

◆ Null()

virtual bool CesiumJsonWriter::JsonWriter::Null ( )
virtual

Writes a null value to the output.

Returns
True if the write was successful.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ Primitive() [1/8]

virtual void CesiumJsonWriter::JsonWriter::Primitive ( double value)
virtual

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

Parameters
valueThe double value to write.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ Primitive() [2/8]

virtual void CesiumJsonWriter::JsonWriter::Primitive ( float value)
virtual

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

Parameters
valueThe float value to write.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ Primitive() [3/8]

virtual void CesiumJsonWriter::JsonWriter::Primitive ( std::int32_t value)
virtual

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

Parameters
valueThe int32_t value to write.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ Primitive() [4/8]

virtual void CesiumJsonWriter::JsonWriter::Primitive ( std::int64_t value)
virtual

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

Parameters
valueThe int64_t value to write.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ Primitive() [5/8]

virtual void CesiumJsonWriter::JsonWriter::Primitive ( std::nullptr_t value)
virtual

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

Parameters
valueThe null value to write.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ Primitive() [6/8]

virtual void CesiumJsonWriter::JsonWriter::Primitive ( std::string_view string)
virtual

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

Parameters
stringThe string value to write.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ Primitive() [7/8]

virtual void CesiumJsonWriter::JsonWriter::Primitive ( std::uint32_t value)
virtual

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

Parameters
valueThe uint32_t value to write.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ Primitive() [8/8]

virtual void CesiumJsonWriter::JsonWriter::Primitive ( std::uint64_t value)
virtual

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

Parameters
valueThe uint64_t value to write.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ RawNumber()

virtual bool CesiumJsonWriter::JsonWriter::RawNumber ( const char * str,
unsigned int length,
bool copy )
virtual

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 in CesiumJsonWriter::PrettyJsonWriter.

◆ StartArray()

virtual bool CesiumJsonWriter::JsonWriter::StartArray ( )
virtual

Writes the start of a JSON array to the output.

Returns
True if the write was successful.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ StartObject()

virtual bool CesiumJsonWriter::JsonWriter::StartObject ( )
virtual

Writes the start of a JSON object to the output.

Returns
True if the write was successful.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ String()

virtual bool CesiumJsonWriter::JsonWriter::String ( std::string_view string)
virtual

Writes the given string as a value to the output.

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

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ toBytes()

virtual std::vector< std::byte > CesiumJsonWriter::JsonWriter::toBytes ( )
virtual

Obtains the written output as a buffer of bytes.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ toString()

virtual std::string CesiumJsonWriter::JsonWriter::toString ( )
virtual

Obtains the written output as a string.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ toStringView()

virtual std::string_view CesiumJsonWriter::JsonWriter::toStringView ( )
virtual

Obtains the written output as a string_view.

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ Uint()

virtual bool CesiumJsonWriter::JsonWriter::Uint ( unsigned int i)
virtual

Writes an unsigned integer value to the output.

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

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.

◆ Uint64()

virtual bool CesiumJsonWriter::JsonWriter::Uint64 ( std::uint64_t i)
virtual

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

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

Reimplemented in CesiumJsonWriter::PrettyJsonWriter.


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