HDK
|
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 |
void | setPrecision (int precision) |
Direct access to options. More... | |
int | getPrecision () const |
void | setIndentStep (int indentstep) |
int | getIndentStep () const |
void | setUseTokens (bool usetokens) |
bool | getUseTokens () const |
void | setTextWidth (int width) |
int | getTextWidth () const |
void | setComments (bool comment) |
bool | getComments () const |
void | setPrettyPrint (bool prettyprint) |
bool | getPrettyPrint () const |
void | setPrettyCompact (bool compact) |
bool | getPrettyCompact () 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 | jsonRealPreserveType (fpreal16 value) |
bool | jsonReal (fpreal32 value) |
Write a 32 bit real. More... | |
bool | jsonRealPreserveType (fpreal32 value) |
bool | jsonReal (fpreal64 value) |
Write a 64 bit real. More... | |
bool | jsonRealPreserveType (fpreal64 value) |
bool | jsonString (const char *value, int64 length=0) |
bool | jsonStringToken (const UT_StringRef &value) |
bool | jsonStringToken (const char *value, int64 length) |
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 | jsonValue (bool value) |
bool | jsonValue (int8 value) |
bool | jsonValue (int16 value) |
bool | jsonValue (int32 value) |
bool | jsonValue (unsigned value) |
bool | jsonValue (int64 value) |
bool | jsonValue (fpreal16 value) |
bool | jsonValue (fpreal32 value) |
bool | jsonValue (fpreal64 value) |
bool | jsonValue (const char *v) |
bool | jsonValue (const UT_String &v) |
bool | jsonValue (const std::string &v) |
bool | jsonValue (const UT_StringRef &v) |
bool | jsonValue (const UT_Int16Array &v) |
bool | jsonValue (const UT_Int32Array &v) |
bool | jsonValue (const UT_Int64Array &v) |
bool | jsonValue (const UT_Fpreal32Array &v) |
bool | jsonValue (const UT_Fpreal64Array &v) |
bool | jsonValue (const UT_StringArray &v) |
bool | jsonValue (const UT_JSONValue &v) |
template<typename T > | |
SYS_FORCE_INLINE bool | jsonKeyValue (const UT_StringRef &key, const T &value) |
template<typename T > | |
SYS_FORCE_INLINE bool | jsonKeyTokenValue (const UT_StringRef &key, const T &value) |
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_JSONWriter * | allocWriter (UT_WorkBuffer &buffer) |
static UT_JSONWriter * | allocWriter (std::ostream &os, bool binary, UT_CompressionType compressionType=UT_COMPRESSION_TYPE_NONE) |
static UT_JSONWriter * | allocWriter (const char *filename, bool binary, UT_CompressionType compressionType=UT_COMPRESSION_TYPE_NONE) |
static UT_JSONWriter * | allocWriter (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... | |
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.
Definition at line 34 of file UT_JSONWriter.h.
UT_JSONWriter::UT_JSONWriter | ( | const UT_Options * | options = 0 | ) |
options | A UT_Options class which sets specific format options. |
|
virtual |
|
static |
Allocate a JSON Writer which will fill a UT_WorkBuffer. Please delete when finished with the writer.
|
static |
Allocate a JSON Writer which writes to an output stream. Please delete when finished with the writer.
|
static |
Allocate a JSON Writer which writes to a named file. Please delete when finished with the writer.
|
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.
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:
void UT_JSONWriter::endNewFile | ( | ) |
End a started embedded file.
bool UT_JSONWriter::endUniformArray | ( | int64 * | nwritten = 0 | ) |
End the uniform array.
nwritten | If provided, the number of items written is returned. |
|
inline |
Return whether writing binary or ASCII JSON.
Definition at line 107 of file UT_JSONWriter.h.
|
inline |
Definition at line 94 of file UT_JSONWriter.h.
|
inline |
Definition at line 88 of file UT_JSONWriter.h.
|
inlineprotected |
Get the nesting level (i.e. how deeply nested in maps/arrays)
Definition at line 436 of file UT_JSONWriter.h.
|
inline |
Get the number of bytes written to output so far.
Definition at line 110 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()
|
inline |
Definition at line 86 of file UT_JSONWriter.h.
|
inline |
Definition at line 98 of file UT_JSONWriter.h.
|
inline |
Definition at line 96 of file UT_JSONWriter.h.
|
inline |
Definition at line 92 of file UT_JSONWriter.h.
|
inline |
Definition at line 90 of file UT_JSONWriter.h.
Returns the JID that matches the given type.
Definition at line 320 of file UT_JSONWriter.h.
Definition at line 321 of file UT_JSONWriter.h.
Definition at line 322 of file UT_JSONWriter.h.
Definition at line 323 of file UT_JSONWriter.h.
Definition at line 324 of file UT_JSONWriter.h.
Definition at line 325 of file UT_JSONWriter.h.
Definition at line 326 of file UT_JSONWriter.h.
Definition at line 327 of file UT_JSONWriter.h.
Definition at line 328 of file UT_JSONWriter.h.
Definition at line 329 of file UT_JSONWriter.h.
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 | ( | 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.
Write a quoted key for the object
usetokens
option in the constructor). 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.
Definition at line 211 of file UT_JSONWriter.h.
|
inline |
Convenience method to write the key/value pair to a map
Definition at line 231 of file UT_JSONWriter.h.
|
inline |
Convenience method to write the key/value pair to a map
Definition at line 224 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::jsonRealPreserveType | ( | fpreal16 | value | ) |
bool UT_JSONWriter::jsonRealPreserveType | ( | fpreal32 | value | ) |
bool UT_JSONWriter::jsonRealPreserveType | ( | fpreal64 | value | ) |
Write a quoted string.
usetokens
option in the constructor). 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.
Definition at line 156 of file UT_JSONWriter.h.
bool UT_JSONWriter::jsonStringTokenArray | ( | const UT_StringArray & | a | ) |
Convenience method to save an array of strings (as tokens)
Efficent method of writing a uniform array of int8 values.
Efficent method of writing a uniform array of int16 values.
Efficent method of writing a uniform array of int32 values.
Efficent method of writing a uniform array of int64 values.
Efficent method of writing a uniform array of fpreal16 values.
Efficent method of writing a uniform array of fpreal32 values.
Efficent method of writing a uniform array of fpreal64 values.
Efficent method of writing a uniform array of uint8 values.
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.
|
inline |
Convenience method for saving common array types
Definition at line 357 of file UT_JSONWriter.h.
|
inline |
Convenience method for saving common array types
Definition at line 359 of file UT_JSONWriter.h.
|
inline |
Convenience method for saving common array types
Definition at line 361 of file UT_JSONWriter.h.
|
inline |
Convenience method for saving common array types
Definition at line 363 of file UT_JSONWriter.h.
|
inline |
Convenience method for saving common array types
Definition at line 365 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 169 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 170 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 171 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 172 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 173 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 174 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 175 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 176 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 177 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 178 of file UT_JSONWriter.h.
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 179 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 181 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 183 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 184 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 186 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 188 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 190 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 192 of file UT_JSONWriter.h.
|
inline |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
Definition at line 194 of file UT_JSONWriter.h.
bool UT_JSONWriter::jsonValue | ( | const UT_JSONValue & | v | ) |
Write a standard JSON value to the stream. Overloaded method to allow convenient use in templated code.
bool UT_JSONWriter::setBinary | ( | bool | bin | ) |
Turn the JSON writer into a binary JSON (bJSON) writer.
|
inline |
Definition at line 93 of file UT_JSONWriter.h.
Definition at line 87 of file UT_JSONWriter.h.
void UT_JSONWriter::setOptions | ( | const UT_Options & | options | ) |
Set formatting/control options base on the UT_Options. The following options are scanned:
Direct access to options.
Definition at line 85 of file UT_JSONWriter.h.
|
inline |
Definition at line 97 of file UT_JSONWriter.h.
|
inline |
Definition at line 95 of file UT_JSONWriter.h.
Definition at line 91 of file UT_JSONWriter.h.
|
inline |
Definition at line 89 of file UT_JSONWriter.h.
void UT_JSONWriter::startNewFile | ( | ) |
Start a new embedded file.
|
protectedpure virtual |
The sub-class must implement this method to write data.
Write a block of 8 bit integer values to the uniform array.
Write a block of 16 bit integer values to the uniform array.
Write a block of 32 bit integer values to the uniform array.
Write a block of 64 bit integer values to the uniform array.
Write a block of 16 bit float/real values to the uniform array.
Write a block of 32 bit float/real values to the uniform array.
Write a block of 64 bit float/real values to the uniform array.
Write a block of 8 bit unsigned integer values to the uniform array.
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.
Write a string to the uniform array.
Internally called to write raw data to output.