Plasma Engine  2.0
Loading...
Searching...
No Matches
plJSONWriter Class Referenceabstract

The base class for JSON writers. More...

#include <JSONWriter.h>

Inheritance diagram for plJSONWriter:

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

 plJSONWriter ()
 Constructor.
 
virtual ~plJSONWriter ()
 Destructor.
 
void SetWhitespaceMode (WhitespaceMode whitespaceMode)
 Configures how much whitespace is output.
 
void SetArrayMode (ArrayMode arrayMode)
 Configures how arrays are written.
 
void AddVariableBool (plStringView sName, bool value)
 Shorthand for "BeginVariable(szName); WriteBool(value); EndVariable(); ".
 
void AddVariableInt32 (plStringView sName, plInt32 value)
 Shorthand for "BeginVariable(szName); WriteInt32(value); EndVariable(); ".
 
void AddVariableUInt32 (plStringView sName, plUInt32 value)
 Shorthand for "BeginVariable(szName); WriteUInt32(value); EndVariable(); ".
 
void AddVariableInt64 (plStringView sName, plInt64 value)
 Shorthand for "BeginVariable(szName); WriteInt64(value); EndVariable(); ".
 
void AddVariableUInt64 (plStringView sName, plUInt64 value)
 Shorthand for "BeginVariable(szName); WriteUInt64(value); EndVariable(); ".
 
void AddVariableFloat (plStringView sName, float value)
 Shorthand for "BeginVariable(szName); WriteFloat(value); EndVariable(); ".
 
void AddVariableDouble (plStringView sName, double value)
 Shorthand for "BeginVariable(szName); WriteDouble(value); EndVariable(); ".
 
void AddVariableString (plStringView sName, plStringView value)
 Shorthand for "BeginVariable(szName); WriteString(value); EndVariable(); ".
 
void AddVariableNULL (plStringView sName)
 Shorthand for "BeginVariable(szName); WriteNULL(value); EndVariable(); ".
 
void AddVariableTime (plStringView sName, plTime value)
 Shorthand for "BeginVariable(szName); WriteTime(value); EndVariable(); ".
 
void AddVariableUuid (plStringView sName, plUuid value)
 Shorthand for "BeginVariable(szName); WriteUuid(value); EndVariable(); ".
 
void AddVariableAngle (plStringView sName, plAngle value)
 Shorthand for "BeginVariable(szName); WriteAngle(value); EndVariable(); ".
 
void AddVariableColor (plStringView sName, const plColor &value)
 Shorthand for "BeginVariable(szName); WriteColor(value); EndVariable(); ".
 
void AddVariableColorGamma (plStringView sName, const plColorGammaUB &value)
 Shorthand for "BeginVariable(szName); WriteColorGamma(value); EndVariable(); ".
 
void AddVariableVec2 (plStringView sName, const plVec2 &value)
 Shorthand for "BeginVariable(szName); WriteVec2(value); EndVariable(); ".
 
void AddVariableVec3 (plStringView sName, const plVec3 &value)
 Shorthand for "BeginVariable(szName); WriteVec3(value); EndVariable(); ".
 
void AddVariableVec4 (plStringView sName, const plVec4 &value)
 Shorthand for "BeginVariable(szName); WriteVec4(value); EndVariable(); ".
 
void AddVariableVec2I32 (plStringView sName, const plVec2I32 &value)
 Shorthand for "BeginVariable(szName); WriteVec2I32(value); EndVariable(); ".
 
void AddVariableVec3I32 (plStringView sName, const plVec3I32 &value)
 Shorthand for "BeginVariable(szName); WriteVec3I32(value); EndVariable(); ".
 
void AddVariableVec4I32 (plStringView sName, const plVec4I32 &value)
 Shorthand for "BeginVariable(szName); WriteVec4I32(value); EndVariable(); ".
 
void AddVariableQuat (plStringView sName, const plQuat &value)
 Shorthand for "BeginVariable(szName); WriteQuat(value); EndVariable(); ".
 
void AddVariableMat3 (plStringView sName, const plMat3 &value)
 Shorthand for "BeginVariable(szName); WriteMat3(value); EndVariable(); ".
 
