![]() |
ezEngine Release 26.9
|
The base class for JSON writers. More...
#include <JSONWriter.h>

Public Types | |
| enum class | WhitespaceMode { All , LessIndentation , NoIndentation , NewlinesOnly , None } |
| Modes to configure how much whitespace the JSON writer will output. More... | |
| enum class | ArrayMode { InOneLine , OneLinePerItem } |
| Modes to configure how arrays are written. More... | |
Public Member Functions | |
| ezJSONWriter () | |
| Constructor. | |
| virtual | ~ezJSONWriter () |
| Destructor. | |
| void | SetWhitespaceMode (WhitespaceMode whitespaceMode) |
| Configures how much whitespace is output. | |
| void | SetArrayMode (ArrayMode arrayMode) |
| Configures how arrays are written. | |
| void | AddVariableBool (ezStringView sName, bool value) |
| Shorthand for "BeginVariable(szName); WriteBool(value); EndVariable(); ". | |
| void | AddVariableInt32 (ezStringView sName, ezInt32 value) |
| Shorthand for "BeginVariable(szName); WriteInt32(value); EndVariable(); ". | |
| void | AddVariableUInt32 (ezStringView sName, ezUInt32 value) |
| Shorthand for "BeginVariable(szName); WriteUInt32(value); EndVariable(); ". | |
| void | AddVariableInt64 (ezStringView sName, ezInt64 value) |
| Shorthand for "BeginVariable(szName); WriteInt64(value); EndVariable(); ". | |
| void | AddVariableUInt64 (ezStringView sName, ezUInt64 value) |
| Shorthand for "BeginVariable(szName); WriteUInt64(value); EndVariable(); ". | |
| void | AddVariableFloat (ezStringView sName, float value) |
| Shorthand for "BeginVariable(szName); WriteFloat(value); EndVariable(); ". | |
| void | AddVariableDouble (ezStringView sName, double value) |
| Shorthand for "BeginVariable(szName); WriteDouble(value); EndVariable(); ". | |
| void | AddVariableString (ezStringView sName, ezStringView value) |
| Shorthand for "BeginVariable(szName); WriteString(value); EndVariable(); ". | |
| void | AddVariableNULL (ezStringView sName) |
| Shorthand for "BeginVariable(szName); WriteNULL(value); EndVariable(); ". | |
| void | AddVariableTime (ezStringView sName, ezTime value) |
| Shorthand for "BeginVariable(szName); WriteTime(value); EndVariable(); ". | |
| void | AddVariableUuid (ezStringView sName, ezUuid value) |
| Shorthand for "BeginVariable(szName); WriteUuid(value); EndVariable(); ". | |
| void | AddVariableAngle (ezStringView sName, ezAngle value) |
| Shorthand for "BeginVariable(szName); WriteAngle(value); EndVariable(); ". | |
| void | AddVariableColor (ezStringView sName, const ezColor &value) |
| Shorthand for "BeginVariable(szName); WriteColor(value); EndVariable(); ". | |
| void | AddVariableColorGamma (ezStringView sName, const ezColorGammaUB &value) |
| Shorthand for "BeginVariable(szName); WriteColorGamma(value); EndVariable(); ". | |
| void | AddVariableVec2 (ezStringView sName, const ezVec2 &value) |
| Shorthand for "BeginVariable(szName); WriteVec2(value); EndVariable(); ". | |
| void | AddVariableVec3 (ezStringView sName, const ezVec3 &value) |
| Shorthand for "BeginVariable(szName); WriteVec3(value); EndVariable(); ". | |
| void | AddVariableVec4 (ezStringView sName, const ezVec4 &value) |
| Shorthand for "BeginVariable(szName); WriteVec4(value); EndVariable(); ". | |
| void | AddVariableVec2I32 (ezStringView sName, const ezVec2I32 &value) |
| Shorthand for "BeginVariable(szName); WriteVec2I32(value); EndVariable(); ". | |
| void | AddVariableVec3I32 (ezStringView sName, const ezVec3I32 &value) |
| Shorthand for "BeginVariable(szName); WriteVec3I32(value); EndVariable(); ". | |
| void | AddVariableVec4I32 (ezStringView sName, const ezVec4I32 &value) |
| Shorthand for "BeginVariable(szName); WriteVec4I32(value); EndVariable(); ". | |
| void | AddVariableQuat (ezStringView sName, const ezQuat &value) |
| Shorthand for "BeginVariable(szName); WriteQuat(value); EndVariable(); ". | |
| void | AddVariableMat3 (ezStringView sName, const ezMat3 &value) |
| Shorthand for "BeginVariable(szName); WriteMat3(value); EndVariable(); ". | |
| void | AddVariableMat4 (ezStringView sName, const ezMat4 &value) |
| Shorthand for "BeginVariable(szName); WriteMat4(value); EndVariable(); ". | |
| void | AddVariableDataBuffer (ezStringView sName, const ezDataBuffer &value) |
| Shorthand for "BeginVariable(szName); WriteDataBuffer(value); EndVariable(); ". | |
| void | AddVariableVariant (ezStringView sName, const ezVariant &value) |
| Shorthand for "BeginVariable(szName); WriteVariant(value); EndVariable(); ". | |
| virtual void | WriteBool (bool value)=0 |
| Writes a bool to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteInt32 (ezInt32 value)=0 |
| Writes an int32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteUInt32 (ezUInt32 value)=0 |
| Writes a uint32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteInt64 (ezInt64 value)=0 |
| Writes an int64 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteUInt64 (ezUInt64 value)=0 |
| Writes a uint64 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteFloat (float value)=0 |
| Writes a float to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteDouble (double value)=0 |
| Writes a double to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteString (ezStringView value)=0 |
| Writes a string to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteNULL ()=0 |
| Writes the value 'null' to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteTime (ezTime value)=0 |
| Writes a time value to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteColor (const ezColor &value)=0 |
| Writes an ezColor to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteColorGamma (const ezColorGammaUB &value)=0 |
| Writes an ezColorGammaUB to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteVec2 (const ezVec2 &value)=0 |
| Writes an ezVec2 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteVec3 (const ezVec3 &value)=0 |
| Writes an ezVec3 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteVec4 (const ezVec4 &value)=0 |
| Writes an ezVec4 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteVec2I32 (const ezVec2I32 &value)=0 |
| Writes an ezVec2I32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteVec3I32 (const ezVec3I32 &value)=0 |
| Writes an ezVec3I32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteVec4I32 (const ezVec4I32 &value)=0 |
| Writes an ezVec4I32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteQuat (const ezQuat &value)=0 |
| Writes an ezQuat to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteMat3 (const ezMat3 &value)=0 |
| Writes an ezMat3 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteMat4 (const ezMat4 &value)=0 |
| Writes an ezMat4 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteUuid (const ezUuid &value)=0 |
| Writes an ezUuid to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteAngle (ezAngle value)=0 |
| Writes an ezAngle to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteDataBuffer (const ezDataBuffer &value)=0 |
| Writes an ezDataBuffer to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
| virtual void | WriteVariant (const ezVariant &value) |
| The default implementation dispatches all supported types to WriteBool, WriteInt32, etc. and asserts on the more complex types. | |
| virtual void | WriteBinaryData (ezStringView sDataType, const void *pData, ezUInt32 uiBytes, ezStringView sValueString=nullptr)=0 |
| Outputs a chunk of memory in some JSON form that can be interpreted as binary data when reading it again. | |
| virtual void | BeginVariable (ezStringView sName)=0 |
| Begins outputting a variable. szName is the variable name. | |
| virtual void | EndVariable ()=0 |
| Ends outputting a variable. | |
| virtual void | BeginArray (ezStringView sName=nullptr)=0 |
| Begins outputting an array variable. | |
| virtual void | EndArray ()=0 |
| Ends outputting an array variable. | |
| virtual void | BeginObject (ezStringView sName=nullptr)=0 |
| Begins outputting an object variable. | |
| virtual void | EndObject ()=0 |
| Ends outputting an object variable. | |
| bool | HadWriteError () const |
| Indicates if an error was encountered while writing. | |
| void | Abandon () |
| Gives up on the output, so that the writer may be destroyed with containers still open. | |
Protected Member Functions | |
| void | SetWriteErrorState () |
| called internally when there was an error during writing | |
Protected Attributes | |
| WhitespaceMode | m_WhitespaceMode = WhitespaceMode::All |
| ArrayMode | m_ArrayMode = ArrayMode::InOneLine |
The base class for JSON writers.
Declares a common interface for writing JSON files. Also implements some utility functions built on top of the interface (AddVariable()).
|
strong |
|
strong |
Modes to configure how much whitespace the JSON writer will output.
|
inline |
Gives up on the output, so that the writer may be destroyed with containers still open.
Derived writers are allowed to assert on destruction that every BeginObject() / BeginArray() was matched, because an unbalanced stream is usually a bug. That check makes an early return between Begin and End fatal, which is a problem for code that discovers half way through writing that it cannot continue - a failed lookup, an object that turned out to be invalid.
Calling this marks the output as unusable and suppresses that check. The written text is not valid JSON afterwards and must not be used. To bail out and still produce usable output, use ezStandardJSONWriter::EndAll() instead.
|
pure virtual |
Begins outputting an array variable.
If szName is nullptr this will create an anonymous array, which is necessary when you want to put an array as a value into another array. BeginArray() with a non-nullptr value for szName is identical to calling BeginVariable() first. In this case EndArray() will also end the variable definition, so no additional call to EndVariable() is required.
Implemented in ezStandardJSONWriter.
|
pure virtual |
Begins outputting an object variable.
If szName is nullptr this will create an anonymous object, which is necessary when you want to put an object as a value into an array. BeginObject() with a non-nullptr value for szName is identical to calling BeginVariable() first. In this case EndObject() will also end the variable definition, so no additional call to EndVariable() is required.
Implemented in ezStandardJSONWriter.
|
pure virtual |
Begins outputting a variable. szName is the variable name.
Between BeginVariable() and EndVariable() you can call the WriteXYZ functions once to write out the variable's data. You can also call BeginArray() and BeginObject() without a variable name to output an array or object variable.
Implemented in ezStandardJSONWriter.
|
pure virtual |
Ends outputting an array variable.
Implemented in ezStandardJSONWriter.
|
pure virtual |
Ends outputting an object variable.
Implemented in ezStandardJSONWriter.
|
pure virtual |
Ends outputting a variable.
Implemented in ezStandardJSONWriter.
| bool ezJSONWriter::HadWriteError | ( | ) | const |
Indicates if an error was encountered while writing.
If any error was encountered at any time during writing, this will return true
|
pure virtual |
Writes an ezAngle to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Outputs a chunk of memory in some JSON form that can be interpreted as binary data when reading it again.
How exactly the raw data is represented in JSON is up to the derived class. szDataType allows to additionally output a string that identifies the type of data.
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes a bool to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an ezColor to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an ezColorGammaUB to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an ezDataBuffer to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes a double to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes a float to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an int32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an int64 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an ezMat3 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an ezMat4 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes the value 'null' to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an ezQuat to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes a string to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes a time value to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes a uint32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes a uint64 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an ezUuid to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
virtual |
The default implementation dispatches all supported types to WriteBool, WriteInt32, etc. and asserts on the more complex types.
A derived class may override this function to implement support for the remaining variant types, if required.
Reimplemented in ezMcpJsonWriter.
|
pure virtual |
Writes an ezVec2 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an ezVec2I32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an ezVec3 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an ezVec3I32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an ezVec4 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.
|
pure virtual |
Writes an ezVec4I32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implemented in ezStandardJSONWriter.