![]() |
XII Release 0.1.0
|
Implements a standard compliant JSON writer, all numbers are output as double values. More...
#include <JSONWriter.h>
Classes | |
struct | CommaWriter |
struct | JSONState |
Public Member Functions | |
xiiStandardJSONWriter () | |
Constructor. | |
~xiiStandardJSONWriter () | |
Destructor. | |
void | SetOutputStream (xiiStreamWriter *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(). | |
virtual void | WriteInt32 (xiiInt32 value) override |
Writes an int32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
virtual void | WriteUInt32 (xiiUInt32 value) override |
Writes a uint32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
virtual void | WriteInt64 (xiiInt64 value) override |
Writes an int64 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
virtual void | WriteUInt64 (xiiUInt64 value) override |
Writes a uint64 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
virtual void | WriteFloat (float value) override |
Writes a float to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
virtual void | WriteDouble (double value) override |
Writes a double to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
virtual void | WriteString (xiiStringView value) override |
Writes a string to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
virtual void | WriteNULL () override |
Writes the value 'null' to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
virtual void | WriteTime (xiiTime value) override |
Writes the time value as a double (i.e. redirects to WriteDouble()). | |
virtual void | WriteColor (const xiiColor &value) override |
Outputs the value via WriteVec4(). | |
virtual void | WriteColorGamma (const xiiColorGammaUB &value) override |
Outputs the value via WriteVec4(). | |
virtual void | WriteVec2 (const xiiVec2 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec2d (const xiiVec2d &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec3 (const xiiVec3 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec3d (const xiiVec3d &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec4 (const xiiVec4 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec4d (const xiiVec4d &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec2I32 (const xiiVec2I32 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec2I64 (const xiiVec2I64 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec3I32 (const xiiVec3I32 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec3I64 (const xiiVec3I64 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec4I32 (const xiiVec4I32 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec4I64 (const xiiVec4I64 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec2U32 (const xiiVec2U32 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec2U64 (const xiiVec2U64 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec3U32 (const xiiVec3U32 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec3U64 (const xiiVec3U64 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec4U32 (const xiiVec4U32 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteVec4U64 (const xiiVec4U64 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteQuat (const xiiQuat &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteQuatd (const xiiQuatd &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteMat3 (const xiiMat3 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteMat3d (const xiiMat3d &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteMat4 (const xiiMat4 &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteMat4d (const xiiMat4d &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteTransform (const xiiTransform &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteTransformd (const xiiTransformd &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteUuid (const xiiUuid &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteAngle (xiiAngle value) override |
Writes a float to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
virtual void | WriteAngle (xiiAngled value) override |
Writes a double to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray(). | |
virtual void | WriteDataBuffer (const xiiDataBuffer &value) override |
Outputs the value via WriteBinaryData(). | |
virtual void | WriteBinaryData (xiiStringView sDataType, const void *pData, xiiUInt32 uiBytes, xiiStringView sValueString={}) 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 (xiiStringView sName) override |
Begins outputting a variable. szName is the variable name. | |
virtual void | EndVariable () override |
Ends outputting a variable. | |
virtual void | BeginArray (xiiStringView sName={}) override |
Begins outputting an array variable. | |
virtual void | EndArray () override |
Ends outputting an array variable. | |
virtual void | BeginObject (xiiStringView sName={}) override |
Begins outputting an object variable. | |
virtual void | EndObject () override |
Ends outputting an object variable. | |
![]() | |
xiiJSONWriter () | |
Constructor. | |
virtual | ~xiiJSONWriter () |
Destructor. | |
void | SetWhitespaceMode (WhitespaceMode whitespaceMode) |
Configures how much whitespace is output. | |
void | SetArrayMode (ArrayMode arrayMode) |
Configures how arrays are written. | |
void | AddVariableBool (xiiStringView sName, bool value) |
Shorthand for "BeginVariable(szName); WriteBool(value); EndVariable(); ". | |
void | AddVariableInt32 (xiiStringView sName, xiiInt32 value) |
Shorthand for "BeginVariable(szName); WriteInt32(value); EndVariable(); ". | |
void | AddVariableUInt32 (xiiStringView sName, xiiUInt32 value) |
Shorthand for "BeginVariable(szName); WriteUInt32(value); EndVariable(); ". | |
void | AddVariableInt64 (xiiStringView sName, xiiInt64 value) |
Shorthand for "BeginVariable(szName); WriteInt64(value); EndVariable(); ". | |
void | AddVariableUInt64 (xiiStringView sName, xiiUInt64 value) |
Shorthand for "BeginVariable(szName); WriteUInt64(value); EndVariable(); ". | |
void | AddVariableFloat (xiiStringView sName, float value) |
Shorthand for "BeginVariable(szName); WriteFloat(value); EndVariable(); ". | |
void | AddVariableDouble (xiiStringView sName, double value) |
Shorthand for "BeginVariable(szName); WriteDouble(value); EndVariable(); ". | |
void | AddVariableString (xiiStringView sName, xiiStringView value) |
Shorthand for "BeginVariable(szName); WriteString(value); EndVariable(); ". | |
void | AddVariableNULL (xiiStringView sName) |
Shorthand for "BeginVariable(szName); WriteNULL(value); EndVariable(); ". | |
void | AddVariableTime (xiiStringView sName, xiiTime value) |
Shorthand for "BeginVariable(szName); WriteTime(value); EndVariable(); ". | |
void | AddVariableUuid (xiiStringView sName, xiiUuid value) |
Shorthand for "BeginVariable(szName); WriteUuid(value); EndVariable(); ". | |
void | AddVariableAngle (xiiStringView sName, xiiAngle value) |
Shorthand for "BeginVariable(szName); WriteAngle(value); EndVariable(); ". | |
void | AddVariableAngle (xiiStringView sName, xiiAngled value) |
Shorthand for "BeginVariable(szName); WriteAngle(value); EndVariable(); ". | |
void | AddVariableColor (xiiStringView sName, const xiiColor &value) |
Shorthand for "BeginVariable(szName); WriteColor(value); EndVariable(); ". | |
void | AddVariableColorGamma (xiiStringView sName, const xiiColorGammaUB &value) |
Shorthand for "BeginVariable(szName); WriteColorGamma(value); EndVariable(); ". | |
void | AddVariableVec2 (xiiStringView sName, const xiiVec2 &value) |
Shorthand for "BeginVariable(szName); WriteVec2(value); EndVariable(); ". | |
void | AddVariableVec2d (xiiStringView sName, const xiiVec2d &value) |
Shorthand for "BeginVariable(szName); WriteVec2d(value); EndVariable(); ". | |
void | AddVariableVec3 (xiiStringView sName, const xiiVec3 &value) |
Shorthand for "BeginVariable(szName); WriteVec3(value); EndVariable(); ". | |
void | AddVariableVec3d (xiiStringView sName, const xiiVec3d &value) |
Shorthand for "BeginVariable(szName); WriteVec3d(value); EndVariable(); ". | |
void | AddVariableVec4 (xiiStringView sName, const xiiVec4 &value) |
Shorthand for "BeginVariable(szName); WriteVec4(value); EndVariable(); ". | |
void | AddVariableVec4d (xiiStringView sName, const xiiVec4d &value) |
Shorthand for "BeginVariable(szName); WriteVec4d(value); EndVariable(); ". | |
void | AddVariableVec2I32 (xiiStringView sName, const xiiVec2I32 &value) |
Shorthand for "BeginVariable(szName); WriteVec2I32(value); EndVariable(); ". | |
void | AddVariableVec2I64 (xiiStringView sName, const xiiVec2I64 &value) |
Shorthand for "BeginVariable(szName); WriteVec2I64(value); EndVariable(); ". | |
void | AddVariableVec3I32 (xiiStringView sName, const xiiVec3I32 &value) |
Shorthand for "BeginVariable(szName); WriteVec3I32(value); EndVariable(); ". | |
void | AddVariableVec3I64 (xiiStringView sName, const xiiVec3I64 &value) |
Shorthand for "BeginVariable(szName); WriteVec3I64(value); EndVariable(); ". | |
void | AddVariableVec4I32 (xiiStringView sName, const xiiVec4I32 &value) |
Shorthand for "BeginVariable(szName); WriteVec4I32(value); EndVariable(); ". | |
void | AddVariableVec4I64 (xiiStringView sName, const xiiVec4I64 &value) |
Shorthand for "BeginVariable(szName); WriteVec4I64(value); EndVariable(); ". | |
void | AddVariableVec2U32 (xiiStringView sName, const xiiVec2U32 &value) |
Shorthand for "BeginVariable(szName); WriteVec2U32(value); EndVariable(); ". | |
void | AddVariableVec2U64 (xiiStringView sName, const xiiVec2U64 &value) |
Shorthand for "BeginVariable(szName); WriteVec2U64(value); EndVariable(); ". | |
void | AddVariableVec3U32 (xiiStringView sName, const xiiVec3U32 &value) |
Shorthand for "BeginVariable(szName); WriteVec3U32(value); EndVariable(); ". | |
void | AddVariableVec3U64 (xiiStringView sName, const xiiVec3U64 &value) |
Shorthand for "BeginVariable(szName); WriteVec3U64(value); EndVariable(); ". | |
void | AddVariableVec4U32 (xiiStringView sName, const xiiVec4U32 &value) |
Shorthand for "BeginVariable(szName); WriteVec4U32(value); EndVariable(); ". | |
void | AddVariableVec4U64 (xiiStringView sName, const xiiVec4U64 &value) |
Shorthand for "BeginVariable(szName); WriteVec4U64(value); EndVariable(); ". | |
void | AddVariableQuat (xiiStringView sName, const xiiQuat &value) |
Shorthand for "BeginVariable(szName); WriteQuat(value); EndVariable(); ". | |
void | AddVariableQuatd (xiiStringView sName, const xiiQuatd &value) |
Shorthand for "BeginVariable(szName); WriteQuatd(value); EndVariable(); ". | |
void | AddVariableMat3 (xiiStringView sName, const xiiMat3 &value) |
Shorthand for "BeginVariable(szName); WriteMat3(value); EndVariable(); ". | |
void | AddVariableMat3d (xiiStringView sName, const xiiMat3d &value) |
Shorthand for "BeginVariable(szName); WriteMat3d(value); EndVariable(); ". | |
void | AddVariableMat4 (xiiStringView sName, const xiiMat4 &value) |
Shorthand for "BeginVariable(szName); WriteMat4(value); EndVariable(); ". | |
void | AddVariableMat4d (xiiStringView sName, const xiiMat4d &value) |
Shorthand for "BeginVariable(szName); WriteMat4d(value); EndVariable(); ". | |
void | AddVariableTransform (xiiStringView sName, const xiiTransform &value) |
Shorthand for "BeginVariable(szName); WriteTransform(value); EndVariable(); ". | |
void | AddVariableTransformd (xiiStringView sName, const xiiTransformd &value) |
Shorthand for "BeginVariable(szName); WriteTransformd(value); EndVariable(); ". | |
void | AddVariableDataBuffer (xiiStringView sName, const xiiDataBuffer &value) |
Shorthand for "BeginVariable(szName); WriteDataBuffer(value); EndVariable(); ". | |
void | AddVariableVariant (xiiStringView sName, const xiiVariant &value) |
Shorthand for "BeginVariable(szName); WriteVariant(value); EndVariable(); ". | |
virtual void | WriteVariant (const xiiVariant &value) |
The default implementation dispatches all supported types to WriteBool, WriteInt32, etc. and asserts on the more complex types. | |
bool | HadWriteError () const |
Indicates if an error was encountered while writing. | |
Protected Types | |
enum | State { Invalid , Empty , Variable , Object , NamedObject , Array , NamedArray } |
Protected Member Functions | |
void | End () |
void | OutputString (xiiStringView s) |
void | OutputEscapedString (xiiStringView s) |
void | OutputIndentation () |
![]() | |
void | SetWriteErrorState () |
called internally when there was an error during writing | |
Protected Attributes | |
xiiInt32 | m_iIndentation |
xiiStreamWriter * | m_pOutput |
xiiHybridArray< JSONState, 16 > | m_StateStack |
![]() | |
WhitespaceMode | m_WhitespaceMode = WhitespaceMode::All |
ArrayMode | m_ArrayMode = ArrayMode::InOneLine |
Additional Inherited Members | |
![]() | |
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... | |
Implements a standard compliant JSON writer, all numbers are output as double values.
xiiStandardJSONWriter 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.
|
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 xiiJSONWriter.
|
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 xiiJSONWriter.
|
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 xiiJSONWriter.
|
overridevirtual |
Ends outputting an array variable.
Implements xiiJSONWriter.
|
overridevirtual |
Ends outputting an object variable.
Implements xiiJSONWriter.
|
overridevirtual |
Ends outputting a variable.
Implements xiiJSONWriter.
|
overridevirtual |
Writes a float to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implements xiiJSONWriter.
|
overridevirtual |
Writes a double to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implements xiiJSONWriter.
|
overridevirtual |
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).
Implements xiiJSONWriter.
|
overridevirtual |
Writes a bool to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteVec4().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteVec4().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Writes a double to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implements xiiJSONWriter.
|
overridevirtual |
Writes a float to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implements xiiJSONWriter.
|
overridevirtual |
Writes an int32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implements xiiJSONWriter.
|
overridevirtual |
Writes an int64 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Writes the value 'null' to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Writes a string to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implements xiiJSONWriter.
|
overridevirtual |
Writes the time value as a double (i.e. redirects to WriteDouble()).
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Writes a uint32 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implements xiiJSONWriter.
|
overridevirtual |
Writes a uint64 to the JSON file. Can only be called between BeginVariable() / EndVariable() or BeginArray() / EndArray().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.
|
overridevirtual |
Outputs the value via WriteBinaryData().
Implements xiiJSONWriter.