HDK
|
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 () | |
UT_JSONParser (const UT_JSONParser &)=delete | |
UT_JSONParser & | operator= (const UT_JSONParser &)=delete |
bool | seekg (exint pos, int dir, bool reset=true) |
UT_IStream * | getInternalStream () |
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_StringArray & | getErrors () 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) |
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:
There are several ways to use a UT_JSONParser instance to parse a JSON stream.
Definition at line 87 of file UT_JSONParser.h.
typedef iterator UT_JSONParser::traverser |
Definition at line 700 of file UT_JSONParser.h.
UT_JSONParser::UT_JSONParser | ( | ) |
UT_JSONParser::~UT_JSONParser | ( | ) |
|
delete |
void UT_JSONParser::addFatal | ( | const char * | fmt, |
... | |||
) |
Add an error message. If the terminate flag is set, parsing will be terminated.
|
inline |
Definition at line 703 of file UT_JSONParser.h.
|
inline |
Definition at line 702 of file UT_JSONParser.h.
|
inline |
Returns whether we're reading a binary or ASCII file.
Definition at line 456 of file UT_JSONParser.h.
|
inline |
Get resulting warnings/errors.
Definition at line 449 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 |
|
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 473 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.
|
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 374 of file UT_JSONParser.h.
|
delete |
|
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 239 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.
|
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 437 of file UT_JSONParser.h.
|
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 426 of file UT_JSONParser.h.
|
inline |
Alternate short-form.
Definition at line 147 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 | ) |
|
inline |
Definition at line 156 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 | ) |
|
inline |
Definition at line 162 of file UT_JSONParser.h.
bool UT_JSONParser::parseObject | ( | UT_JSONHandle & | handle, |
UT_IStream * | is = 0 |
||
) |
Parse a single object.
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.
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.
Definition at line 182 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.
|
inline |
Definition at line 164 of file UT_JSONParser.h.
|
inline |
Definition at line 165 of file UT_JSONParser.h.
|
inline |
Definition at line 166 of file UT_JSONParser.h.
|
inline |
Definition at line 167 of file UT_JSONParser.h.
|
inline |
Definition at line 168 of file UT_JSONParser.h.
|
inline |
Definition at line 169 of file UT_JSONParser.h.
|
inline |
Definition at line 170 of file UT_JSONParser.h.
|
inline |
Definition at line 171 of file UT_JSONParser.h.
|
inline |
Definition at line 172 of file UT_JSONParser.h.
|
inline |
Definition at line 173 of file UT_JSONParser.h.
|
inline |
Definition at line 174 of file UT_JSONParser.h.
|
inline |
Definition at line 175 of file UT_JSONParser.h.
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.
bool UT_JSONParser::readString | ( | UT_StringHolder & | result | ) |
Convenience method to read a binary encoded string.
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).
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).
Convenience method to a int8 values.
Definition at line 476 of file UT_JSONParser.h.
Convenience method to read int16 values (possibly byte-swapped)
Convenience method to read int32 values (possibly byte-swapped)
Convenience method to read int64 values (possibly byte-swapped)
Convenience method to read uint8 values.
Definition at line 485 of file UT_JSONParser.h.
Convenience method to read uint16 values (possibly byte-swapped)
Convenience method to read uint32 values (possibly byte-swapped)
Convenience method to read uint64 values (possibly byte-swapped)
Convenience method to read fpreal16 values (possibly byte-swapped)
Convenience method to read fpreal32 values (possibly byte-swapped)
Convenience method to read fpreal64 values (possibly byte-swapped)
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.
|
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 112 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)
|
friend |
Definition at line 836 of file UT_JSONParser.h.
Definition at line 90 of file UT_JSONParser.h.