HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_JSONParser Class Reference

JSON reader class which handles parsing of JSON or bJSON files. More...

#include <UT_JSONParser.h>

Classes

class  iterator
 Traverse an array object in the parser. More...
 
class  TiledStream
 
class  TiledStreamBuf
 

Public Types

typedef iterator traverser
 

Public Member Functions

 UT_JSONParser ()
 
 ~UT_JSONParser ()
 
bool seekg (exint pos, int dir, bool reset=true)
 
UT_IStreamgetInternalStream ()
 
void setBinary (bool isBinary)
 
bool parseObject (UT_JSONHandle &handle, UT_IStream *is=0)
 
bool parseBool (bool &v)
 
bool parseInteger (int64 &v)
 
bool parseInt (int64 &v)
 Alternate short-form. More...
 
bool parseReal (fpreal64 &v)
 
bool parseNumber (int8 &v)
 Generic parsing of a number (int) More...
 
bool parseNumber (int16 &v)
 
bool parseNumber (int32 &v)
 
bool parseNumber (int64 &v)
 
bool parseNumber (uint8 &v)
 
bool parseNumber (uint16 &v)
 
bool parseNumber (fpreal16 &v)
 Generic parsing of a number (real) More...
 
bool parseNumber (fpreal32 &v)
 
bool parseNumber (fpreal64 &v)
 
bool parseValue (UT_WorkBuffer &v)
 
bool parseValue (UT_StringHolder &v)
 
bool parseValue (bool &v)
 
bool parseValue (int8 &v)
 
bool parseValue (int16 &v)
 
bool parseValue (int32 &v)
 
bool parseValue (int64 &v)
 
bool parseValue (uint8 &v)
 
bool parseValue (uint16 &v)
 
bool parseValue (fpreal16 &v)
 
bool parseValue (fpreal32 &v)
 
bool parseValue (fpreal64 &v)
 
template<typename T >
int64 parseUniformArray (T *data, int64 len)
 
template<typename T >
int64 parseArrayValues (iterator &it, T *data, int64 len)
 
int64 parseUniformBoolArray (UT_BitArray &data, int64 len)
 
template<typename OP_TYPE , typename POD_TYPE >
bool loadPODArray (OP_TYPE &op)
 
bool parseBeginMap (bool &error)
 
bool parseBeginArray (bool &error)
 
bool parseEndMap (bool &error)
 
bool parseEndArray (bool &error)
 
bool skipNextObject ()
 Simple convenience method to skip the next object in the stream. More...
 
const UT_StringArraygetErrors () const
 Get resulting warnings/errors. More...
 
bool readBytes (void *data, exint bytes)
 
bool getBinary () const
 Returns whether we're reading a binary or ASCII file. More...
 
int64 getStreamLineCount () const
 Returns the current position in the input stream. More...
 
int64 getStreamLineStartPosition () const
 
int64 getStreamPosition () const
 
bool isRandomAccessFile (UT_WorkBuffer &filename) const
 
bool getSwapFlag () const
 
bool readValue (int8 *v, exint n)
 Convenience method to a int8 values. More...
 
bool readValue (int16 *v, exint n)
 Convenience method to read int16 values (possibly byte-swapped) More...
 
bool readValue (int32 *v, exint n)
 Convenience method to read int32 values (possibly byte-swapped) More...
 
bool readValue (int64 *v, exint n)
 Convenience method to read int64 values (possibly byte-swapped) More...
 
bool readValue (uint8 *v, exint n)
 Convenience method to read uint8 values. More...
 
bool readValue (uint16 *v, exint n)
 Convenience method to read uint16 values (possibly byte-swapped) More...
 
bool readValue (uint32 *v, exint n)
 Convenience method to read uint32 values (possibly byte-swapped) More...
 
bool readValue (uint64 *v, exint n)
 Convenience method to read uint64 values (possibly byte-swapped) More...
 
bool readValue (fpreal16 *v, exint n)
 Convenience method to read fpreal16 values (possibly byte-swapped) More...
 