void AddVariableMat4 (plStringView sName, const plMat4 &value)
 Shorthand for "BeginVariable(szName); WriteMat4(value); EndVariable(); ".
 
void AddVariableDataBuffer (plStringView sName, const plDataBuffer &value)
 Shorthand for "BeginVariable(szName); WriteDataBuffer(value); EndVariable(); ".
 
void AddVariableVariant (plStringView sName, const plVariant &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 (plInt32 value)=0
 Writes an int32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteUInt32 (plUInt32 value)=0
 Writes a uint32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteInt64 (plInt64 value)=0
 Writes an int64 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteUInt64 (plUInt64 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 (plStringView 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 (plTime value)=0
 Writes a time value to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteColor (const plColor &value)=0
 Writes an plColor to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteColorGamma (const plColorGammaUB &value)=0
 Writes an plColorGammaUB to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteVec2 (const plVec2 &value)=0
 Writes an plVec2 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteVec3 (const plVec3 &value)=0
 Writes an plVec3 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteVec4 (const plVec4 &value)=0
 Writes an plVec4 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteVec2I32 (const plVec2I32 &value)=0
 Writes an plVec2I32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteVec3I32 (const plVec3I32 &value)=0
 Writes an plVec3I32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteVec4I32 (const plVec4I32 &value)=0
 Writes an plVec4I32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteQuat (const plQuat &value)=0
 Writes an plQuat to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteMat3 (const plMat3 &value)=0
 Writes an plMat3 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteMat4 (const plMat4 &value)=0
 Writes an plMat4 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteUuid (const plUuid &value)=0
 Writes an plUuid to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteAngle (plAngle value)=0
 Writes an plAngle to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteDataBuffer (const plDataBuffer &value)=0
 Writes an plDataBuffer to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
 
virtual void WriteVariant (const plVariant &value)
 The default implementation dispatches all supported types to WriteBool, WriteInt32, etc. and asserts on the more complex types.
 
virtual void WriteBinaryData (plStringView sDataType, const void *pData, plUInt32 uiBytes, plStringView 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 (plStringView sName)=0
 Begins outputting a variable. szName is the variable name.
 
virtual void EndVariable ()=0
 Ends outputting a variable.
 
virtual void BeginArray (plStringView sName=nullptr)=0
 Begins outputting an array variable.
 
virtual void EndArray ()=0
 Ends outputting an array variable.
 
virtual void BeginObject (plStringView 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.
 

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
 

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

◆ ArrayMode

enum class plJSONWriter::ArrayMode
strong

Modes to configure how arrays are written.

Enumerator
InOneLine 

All array items are written in a single line in the file.

OneLinePerItem 

Each array item is put on a separate line.

◆ WhitespaceMode

enum class plJSONWriter::WhitespaceMode
strong

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

◆ BeginArray()

virtual void plJSONWriter::BeginArray ( plStringView sName = 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 plStandardJSONWriter.

◆ BeginObject()

virtual void plJSONWriter::BeginObject ( plStringView sName = 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 plStandardJSONWriter.

◆ BeginVariable()

virtual void plJSONWriter::BeginVariable ( plStringView sName)
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 plStandardJSONWriter.

◆ EndArray()

virtual void plJSONWriter::EndArray ( )
pure virtual

Ends outputting an array variable.

Implemented in plStandardJSONWriter.

◆ EndObject()

virtual void plJSONWriter::EndObject ( )
pure virtual

Ends outputting an object variable.

Implemented in plStandardJSONWriter.

◆ EndVariable()

virtual void plJSONWriter::EndVariable ( )
pure virtual

Ends outputting a variable.

Implemented in plStandardJSONWriter.

◆ HadWriteError()

bool plJSONWriter::HadWriteError ( ) const

Indicates if an error was encountered while writing.

If any error was encountered at any time during writing, this will return true

◆ WriteAngle()

virtual void plJSONWriter::WriteAngle ( plAngle value)
pure virtual

Writes an plAngle 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 plStandardJSONWriter.

◆ WriteBinaryData()

virtual void plJSONWriter::WriteBinaryData ( plStringView sDataType,
const void * pData,
plUInt32 uiBytes,
plStringView sValueString = 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 plStandardJSONWriter.

◆ WriteBool()

virtual void plJSONWriter::WriteBool ( bool value)
pure virtual

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

Implemented in plStandardJSONWriter.

◆ WriteColor()

void plJSONWriter::WriteColor ( const plColor & value)
pure virtual

Writes an plColor 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 plStandardJSONWriter.

◆ WriteColorGamma()

void plJSONWriter::WriteColorGamma ( const plColorGammaUB & value)
pure virtual

Writes an plColorGammaUB 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 plStandardJSONWriter.

◆ WriteDataBuffer()

void plJSONWriter::WriteDataBuffer ( const plDataBuffer & value)
pure virtual

Writes an plDataBuffer 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 plStandardJSONWriter.

◆ WriteDouble()

virtual void plJSONWriter::WriteDouble ( double value)
pure virtual

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

Implemented in plStandardJSONWriter.

◆ WriteFloat()

virtual void plJSONWriter::WriteFloat ( float value)
pure virtual

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

Implemented in plStandardJSONWriter.

◆ WriteInt32()

virtual void plJSONWriter::WriteInt32 ( plInt32 value)
pure virtual

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

Implemented in plStandardJSONWriter.

◆ WriteInt64()

virtual void plJSONWriter::WriteInt64 ( plInt64 value)
pure virtual

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

Implemented in plStandardJSONWriter.

◆ WriteMat3()

void plJSONWriter::WriteMat3 ( const plMat3 & value)
pure virtual

Writes an plMat3 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 plStandardJSONWriter.

◆ WriteMat4()

void plJSONWriter::WriteMat4 ( const plMat4 & value)
pure virtual

Writes an plMat4 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 plStandardJSONWriter.

◆ WriteNULL()

virtual void plJSONWriter::WriteNULL ( )
pure virtual

Writes the value 'null' to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().

Implemented in plStandardJSONWriter.

◆ WriteQuat()

void plJSONWriter::WriteQuat ( const plQuat & value)
pure virtual

Writes an plQuat 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 plStandardJSONWriter.

◆ WriteString()

virtual void plJSONWriter::WriteString ( plStringView value)
pure virtual

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

Implemented in plStandardJSONWriter.

◆ WriteTime()

virtual void plJSONWriter::WriteTime ( plTime value)
pure virtual

Writes a time value to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().

Implemented in plStandardJSONWriter.

◆ WriteUInt32()

virtual void plJSONWriter::WriteUInt32 ( plUInt32 value)
pure virtual

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

Implemented in plStandardJSONWriter.

◆ WriteUInt64()

virtual void plJSONWriter::WriteUInt64 ( plUInt64 value)
pure virtual

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

Implemented in plStandardJSONWriter.

◆ WriteUuid()

virtual void plJSONWriter::WriteUuid ( const plUuid & value)
pure virtual

Writes an plUuid 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 plStandardJSONWriter.

◆ WriteVariant()

void plJSONWriter::WriteVariant ( const plVariant & 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.

◆ WriteVec2()

void plJSONWriter::WriteVec2 ( const plVec2 & value)
pure virtual

Writes an plVec2 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 plStandardJSONWriter.

◆ WriteVec2I32()

void plJSONWriter::WriteVec2I32 ( const plVec2I32 & value)
pure virtual

Writes an plVec2I32 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 plStandardJSONWriter.

◆ WriteVec3()

void plJSONWriter::WriteVec3 ( const plVec3 & value)
pure virtual

Writes an plVec3 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 plStandardJSONWriter.

◆ WriteVec3I32()

void plJSONWriter::WriteVec3I32 ( const plVec3I32 & value)
pure virtual

Writes an plVec3I32 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 plStandardJSONWriter.

◆ WriteVec4()

void plJSONWriter::WriteVec4 ( const plVec4 & value)
pure virtual

Writes an plVec4 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 plStandardJSONWriter.

◆ WriteVec4I32()

void plJSONWriter::WriteVec4I32 ( const plVec4I32 & value)
pure virtual

Writes an plVec4I32 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 plStandardJSONWriter.


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