ezEngine  Milestone 7
ezJSONWriter Class Referenceabstract

The base class for JSON writers. More...

#include <JSONWriter.h>

Inheritance diagram for ezJSONWriter:

Public Types

enum  WhitespaceMode {
  All, LessIndentation, NoIndentation, NewlinesOnly,
  None
}
 Modes to configure how much whitespace the JSON writer will output. More...
 

Public Member Functions

 ezJSONWriter ()
 Constructor.
 
void SetWhitespaceMode (WhitespaceMode wsm)
 Configures how much whitespace is output.
 
void AddVariableBool (const char *szName, bool value)
 Shorthand for "BeginVariable(szName); WriteBool(value); EndVariable(); ".
 
void AddVariableInt32 (const char *szName, ezInt32 value)
 Shorthand for "BeginVariable(szName); WriteInt32(value); EndVariable(); ".
 
void AddVariableUInt32 (const char *szName, ezUInt32 value)
 Shorthand for "BeginVariable(szName); WriteUInt32(value); EndVariable(); ".
 
void AddVariableInt64 (const char *szName, ezInt64 value)
 Shorthand for "BeginVariable(szName); WriteInt64(value); EndVariable(); ".
 
void AddVariableUInt64 (const char *szName, ezUInt64 value)
 Shorthand for "BeginVariable(szName); WriteUInt64(value); EndVariable(); ".
 
void AddVariableFloat (const char *szName, float value)
 Shorthand for "BeginVariable(szName); WriteFloat(value); EndVariable(); ".
 
void AddVariableDouble (const char *szName, double value)
 Shorthand for "BeginVariable(szName); WriteDouble(value); EndVariable(); ".
 
void AddVariableString (const char *szName, const char *value)
 Shorthand for "BeginVariable(szName); WriteString(value); EndVariable(); ".
 
void AddVariableNULL (const char *szName)
 Shorthand for "BeginVariable(szName); WriteNULL(value); EndVariable(); ".
 
void AddVariableTime (const char *szName, ezTime value)
 Shorthand for "BeginVariable(szName); WriteTime(value); EndVariable(); ".
 
void AddVariableUuid (const char *szName, ezUuid value)
 Shorthand for "BeginVariable(szName); WriteUuid(value); EndVariable(); ".
 
void AddVariableColor (const char *szName, const ezColor &value)
 Shorthand for "BeginVariable(szName); WriteColor(value); EndVariable(); ".
 
void AddVariableVec2 (const char *szName, const ezVec2 &value)
 Shorthand for "BeginVariable(szName); WriteVec2(value); EndVariable(); ".
 
void AddVariableVec3 (const char *szName, const ezVec3 &value)
 Shorthand for "BeginVariable(szName); WriteVec3(value); EndVariable(); ".
 
void AddVariableVec4 (const char *szName, const ezVec4 &value)
 Shorthand for "BeginVariable(szName); WriteVec4(value); EndVariable(); ".
 
void AddVariableQuat (const char *szName, const ezQuat &value)
 Shorthand for "BeginVariable(szName); WriteQuat(value); EndVariable(); ".
 
void AddVariableMat3 (const char *szName, const ezMat3 &value)
 Shorthand for "BeginVariable(szName); WriteMat3(value); EndVariable(); ".
 
void AddVariableMat4 (const char *szName, const ezMat4 &value)
 Shorthand for "BeginVariable(szName); WriteMat4(value); EndVariable(); ".
 
