HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_JSONWriter Class Referenceabstract

Class which writes ASCII or binary JSON streams. More...

#include <UT_JSONWriter.h>

Classes

class  TiledStream
 
class  TiledStreamBuf
 

Public Member Functions

 UT_JSONWriter (const UT_Options *options=0)
 
virtual ~UT_JSONWriter ()
 
void setOptions (const UT_Options &options)
 
void getOptions (UT_Options &options) const
 
bool setBinary (bool bin)
 
bool getBinary () const
 Return whether writing binary or ASCII JSON. More...
 
int64 getNumBytesWritten () const
 Get the number of bytes written to output so far. More...
 
void startNewFile ()
 Start a new embedded file. More...
 
void endNewFile ()
 End a started embedded file. More...
 
bool jsonComment (const char *format,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
 
bool bool jsonNull ()
 Write a null to the stream. More...
 
bool jsonBool (bool value)
 Write true/false. More...
 
bool jsonInt (int32 value)
 Write an integer value. More...
 
bool jsonInt (int64 value)
 Write a 64 bit integer value. More...
 
bool jsonInt64 (int64 value)
 Write a 64 bit integer as a 64 bit integer. More...
 
bool jsonReal (fpreal16 value)
 Write a 16 bit real. More...
 
bool jsonReal (fpreal32 value)
 Write a 32 bit real. More...
 
bool jsonReal (fpreal64 value)
 Write a 64 bit real. More...
 
bool jsonString (const char *value, int64 length=0)
 
bool jsonStringToken (const UT_StringRef &value)
 
bool jsonStringToken (const char *value, int64 length)
 
bool jsonValue (bool value)
 
bool jsonValue (int8 value)
 
bool jsonValue (int16 value)
 
bool jsonValue (int32 value)
 
bool jsonValue (int64 value)
 
bool jsonValue (fpreal16 value)
 
bool jsonValue (fpreal32 value)
 
bool jsonValue (fpreal64 value)
 
bool jsonBeginMap ()
 Begin a map/object dictionary. More...
 
bool jsonKey (const char *value, int64 length=0)
 
bool jsonKeyToken (const UT_StringRef &value)
 
bool jsonKeyToken (const char *value, int64 length)
 
bool jsonEndMap ()
 End the object. More...
 
bool jsonBeginArray ()
 Begin a generic array object. More...
 
bool jsonEndArray (bool newline=true)
 
bool beginUniformArray (int64 length, UT_JID id)
 
bool uniformWrite (bool value)
 
bool uniformWrite (int8 value)
 Write an 8 bit integer value to the uniform array. More...
 
bool uniformWrite (int16 value)
 Write an 16 bit integer value to the uniform array. More...
 
bool uniformWrite (int32 value)
 Write an 32 bit integer value to the uniform array. More...
 
bool uniformWrite (int64 value)
 Write an 64 bit integer value to the uniform array. More...
 
bool uniformWrite (fpreal16 value)
 Write an 16 bit float/real value to the uniform array. More...
 
bool uniformWrite (fpreal32 value)
 Write an 32 bit float/real value to the uniform array. More...
 
bool uniformWrite (fpreal64 value)
 Write an 64 bit float/real value to the uniform array. More...
 
bool uniformWrite (uint8 value)
 Write an 8 bit unsigned integer value to the uniform array. More...
 
bool uniformWrite (uint16 value)
 Write an 16 bit unsigned integer value to the uniform array. More...
 
bool uniformWrite (const char *value, int64 length=0)
 Write a string to the uniform array. More...
 
bool uniformBlockWrite (const int8 *value, int64 count)
 Write a block of 8 bit integer values to the uniform array. More...
 
bool uniformBlockWrite (const int16 *value, int64 count)
 Write a block of 16 bit integer values to the uniform array. More...
 
bool uniformBlockWrite (const int32 *value, int64 count)
 Write a block of 32 bit integer values to the uniform array. More...
 
bool uniformBlockWrite (const int64 *value, int64 count)
 Write a block of 64 bit integer values to the uniform array. More...
 
bool uniformBlockWrite (const fpreal16 *value, int64 count)
 Write a block of 16 bit float/real values to the uniform array. More...
 
bool uniformBlockWrite (const fpreal32 *value, int64 count)
 Write a block of 32 bit float/real values to the uniform array. More...
 
bool uniformBlockWrite (const fpreal64 *value, int64 count)
 Write a block of 64 bit float/real values to the uniform array. More...
 
bool uniformBlockWrite (const uint8 *value, int64 count)
 Write a block of 8 bit unsigned integer values to the uniform array. More...
 
bool uniformBlockWrite (const uint16 *value, int64 count)
 Write a block of 16 bit unsigned integer values to the uniform array. More...
 
bool endUniformArray (int64 *nwritten=0)
 
virtual bool writeData (const void *data, int64 bytes)
 Internally called to write raw data to output. More...
 
bool jsonUniformArray (int64 length, const int8 *value)
 Efficent method of writing a uniform array of int8 values. More...
 
bool jsonUniformArray (int64 length, const int16 *value)
 Efficent method of writing a uniform array of int16 values. More...
 
bool jsonUniformArray (int64 length, const int32 *value)
 Efficent method of writing a uniform array of int32 values. More...
 
bool jsonUniformArray (int64 length, const int64 *value)
 Efficent method of writing a uniform array of int64 values. More...
 
bool jsonUniformArray (int64 length, const fpreal16 *value)
 Efficent method of writing a uniform array of fpreal16 values. More...
 
bool jsonUniformArray (int64 length, const fpreal32 *value)
 Efficent method of writing a uniform array of fpreal32 values. More...
 
bool jsonUniformArray (int64 length, const fpreal64 *value)
 Efficent method of writing a uniform array of fpreal64 values. More...
 
bool jsonUniformArray (int64 length, const uint8 *value)
 Efficent method of writing a uniform array of uint8 values. More...
 
bool jsonUniformArray (int64 length, const uint16 *value)
 Efficent method of writing a uniform array of uint16 values. More...
 
bool jsonUniformArray (int64 length, const UT_BitArray &value, bool verbose_ascii=false)
 Efficient method of writing a uniform array of bool values. More...
 
bool jsonStringArray (const UT_StringArray &a)
 Convenience method to save an array of strings. More...
 
bool jsonStringTokenArray (const UT_StringArray &a)
 Convenience method to save an array of strings (as tokens) More...
 
bool jsonUniformArray (const UT_Int16Array &a)
 
bool jsonUniformArray (const UT_Int32Array &a)
 
bool jsonUniformArray (const UT_Int64Array &a)
 
bool jsonUniformArray (const UT_Fpreal32Array &a)
 
bool jsonUniformArray (const UT_Fpreal64Array &a)
 

Static Public Member Functions

static UT_JSONWriterallocWriter (UT_WorkBuffer &buffer)
 
static UT_JSONWriterallocWriter (std::ostream &os, bool binary, UT_CompressionType compressionType=UT_COMPRESSION_TYPE_NONE)
 
static UT_JSONWriterallocWriter (const char *filename, bool binary, UT_CompressionType compressionType=UT_COMPRESSION_TYPE_NONE)
 
static UT_JSONWriterallocWriter (UT_JSONValue &value)
 
static UT_JID jidFromValue (const bool *)
 Returns the JID that matches the given type. More...
 
static UT_JID jidFromValue (const int8 *)
 
static UT_JID jidFromValue (const int16 *)
 
static UT_JID jidFromValue (const int32 *)
 
static UT_JID jidFromValue (const int64 *)
 
static UT_JID jidFromValue (const fpreal16 *)
 
static UT_JID jidFromValue (const fpreal32 *)
 
static UT_JID jidFromValue (const fpreal64 *)
 
static UT_JID jidFromValue (const uint8 *)
 
static UT_JID jidFromValue (const uint16 *)
 

Protected Member Functions

virtual bool subclassWriteData (const void *data, int64 bytes)=0
 The sub-class must implement this method to write data. More...
 
int getNesting () const
 Get the nesting level (i.e. how deeply nested in maps/arrays) More...
 

Detailed Description

Class which writes ASCII or binary JSON streams.

The JSON format (http://www.json.org) is a generic way to store data. Houdini extends JSON to a byte-stream binary encoding (see UT_JID for details). The UT_JSONWriter class is used to write JSON (binary or ASCII) to a stream.

See Also
UT_JID
Examples:
packedshareddata/GU_PackedSharedData.C, packedshareddata/GU_PackedSharedData.h, tetprim/GEO_PrimTetra.C, and tetprim/GEO_PrimTetra.h.

Definition at line 32 of file UT_JSONWriter.h.

Constructor & Destructor Documentation

UT_JSONWriter::UT_JSONWriter ( const UT_Options options = 0)
Parameters
options
A UT_Options class which sets specific format options.
See Also
setOptions()
virtual UT_JSONWriter::~UT_JSONWriter ( )
virtual

Member Function Documentation

static UT_JSONWriter* UT_JSONWriter::allocWriter ( UT_WorkBuffer buffer)
static

Allocate a JSON Writer which will fill a UT_WorkBuffer. Please delete when finished with the writer.

static UT_JSONWriter* UT_JSONWriter::allocWriter ( std::ostream &  os,
bool  binary,
UT_CompressionType  compressionType = UT_COMPRESSION_TYPE_NONE 
)
static

Allocate a JSON Writer which writes to an output stream. Please delete when finished with the writer.

static UT_JSONWriter* UT_JSONWriter::allocWriter ( const char *  filename,
bool  binary,
UT_CompressionType  compressionType = UT_COMPRESSION_TYPE_NONE 
)
static

Allocate a JSON Writer which writes to a named file. Please delete when finished with the writer.

static UT_JSONWriter* UT_JSONWriter::allocWriter ( UT_JSONValue value)
static

Allocate a JSON Writer which writes into a given UT_JSONValue. The value will only be set properly at the conclusion of writing. Please delete when finished with the writer.

bool UT_JSONWriter::beginUniformArray ( int64  length,
UT_JID  id 
)

When writing binary JSON files, uniform arrays can be encoded without repetition of the type information which results in a more compressed data format.

beingUniformArray() starts a uniform array. The id should be one of:

  • UT_JID_BOOL
  • UT_JID_INT8
  • UT_JID_INT16
  • UT_JID_INT32
  • UT_JID_INT64
  • UT_JID_UINT8
  • UT_JID_UINT16
  • UT_JID_REAL16
  • UT_JID_REAL32
  • UT_JID_REAL64
  • UT_JID_STRING
void UT_JSONWriter::endNewFile ( )

End a started embedded file.

bool UT_JSONWriter::endUniformArray ( int64 nwritten = 0)

End the uniform array.

Parameters
nwritten
If provided, the number of items written is returned.
Note
The JSONWriter class will automatically clamp or fill the uniform array with 0, but nwritten will return the actual number of calls to uniformWrite().
bool UT_JSONWriter::getBinary ( ) const
inline

Return whether writing binary or ASCII JSON.

Definition at line 87 of file UT_JSONWriter.h.

int UT_JSONWriter::getNesting ( ) const
inlineprotected

Get the nesting level (i.e. how deeply nested in maps/arrays)

Definition at line 373 of file UT_JSONWriter.h.

int64 UT_JSONWriter::getNumBytesWritten ( ) const
inline

Get the number of bytes written to output so far.

Examples:
packedshareddata/GU_PackedSharedData.C.

Definition at line 90 of file UT_JSONWriter.h.

void UT_JSONWriter::getOptions ( UT_Options options) const

Get the current options. This will set the token/values in the UT_Options based on options from setOptions()

static UT_JID UT_JSONWriter::jidFromValue ( const bool *  )
inlinestatic

Returns the JID that matches the given type.

Definition at line 257 of file UT_JSONWriter.h.

static UT_JID UT_JSONWriter::jidFromValue ( const int8 )
inlinestatic

Definition at line 258 of file UT_JSONWriter.h.

static UT_JID UT_JSONWriter::jidFromValue ( const int16 )
inlinestatic

Definition at line 259 of file UT_JSONWriter.h.

static UT_JID UT_JSONWriter::jidFromValue ( const int32 )
inlinestatic

Definition at line 260 of file UT_JSONWriter.h.

static UT_JID UT_JSONWriter::jidFromValue ( const int64 )
inlinestatic

Definition at line 261 of file UT_JSONWriter.h.

static UT_JID UT_JSONWriter::jidFromValue ( const fpreal16 )
inlinestatic

Definition at line 262 of file UT_JSONWriter.h.

static UT_JID UT_JSONWriter::jidFromValue ( const fpreal32 )
inlinestatic

Definition at line 263 of file UT_JSONWriter.h.

static UT_JID UT_JSONWriter::jidFromValue ( const fpreal64 )
inlinestatic

Definition at line 264 of file UT_JSONWriter.h.

static UT_JID UT_JSONWriter::jidFromValue ( const uint8 )
inlinestatic

Definition at line 265 of file UT_JSONWriter.h.

static UT_JID UT_JSONWriter::jidFromValue ( const uint16 )
inlinestatic

Definition at line 266 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonBeginArray ( )

Begin a generic array object.

Examples:
packedshareddata/GU_PackedSharedData.C.
bool UT_JSONWriter::jsonBeginMap ( )

Begin a map/object dictionary.

Examples:
packedshareddata/GU_PackedSharedData.C.
bool UT_JSONWriter::jsonBool ( bool  value)

Write true/false.

bool UT_JSONWriter::jsonComment ( const char *  format,
  ... 
)

Output a comment in the JSON stream. Not all JSON parsers (actually very few) support comments. The json:comments must be enabled for this statement to have any effect.

bool UT_JSONWriter::jsonEndArray ( bool  newline = true)

End a generic array object By default, a new line will be output for pretty printing. The newline can give a hint to omit the new line before the end of the array marker.

Examples:
packedshareddata/GU_PackedSharedData.C.
bool UT_JSONWriter::jsonEndMap ( )

End the object.

Examples:
packedshareddata/GU_PackedSharedData.C.
bool UT_JSONWriter::jsonInt ( int32  value)

Write an integer value.

bool UT_JSONWriter::jsonInt ( int64  value)

Write a 64 bit integer value.

bool UT_JSONWriter::jsonInt64 ( int64  value)

Write a 64 bit integer as a 64 bit integer.

bool UT_JSONWriter::jsonKey ( const char *  value,
int64  length = 0 
)

Write a quoted key for the object

Note
Use jsonKeyToken() to take advantage of token compression (this can be turned off with the usetokens option in the constructor).
See Also
UT_JID
bool UT_JSONWriter::jsonKeyToken ( const UT_StringRef value)

For binary streams, common key strings can be output more efficiently using the token interface. Token key strings will appear as strings in ASCII streams.

Examples:
packedshareddata/GU_PackedSharedData.C.
bool UT_JSONWriter::jsonKeyToken ( const char *  value,
int64  length 
)
inline

Definition at line 166 of file UT_JSONWriter.h.

bool bool UT_JSONWriter::jsonNull ( )

Write a null to the stream.

bool UT_JSONWriter::jsonReal ( fpreal16  value)

Write a 16 bit real.

bool UT_JSONWriter::jsonReal ( fpreal32  value)

Write a 32 bit real.

bool UT_JSONWriter::jsonReal ( fpreal64  value)

Write a 64 bit real.

bool UT_JSONWriter::jsonString ( const char *  value,
int64  length = 0 
)

Write a quoted string.

Warning
Please use jsonKey() to write key strings.
Note
Use jsonStringToken() to take advantage of token compression (this can be turned off with the usetokens option in the constructor).
See Also
UT_JID
Examples:
packedshareddata/GU_PackedSharedData.C.
bool UT_JSONWriter::jsonStringArray ( const UT_StringArray a)

Convenience method to save an array of strings.

bool UT_JSONWriter::jsonStringToken ( const UT_StringRef value)

For binary streams, common strings can be output more efficiently using the token interface. Token strings will appear as strings in ASCII streams.

Examples:
packedshareddata/GU_PackedSharedData.C.
bool UT_JSONWriter::jsonStringToken ( const char *  value,
int64  length 
)
inline

Definition at line 133 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonStringTokenArray ( const UT_StringArray a)

Convenience method to save an array of strings (as tokens)

bool UT_JSONWriter::jsonUniformArray ( int64  length,
const int8 value 
)

Efficent method of writing a uniform array of int8 values.

bool UT_JSONWriter::jsonUniformArray ( int64  length,
const int16 value 
)

Efficent method of writing a uniform array of int16 values.

bool UT_JSONWriter::jsonUniformArray ( int64  length,
const int32 value 
)

Efficent method of writing a uniform array of int32 values.

bool UT_JSONWriter::jsonUniformArray ( int64  length,
const int64 value 
)

Efficent method of writing a uniform array of int64 values.

bool UT_JSONWriter::jsonUniformArray ( int64  length,
const fpreal16 value 
)

Efficent method of writing a uniform array of fpreal16 values.

bool UT_JSONWriter::jsonUniformArray ( int64  length,
const fpreal32 value 
)

Efficent method of writing a uniform array of fpreal32 values.

bool UT_JSONWriter::jsonUniformArray ( int64  length,
const fpreal64 value 
)

Efficent method of writing a uniform array of fpreal64 values.

bool UT_JSONWriter::jsonUniformArray ( int64  length,
const uint8 value 
)

Efficent method of writing a uniform array of uint8 values.

bool UT_JSONWriter::jsonUniformArray ( int64  length,
const uint16 value 
)

Efficent method of writing a uniform array of uint16 values.

bool UT_JSONWriter::jsonUniformArray ( int64  length,
const UT_BitArray value,
bool  verbose_ascii = false 
)

Efficient method of writing a uniform array of bool values.

bool UT_JSONWriter::jsonUniformArray ( const UT_Int16Array a)
inline

Convenience method for saving common array types

Definition at line 294 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonUniformArray ( const UT_Int32Array a)
inline

Convenience method for saving common array types

Definition at line 296 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonUniformArray ( const UT_Int64Array a)
inline

Convenience method for saving common array types

Definition at line 298 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonUniformArray ( const UT_Fpreal32Array a)
inline

Convenience method for saving common array types

Definition at line 300 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonUniformArray ( const UT_Fpreal64Array a)
inline

Convenience method for saving common array types

Definition at line 302 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( bool  value)
inline

Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.

Definition at line 145 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( int8  value)
inline

Definition at line 146 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( int16  value)
inline

Definition at line 147 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( int32  value)
inline

Definition at line 148 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( int64  value)
inline

Definition at line 149 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( fpreal16  value)
inline

Definition at line 150 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( fpreal32  value)
inline

Definition at line 151 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( fpreal64  value)
inline

Definition at line 152 of file UT_JSONWriter.h.

bool UT_JSONWriter::setBinary ( bool  bin)

Turn the JSON writer into a binary JSON (bJSON) writer.

Warning
This method must be called before any other data is written to the JSON file. It's a good idea to call in the sub-class constructor.
void UT_JSONWriter::setOptions ( const UT_Options options)

Set formatting/control options base on the UT_Options. The following options are scanned:

  • int "json:precision" – ASCII float precision [9]. Note half-precision floats will use half this precision, while double precision will use twice the digits.
  • int "json:indentstep" – ASCII indent step for maps/arrays [8]
  • int "json:textwidth" – ASCII wrap lines after byte count [256]
  • bool "json:comments" – Allow comments in ASCII stream [false]
  • bool "json:prettyprint" – Pretty print ASCII stream [true]
  • bool "json:usetokens" – Binary string token compression [true]
void UT_JSONWriter::startNewFile ( )

Start a new embedded file.

virtual bool UT_JSONWriter::subclassWriteData ( const void data,
int64  bytes 
)
protectedpure virtual

The sub-class must implement this method to write data.

bool UT_JSONWriter::uniformBlockWrite ( const int8 value,
int64  count 
)

Write a block of 8 bit integer values to the uniform array.

bool UT_JSONWriter::uniformBlockWrite ( const int16 value,
int64  count 
)

Write a block of 16 bit integer values to the uniform array.

bool UT_JSONWriter::uniformBlockWrite ( const int32 value,
int64  count 
)

Write a block of 32 bit integer values to the uniform array.

bool UT_JSONWriter::uniformBlockWrite ( const int64 value,
int64  count 
)

Write a block of 64 bit integer values to the uniform array.

bool UT_JSONWriter::uniformBlockWrite ( const fpreal16 value,
int64  count 
)

Write a block of 16 bit float/real values to the uniform array.

bool UT_JSONWriter::uniformBlockWrite ( const fpreal32 value,
int64  count 
)

Write a block of 32 bit float/real values to the uniform array.

bool UT_JSONWriter::uniformBlockWrite ( const fpreal64 value,
int64  count 
)

Write a block of 64 bit float/real values to the uniform array.

bool UT_JSONWriter::uniformBlockWrite ( const uint8 value,
int64  count 
)

Write a block of 8 bit unsigned integer values to the uniform array.

bool UT_JSONWriter::uniformBlockWrite ( const uint16 value,
int64  count 
)

Write a block of 16 bit unsigned integer values to the uniform array.

bool UT_JSONWriter::uniformWrite ( bool  value)

Write a bool value to a uniform array. The bool values are packed into a bit array (where each 32-bit word stores 32 bits).

bool UT_JSONWriter::uniformWrite ( int8  value)

Write an 8 bit integer value to the uniform array.

bool UT_JSONWriter::uniformWrite ( int16  value)

Write an 16 bit integer value to the uniform array.

bool UT_JSONWriter::uniformWrite ( int32  value)

Write an 32 bit integer value to the uniform array.

bool UT_JSONWriter::uniformWrite ( int64  value)

Write an 64 bit integer value to the uniform array.

bool UT_JSONWriter::uniformWrite ( fpreal16  value)

Write an 16 bit float/real value to the uniform array.

bool UT_JSONWriter::uniformWrite ( fpreal32  value)

Write an 32 bit float/real value to the uniform array.

bool UT_JSONWriter::uniformWrite ( fpreal64  value)

Write an 64 bit float/real value to the uniform array.

bool UT_JSONWriter::uniformWrite ( uint8  value)

Write an 8 bit unsigned integer value to the uniform array.

bool UT_JSONWriter::uniformWrite ( uint16  value)

Write an 16 bit unsigned integer value to the uniform array.

bool UT_JSONWriter::uniformWrite ( const char *  value,
int64  length = 0 
)

Write a string to the uniform array.

virtual bool UT_JSONWriter::writeData ( const void data,
int64  bytes 
)
virtual

Internally called to write raw data to output.


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