UT_JSONWriter Class Reference

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

#include <UT_JSONWriter.h>

List of all members.

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)
virtual bool enableGZip ()
bool getBinary () const
 Return whether writing binary or ASCII JSON.
bool jsonComment (const char *format,...)
bool jsonNull ()
 Write a null to the stream.
bool jsonBool (bool value)
 Write true/false.
bool jsonInt (int32 value)
 Write an integer value.
bool jsonInt (int64 value)
 Write a 64 bit integer value.
bool jsonReal (fpreal16 value)
 Write a 16 bit real.
bool jsonReal (fpreal32 value)
 Write a 32 bit real.
bool jsonReal (fpreal64 value)
 Write a 64 bit real.
bool jsonString (const char *value, int64 length=0)
bool jsonStringToken (const char *value, int64 length=0)
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.
bool jsonKey (const char *value, int64 length=0)
bool jsonKeyToken (const char *value, int64 length=0)
bool jsonEndMap ()
 End the object.
bool jsonBeginArray ()
 Begin a generic array object.
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.
bool uniformWrite (int16 value)
 Write an 16 bit integer value to the uniform array.
bool uniformWrite (int32 value)
 Write an 32 bit integer value to the uniform array.
bool uniformWrite (int64 value)
 Write an 64 bit integer value to the uniform array.
bool uniformWrite (fpreal16 value)
 Write an 16 bit float/real value to the uniform array.
bool uniformWrite (fpreal32 value)
 Write an 32 bit float/real value to the uniform array.
bool uniformWrite (fpreal64 value)
 Write an 64 bit float/real value to the uniform array.
bool uniformWrite (uint8 value)
 Write an 8 bit unsigned integer value to the uniform array.
bool uniformWrite (uint16 value)
 Write an 16 bit unsigned integer value to the uniform array.
bool uniformWrite (const char *value, int64 length=0)
 Write a string to the uniform array.
bool endUniformArray (int64 *nwritten=0)
bool jsonUniformArray (int64 length, const int8 *value)
 Efficent method of writing a uniform array of int8 values.
bool jsonUniformArray (int64 length, const int16 *value)
 Efficent method of writing a uniform array of int16 values.
bool jsonUniformArray (int64 length, const int32 *value)
 Efficent method of writing a uniform array of int32 values.
bool jsonUniformArray (int64 length, const int64 *value)
 Efficent method of writing a uniform array of int64 values.
bool jsonUniformArray (int64 length, const fpreal16 *value)
 Efficent method of writing a uniform array of fpreal16 values.
bool jsonUniformArray (int64 length, const fpreal32 *value)
 Efficent method of writing a uniform array of fpreal32 values.
bool jsonUniformArray (int64 length, const fpreal64 *value)
 Efficent method of writing a uniform array of fpreal64 values.
bool jsonUniformArray (int64 length, const uint8 *value)
 Efficent method of writing a uniform array of uint8 values.
bool jsonUniformArray (int64 length, const uint16 *value)
 Efficent method of writing a uniform array of uint16 values.

Static Public Member Functions

static UT_JSONWriterallocWriter (UT_WorkBuffer &buffer)
static UT_JSONWriterallocWriter (ostream &os, bool binary, bool gzip=false)
static UT_JSONWriterallocWriter (const char *filename, bool binary, bool gzip=false)

Protected Member Functions

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


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

Definition at line 35 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 ( const char *  filename,
bool  binary,
bool  gzip = false 
) [static]

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

static UT_JSONWriter* UT_JSONWriter::allocWriter ( ostream &  os,
bool  binary,
bool  gzip = false 
) [static]

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

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.

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

virtual bool UT_JSONWriter::enableGZip (  )  [virtual]

Turn on gzip compression (if possible). This must be called before setBinary().

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 82 of file UT_JSONWriter.h.

int UT_JSONWriter::getNesting (  )  const [inline, protected]

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

Definition at line 226 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()

bool UT_JSONWriter::jsonBeginArray (  ) 

Begin a generic array object.

bool UT_JSONWriter::jsonBeginMap (  ) 

Begin a map/object dictionary.

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.

bool UT_JSONWriter::jsonEndMap (  ) 

End the object.

bool UT_JSONWriter::jsonInt ( int64  value  ) 

Write a 64 bit integer value.

bool UT_JSONWriter::jsonInt ( int32  value  ) 

Write an integer value.

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 char *  value,
int64  length = 0 
)

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.

bool UT_JSONWriter::jsonNull (  ) 

Write a null to the stream.

bool UT_JSONWriter::jsonReal ( fpreal64  value  ) 

Write a 64 bit real.

bool UT_JSONWriter::jsonReal ( fpreal32  value  ) 

Write a 32 bit real.

bool UT_JSONWriter::jsonReal ( fpreal16  value  ) 

Write a 16 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

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

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

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 uint8 value 
)

Efficent method of writing a uniform array of uint8 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 fpreal32 value 
)

Efficent method of writing a uniform array of fpreal32 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 int64 value 
)

Efficent method of writing a uniform array of int64 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 int16 value 
)

Efficent method of writing a uniform array of int16 values.

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

Efficent method of writing a uniform array of int8 values.

bool UT_JSONWriter::jsonValue ( fpreal64  value  )  [inline]

Definition at line 126 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( fpreal32  value  )  [inline]

Definition at line 125 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( fpreal16  value  )  [inline]

Definition at line 124 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( int64  value  )  [inline]

Definition at line 123 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( int32  value  )  [inline]

Definition at line 122 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( int16  value  )  [inline]

Definition at line 121 of file UT_JSONWriter.h.

bool UT_JSONWriter::jsonValue ( int8  value  )  [inline]

Definition at line 120 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 119 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 [12]
  • 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]

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

Write a string 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 ( uint8  value  ) 

Write an 8 bit unsigned integer 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 ( fpreal32  value  ) 

Write an 32 bit float/real 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 ( int64  value  ) 

Write an 64 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 ( int16  value  ) 

Write an 16 bit integer value to the uniform array.

bool UT_JSONWriter::uniformWrite ( int8  value  ) 

Write an 8 bit integer value 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).

virtual bool UT_JSONWriter::writeData ( const void *  data,
int64  bytes 
) [protected, pure virtual]

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


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

Generated on Mon Jan 28 00:30:11 2013 for HDK by  doxygen 1.5.9