void AddVariableVariant (const char *szName, 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 (const char *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(). More...
 
virtual void WriteVec2 (const ezVec2 &value)=0
 Writes an ezVec2 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteVec3 (const ezVec3 &value)=0
 Writes an ezVec3 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteVec4 (const ezVec4 &value)=0
 Writes an ezVec4 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteQuat (const ezQuat &value)=0
 Writes an ezQuat to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteMat3 (const ezMat3 &value)=0
 Writes an ezMat3 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteMat4 (const ezMat4 &value)=0
 Writes an ezMat4 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteUuid (const ezUuid &value)=0
 Writes an ezUuid to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteVariant (const ezVariant &value)
 The default implementation dispatches all supported types to WriteBool, WriteInt32, etc. and asserts on the more complex types. More...
 
virtual void WriteBinaryData (const char *szDataType, const void *pData, ezUInt32 uiBytes, const char *szValueString=nullptr)=0
 Outputs a chunk of memory in some JSON form that can be interpreted as binary data when reading it again. More...
 
virtual void BeginVariable (const char *szName)=0
 Begins outputting a variable. szName is the variable name. More...
 
virtual void EndVariable ()=0
 Ends outputting a variable.
 
virtual void BeginArray (const char *szName=nullptr)=0
 Begins outputting an array variable. More...
 
virtual void EndArray ()=0
 Ends outputting an array variable.
 
virtual void BeginObject (const char *szName=nullptr)=0
 Begins outputting an object variable. More...
 
virtual void EndObject ()=0
 Ends outputting an object variable.
 

Protected Attributes

WhitespaceMode m_WhitespaceMode
 

Detailed Description

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()).

Member Enumeration Documentation

Modes to configure how much whitespace the JSON writer will output.

Enumerator
All 

All whitespace is output. This is the default, it should be used for files that are read by humans.

LessIndentation 

Saves some space by using less space for indentation.

NoIndentation 

Saves even more space by dropping all indentation from the output. The result will be noticeably less readable.

NewlinesOnly 

All unnecessary whitespace, except for newlines, is not output.

None 

No whitespace, not even newlines, is output. This should be used when JSON is used for data exchange, but probably not read by humans.

Member Function Documentation

virtual void ezJSONWriter::BeginArray ( const char *  szName = nullptr)
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.

virtual void ezJSONWriter::BeginObject ( const char *  szName = nullptr)
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.

virtual void ezJSONWriter::BeginVariable ( const char *  szName)
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.

virtual void ezJSONWriter::WriteBinaryData ( const char *  szDataType,
const void *  pData,
ezUInt32  uiBytes,
const char *  szValueString = nullptr 
)
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.

void ezJSONWriter::WriteColor ( const ezColor value)
pure virtual

Writes an ezColor to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().

Note
Standard JSON does not have a suitable type for this. A derived class might turn this into an object or output it via WriteBinaryData().

Implemented in ezStandardJSONWriter.

void ezJSONWriter::WriteMat3 ( const ezMat3 value)
pure virtual

Writes an ezMat3 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().

Note
Standard JSON does not have a suitable type for this. A derived class might turn this into an object or output it via WriteBinaryData().

Implemented in ezStandardJSONWriter.

void ezJSONWriter::WriteMat4 ( const ezMat4 value)
pure virtual

Writes an ezMat4 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().

Note
Standard JSON does not have a suitable type for this. A derived class might turn this into an object or output it via WriteBinaryData().

Implemented in ezStandardJSONWriter.

void ezJSONWriter::WriteQuat ( const ezQuat value)
pure virtual

Writes an ezQuat to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().

Note
Standard JSON does not have a suitable type for this. A derived class might turn this into an object or output it via WriteBinaryData().

Implemented in ezStandardJSONWriter.

virtual void ezJSONWriter::WriteUuid ( const ezUuid value)
pure virtual

Writes an ezUuid to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().

Note
Standard JSON does not have a suitable type for this. A derived class might turn this into an object or output it via WriteBinaryData().

Implemented in ezStandardJSONWriter.

void ezJSONWriter::WriteVariant ( const ezVariant value)
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.

void ezJSONWriter::WriteVec2 ( const ezVec2 value)
pure virtual

Writes an ezVec2 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().

Note
Standard JSON does not have a suitable type for this. A derived class might turn this into an object or output it via WriteBinaryData().

Implemented in ezStandardJSONWriter.

void ezJSONWriter::WriteVec3 ( const ezVec3 value)
pure virtual

Writes an ezVec3 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().

Note
Standard JSON does not have a suitable type for this. A derived class might turn this into an object or output it via WriteBinaryData().

Implemented in ezStandardJSONWriter.

void ezJSONWriter::WriteVec4 ( const ezVec4 value)
pure virtual

Writes an ezVec4 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().

Note
Standard JSON does not have a suitable type for this. A derived class might turn this into an object or output it via WriteBinaryData().

Implemented in ezStandardJSONWriter.


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