ezEngine  Milestone 7
ezStandardJSONWriter Class Reference

Implements a standard compliant JSON writer, all numbers are output as double values. More...

#include <JSONWriter.h>

Inheritance diagram for ezStandardJSONWriter:

Classes

struct  CommaWriter
 
struct  JSONState
 

Public Member Functions

 ezStandardJSONWriter ()
 Constructor.
 
 ~ezStandardJSONWriter ()
 Destructor.
 
void SetOutputStream (ezStreamWriterBase *pOutput)
 All output is written to this binary stream.
 
virtual void WriteBool (bool value) override
 Writes a bool to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteInt32 (ezInt32 value) override
 Writes an int32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteUInt32 (ezUInt32 value) override
 Writes a uint32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteInt64 (ezInt64 value) override
 Writes an int64 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteUInt64 (ezUInt64 value) override
 Writes a uint64 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteFloat (float value) override
 Writes a float to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteDouble (double value) override
 Writes a double to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteString (const char *value) override
 Writes a string to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteNULL () override
 Writes the value 'null' to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). More...
 
virtual void WriteTime (ezTime value) override
 Writes the time value as a double (i.e. redirects to WriteDouble()).
 
virtual void WriteColor (const ezColor &value) override
 Outputs the value via WriteVec4().
 
virtual void WriteVec2 (const ezVec2 &value) override
 Outputs the value via WriteBinaryData().
 
virtual void WriteVec3 (const ezVec3 &value) override
 Outputs the value via WriteBinaryData().
 
virtual void WriteVec4 (const ezVec4 &value) override
 Outputs the value via WriteBinaryData().
 
virtual void WriteQuat (const ezQuat &value) override
 Outputs the value via WriteBinaryData().
 
virtual void WriteMat3 (const ezMat3 &value) override
 Outputs the value via WriteBinaryData().
 
virtual void WriteMat4 (const ezMat4 &value) override
 Outputs the value via WriteBinaryData().
 
virtual void WriteUuid (const ezUuid &value) override
 Outputs the value via WriteBinaryData().
 
virtual void WriteBinaryData (const char *szDataType, const void *pData, ezUInt32 uiBytes, const char *szValueString=nullptr) override
 Implements the MongoDB way of writing binary data. First writes a "$type" variable, then a "$binary" variable that represents the raw data (Hex encoded, little endian).
 
virtual void BeginVariable (const char *szName) override
 Begins outputting a variable. szName is the variable name. More...
 
virtual void EndVariable () override
 Ends outputting a variable. More...
 
virtual void BeginArray (const char *szName=nullptr) override
 Begins outputting an array variable. More...
 
virtual void EndArray () override
 Ends outputting an array variable. More...
 
virtual void BeginObject (const char *szName=nullptr) override
 Begins outputting an object variable. More...
 
virtual void EndObject () override
 Ends outputting an object variable. More...
 
- Public Member Functions inherited from ezJSONWriter
 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 WriteVariant (const ezVariant &value)
 The default implementation dispatches all supported types to WriteBool, WriteInt32, etc. and asserts on the more complex types. More...
 

Protected Types

enum  State {
  Invalid, Empty, Variable, Object,
  NamedObject, Array, NamedArray
}
 

Protected Member Functions

void End ()
 
void OutputString (const char *sz)
 
void OutputEscapedString (const char *sz)
 
void OutputIndentation ()
 

Protected Attributes

ezInt32 m_iIndentation
 
ezStreamWriterBasem_pOutput
 
ezHybridArray< JSONState, 16 > m_StateStack
 
- Protected Attributes inherited from ezJSONWriter
WhitespaceMode m_WhitespaceMode
 

Additional Inherited Members

- Public Types inherited from ezJSONWriter
enum  WhitespaceMode {
  All, LessIndentation, NoIndentation, NewlinesOnly,
  None
}
 Modes to configure how much whitespace the JSON writer will output. More...
 

Detailed Description

Implements a standard compliant JSON writer, all numbers are output as double values.

ezStandardJSONWriter also implements WriteBinaryData() and the functions WriteVec2() etc., for which there is no standard way to implement them in JSON. WriteVec2() etc. will simply redirect to WriteBinaryData(), which in turn implements the MongoDB convention of outputting binary data. I.e. it will turn the data into a JSON object which contains one variable called "$type" that identifies the data type, and one variable called "$binary" which contains the raw binary data Hex encoded in little endian format. If you want to write a fully standard compliant JSON file, just don't output any of these types.

Member Function Documentation

void ezStandardJSONWriter::BeginArray ( const char *  szName = nullptr)
overridevirtual

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.

Implements ezJSONWriter.

void ezStandardJSONWriter::BeginObject ( const char *  szName = nullptr)
overridevirtual

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.

Implements ezJSONWriter.

void ezStandardJSONWriter::BeginVariable ( const char *  szName)
overridevirtual

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.

Implements ezJSONWriter.

void ezStandardJSONWriter::EndArray ( )
overridevirtual

Ends outputting an array variable.

Implements ezJSONWriter.

void ezStandardJSONWriter::EndObject ( )
overridevirtual

Ends outputting an object variable.

Implements ezJSONWriter.

void ezStandardJSONWriter::EndVariable ( )
overridevirtual

Ends outputting a variable.

Implements ezJSONWriter.

void ezStandardJSONWriter::WriteBool ( bool  value)
overridevirtual

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

Implements ezJSONWriter.

void ezStandardJSONWriter::WriteDouble ( double  value)
overridevirtual

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

Implements ezJSONWriter.

Reimplemented in ezExtendedJSONWriter.

void ezStandardJSONWriter::WriteFloat ( float  value)
overridevirtual

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

Implements ezJSONWriter.

Reimplemented in ezExtendedJSONWriter.

void ezStandardJSONWriter::WriteInt32 ( ezInt32  value)
overridevirtual

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

Implements ezJSONWriter.

Reimplemented in ezExtendedJSONWriter.

void ezStandardJSONWriter::WriteInt64 ( ezInt64  value)
overridevirtual

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

Implements ezJSONWriter.

Reimplemented in ezExtendedJSONWriter.

void ezStandardJSONWriter::WriteNULL ( )
overridevirtual

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

Implements ezJSONWriter.

void ezStandardJSONWriter::WriteString ( const char *  value)
overridevirtual

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

Implements ezJSONWriter.

void ezStandardJSONWriter::WriteUInt32 ( ezUInt32  value)
overridevirtual

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

Implements ezJSONWriter.

Reimplemented in ezExtendedJSONWriter.

void ezStandardJSONWriter::WriteUInt64 ( ezUInt64  value)
overridevirtual

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

Implements ezJSONWriter.

Reimplemented in ezExtendedJSONWriter.


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