bool readValue (fpreal32 *v, exint n)
 Convenience method to read fpreal32 values (possibly byte-swapped) More...
 
bool readValue (fpreal64 *v, exint n)
 Convenience method to read fpreal64 values (possibly byte-swapped) More...
 
void addFatal (const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
 
void void addWarning (const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
 
void void void stealErrors (const UT_JSONParser &parser)
 Steal errors from another parser (leaves the other parser intact) More...
 
iterator beginMap ()
 
iterator beginArray ()
 
bool parseString (UT_WorkBuffer &v)
 
bool parseString (UT_StringHolder &v)
 
bool parseKey (UT_WorkBuffer &v)
 
bool parseKey (UT_StringHolder &v)
 
bool readString (UT_WorkBuffer &storage)
 
bool readString (UT_StringHolder &result)
 
bool readStringToken (UT_WorkBuffer &storage)
 
bool readStringToken (UT_StringHolder &str)
 

Public Attributes

class UT_API iterator
 

Friends

class UT_AutoJSONParser
 
bool readUniformArray (int16 *buffer, int64 buffer_size)
 
bool readUniformArray (int32 *buffer, int64 buffer_size)
 
bool readUniformArray (int64 *buffer, int64 buffer_size)
 
bool readUniformArray (uint8 *buffer, int64 buffer_size)
 
bool readUniformArray (uint16 *buffer, int64 buffer_size)
 
bool readUniformArray (fpreal16 *buffer, int64 buffer_size)
 
bool readUniformArray (fpreal32 *buffer, int64 buffer_size)
 
bool readUniformArray (fpreal64 *buffer, int64 buffer_size)
 

Detailed Description

JSON reader class which handles parsing of JSON or bJSON files.

The JSON format (http://www.json.org) is a generic way to store data. Houdini extends JSON to a byte-stream binary encoding. This class is used to parse JSON (binary or ASCII) and provides callbacks to handle the data.

For binary JSON files, Houdini has extended JSON slightly to support compact versions for specific data representations. The ua methods callback methods on the JSONHandle are used to process a uniform array of simple types. Data for the uniform array can be read directly from the stream. Care must be taken for uaBool() and uaString() which encode the array data. uaReadString() can be used to read a string from the data stream. The uniform array of uaBool encodes the bits into 32-bit words.

The standard implementation of the uaInt16() method is:

bool
UT_JSONParser::uaInt16(int64 length) {
if (!jsonBeginArray())
return false;
for (int64 i=0; i < length; i++) {
if (!read(&value, sizeof(int16)))
return false;
if (getSwapFlag())
UTswapBytes(&value, 1);
if (!jsonInt(value))
return false;
}
return jsonEndArray();
}
See Also
UT_JID, UT_JSONHandle
Examples:
packedshareddata/GU_PackedSharedData.C, tetprim/GEO_PrimTetra.C, and tetprim/GEO_PrimTetra.h.

Definition at line 72 of file UT_JSONParser.h.

Member Typedef Documentation

Definition at line 682 of file UT_JSONParser.h.

Constructor & Destructor Documentation

UT_JSONParser::UT_JSONParser ( )
UT_JSONParser::~UT_JSONParser ( )

Member Function Documentation

void UT_JSONParser::addFatal ( const char *  fmt,
  ... 
)

Add an error message. If the terminate flag is set, parsing will be terminated.

void void UT_JSONParser::addWarning ( const char *  fmt,
  ... 
)
iterator UT_JSONParser::beginArray ( )
inline

Definition at line 685 of file UT_JSONParser.h.

iterator UT_JSONParser::beginMap ( )
inline

Definition at line 684 of file UT_JSONParser.h.

bool UT_JSONParser::getBinary ( ) const
inline

Returns whether we're reading a binary or ASCII file.

Definition at line 438 of file UT_JSONParser.h.

const UT_StringArray& UT_JSONParser::getErrors ( ) const
inline

Get resulting warnings/errors.

Definition at line 431 of file UT_JSONParser.h.

UT_IStream* UT_JSONParser::getInternalStream ( )

Retrieves the stream that is being used internally to read This is used for seekable geometry files to read the footer without parsing it as JSON. Normally using this should be avoided.

int64 UT_JSONParser::getStreamLineCount ( ) const

Returns the current position in the input stream.

int64 UT_JSONParser::getStreamLineStartPosition ( ) const
int64 UT_JSONParser::getStreamPosition ( ) const
bool UT_JSONParser::getSwapFlag ( ) const
inline

When reading raw binary data, this returns whether the endianness of the file is different than the endianness of the processor (requiring byte swapping). There are convenience methods to read integer/real data which automatically swap. However, when reading uniform arrays in batch mode, it is more efficient to swap the entire array rather than piecemeal.

Definition at line 455 of file UT_JSONParser.h.

bool UT_JSONParser::isRandomAccessFile ( UT_WorkBuffer filename) const

Returns the true and sets the filename if the stream supports random seeks.

template<typename OP_TYPE , typename POD_TYPE >
bool UT_JSONParser::loadPODArray ( OP_TYPE &  op)
inline

Load an entire array of POD data using the operator passed in. This method may allocate a temporary buffer to load a uniform array.

Definition at line 356 of file UT_JSONParser.h.

template<typename T >
int64 UT_JSONParser::parseArrayValues ( iterator it,
T data,
int64  len 
)
inline

A utility method to load blocks of values from an array which can load data from uniform arrays very efficiently. Returns the number of elements successfully extracted from the parser. A maximum of len elements will be saved in data.

Definition at line 221 of file UT_JSONParser.h.

bool UT_JSONParser::parseBeginArray ( bool &  error)

Returns true if the next token was the start of an array. If there was an error parsing the stream, then error will be set, otherwise the error parameter will remain unchanged.

bool UT_JSONParser::parseBeginMap ( bool &  error)

Returns true if the next token was the start of a map. If there was an error parsing the stream, then error will be set, otherwise the error parameter will remain unchanged.

bool UT_JSONParser::parseBool ( bool &  v)

Simple convenience method to parse a single string (keys not valid) This is done by reading the next object using UT_JSONValue. The method fails if the next object in the stream is not a string.

bool UT_JSONParser::parseEndArray ( bool &  error)
inline

Returns true if the next token was an end of an array. If there was an error parsing the stream, then error will be set, otherwise the error parameter will remain unchanged.

Definition at line 419 of file UT_JSONParser.h.

bool UT_JSONParser::parseEndMap ( bool &  error)
inline

Returns true if the next token was an end map. If there was an error parsing the stream, then error will be set, otherwise the error parameter will remain unchanged.

Definition at line 408 of file UT_JSONParser.h.

bool UT_JSONParser::parseInt ( int64 v)
inline

Alternate short-form.

Definition at line 129 of file UT_JSONParser.h.

bool UT_JSONParser::parseInteger ( int64 v)

Simple convenience method to parse a single integer This is done by reading the next object using UT_JSONValue The method fails if the next object in the stream is not a number or bool. Real values are cast to integers.

bool UT_JSONParser::parseKey ( UT_WorkBuffer v)

Simple convenience method to parse a single map key (strings not valid) This is done by reading the next object using UT_JSONValue The method fails if the next object in the stream is not a key.

bool UT_JSONParser::parseKey ( UT_StringHolder v)

Simple convenience method to parse a single map key (strings not valid) This is done by reading the next object using UT_JSONValue The method fails if the next object in the stream is not a key.

bool UT_JSONParser::parseNumber ( int8 v)

Generic parsing of a number (int)

bool UT_JSONParser::parseNumber ( int16 v)
bool UT_JSONParser::parseNumber ( int32 v)
bool UT_JSONParser::parseNumber ( int64 v)
inline

Definition at line 138 of file UT_JSONParser.h.

bool UT_JSONParser::parseNumber ( uint8 v)
bool UT_JSONParser::parseNumber ( uint16 v)
bool UT_JSONParser::parseNumber ( fpreal16 v)

Generic parsing of a number (real)

bool UT_JSONParser::parseNumber ( fpreal32 v)
bool UT_JSONParser::parseNumber ( fpreal64 v)
inline

Definition at line 144 of file UT_JSONParser.h.

bool UT_JSONParser::parseObject ( UT_JSONHandle handle,
UT_IStream is = 0 
)

Parse a single object.

Parameters
handle
The UT_JSONHandle to perform interpretation of the JSON tokens
is
If specified, data will be read from this stream. The initial parseObject() call must have a stream.
bool UT_JSONParser::parseReal ( fpreal64 v)

Simple convenience method to parse a single real This is done by reading the next object using UT_JSONValue The method fails if the next object in the stream is not a number

bool UT_JSONParser::parseString ( UT_WorkBuffer v)

Simple convenience method to parse a single string (keys not valid) This is done by reading the next object using UT_JSONValue. The method fails if the next object in the stream is not a string.

bool UT_JSONParser::parseString ( UT_StringHolder v)

Simple convenience method to parse a single string (keys not valid) This is done by reading the next object using UT_JSONValue. The method fails if the next object in the stream is not a string.

template<typename T >
int64 UT_JSONParser::parseUniformArray ( T data,
int64  len 
)
inline

A utility method to load a uniform array of data (ie. those written out by UT_JSONWriter::uniformArray()). Returns the number of elements successfully extracted from the parser. A maximum of len elements will be saved in data.

Examples:
tetprim/GEO_PrimTetra.C.

Definition at line 164 of file UT_JSONParser.h.

int64 UT_JSONParser::parseUniformBoolArray ( UT_BitArray data,
int64  len 
)

A utility method to load a uniform array of data (ie. those written out by UT_JSONWriter::uniformArray()). Returns the number of elements successfully extracted from the parser. A maximum of len elements will be saved in data.

bool UT_JSONParser::parseValue ( UT_WorkBuffer v)
inline

Definition at line 146 of file UT_JSONParser.h.

bool UT_JSONParser::parseValue ( UT_StringHolder v)
inline

Definition at line 147 of file UT_JSONParser.h.

bool UT_JSONParser::parseValue ( bool &  v)
inline

Definition at line 148 of file UT_JSONParser.h.

bool UT_JSONParser::parseValue ( int8 v)
inline

Definition at line 149 of file UT_JSONParser.h.

bool UT_JSONParser::parseValue ( int16 v)
inline

Definition at line 150 of file UT_JSONParser.h.

bool UT_JSONParser::parseValue ( int32 v)
inline

Definition at line 151 of file UT_JSONParser.h.

bool UT_JSONParser::parseValue ( int64 v)
inline

Definition at line 152 of file UT_JSONParser.h.

bool UT_JSONParser::parseValue ( uint8 v)
inline

Definition at line 153 of file UT_JSONParser.h.

bool UT_JSONParser::parseValue ( uint16 v)
inline

Definition at line 154 of file UT_JSONParser.h.

bool UT_JSONParser::parseValue ( fpreal16 v)
inline

Definition at line 155 of file UT_JSONParser.h.

bool UT_JSONParser::parseValue ( fpreal32 v)
inline

Definition at line 156 of file UT_JSONParser.h.

bool UT_JSONParser::parseValue ( fpreal64 v)
inline

Definition at line 157 of file UT_JSONParser.h.

bool UT_JSONParser::readBytes ( void data,
exint  bytes 
)

The read method should be called whenever data needs to be read from the stream. It keeps line counts & character offsets.

bool UT_JSONParser::readString ( UT_WorkBuffer storage)

Convenience method to read a binary encoded string.

Note
This should be used when reading uniform arrays of UT_JID_STRING type.
bool UT_JSONParser::readString ( UT_StringHolder result)

Convenience method to read a binary encoded string.

Note
This should be used when reading uniform arrays of UT_JID_STRING type.
bool UT_JSONParser::readStringToken ( UT_WorkBuffer storage)

Convenience method to read a binary encoded string token. Instead of reading an encoded string (readString()), an integer token will be read. This indexes the shared string table (see UT_JID_TOKENDEF, UT_JID_TOKENREF).

Note
This should be used when reading uniform arrays of UT_JID_TOKENREF type.
bool UT_JSONParser::readStringToken ( UT_StringHolder str)

Convenience method to read a binary encoded string token. Instead of reading an encoded string (readString()), an integer token will be read. This indexes the shared string table (see UT_JID_TOKENDEF, UT_JID_TOKENREF).

Note
This should be used when reading uniform arrays of UT_JID_TOKENREF type.
bool UT_JSONParser::readUniformArray ( int16 buffer,
int64  buffer_size 
)

Used by iterator

bool UT_JSONParser::readUniformArray ( int32 buffer,
int64  buffer_size 
)

Used by iterator

bool UT_JSONParser::readUniformArray ( int64 buffer,
int64  buffer_size 
)

Used by iterator

bool UT_JSONParser::readUniformArray ( uint8 buffer,
int64  buffer_size 
)

Used by iterator

bool UT_JSONParser::readUniformArray ( uint16 buffer,
int64  buffer_size 
)

Used by iterator

bool UT_JSONParser::readUniformArray ( fpreal16 buffer,
int64  buffer_size 
)

Used by iterator

bool UT_JSONParser::readUniformArray ( fpreal32 buffer,
int64  buffer_size 
)

Used by iterator

bool UT_JSONParser::readUniformArray ( fpreal64 buffer,
int64  buffer_size 
)

Used by iterator

bool UT_JSONParser::readValue ( int8 v,
exint  n 
)
inline

Convenience method to a int8 values.

Definition at line 458 of file UT_JSONParser.h.

bool UT_JSONParser::readValue ( int16 v,
exint  n 
)

Convenience method to read int16 values (possibly byte-swapped)

bool UT_JSONParser::readValue ( int32 v,
exint  n 
)

Convenience method to read int32 values (possibly byte-swapped)

bool UT_JSONParser::readValue ( int64 v,
exint  n 
)

Convenience method to read int64 values (possibly byte-swapped)

bool UT_JSONParser::readValue ( uint8 v,
exint  n 
)
inline

Convenience method to read uint8 values.

Definition at line 467 of file UT_JSONParser.h.

bool UT_JSONParser::readValue ( uint16 v,
exint  n 
)

Convenience method to read uint16 values (possibly byte-swapped)

bool UT_JSONParser::readValue ( uint32 v,
exint  n 
)

Convenience method to read uint32 values (possibly byte-swapped)

bool UT_JSONParser::readValue ( uint64 v,
exint  n 
)

Convenience method to read uint64 values (possibly byte-swapped)

bool UT_JSONParser::readValue ( fpreal16 v,
exint  n 
)

Convenience method to read fpreal16 values (possibly byte-swapped)

bool UT_JSONParser::readValue ( fpreal32 v,
exint  n 
)

Convenience method to read fpreal32 values (possibly byte-swapped)

bool UT_JSONParser::readValue ( fpreal64 v,
exint  n 
)

Convenience method to read fpreal64 values (possibly byte-swapped)

bool UT_JSONParser::seekg ( exint  pos,
int  dir,
bool  reset = true 
)

Seek the parser to a specific location in stream (see streams seekg) If the reset flag is true then the parser will be reset so it expects to see the beginning of a JSON stream.

void UT_JSONParser::setBinary ( bool  isBinary)
inline

Set's binary to given value. This is used to read BJSON without having the magic infront of it (for embedded geometry)

Definition at line 94 of file UT_JSONParser.h.

bool UT_JSONParser::skipNextObject ( )

Simple convenience method to skip the next object in the stream.

void void void UT_JSONParser::stealErrors ( const UT_JSONParser parser)

Steal errors from another parser (leaves the other parser intact)

Friends And Related Function Documentation

friend class UT_AutoJSONParser
friend

Definition at line 815 of file UT_JSONParser.h.

Member Data Documentation

Definition at line 75 of file UT_JSONParser.h.


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