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

Class to store JSON objects as C++ objects. More...

#include <UT_JSONValue.h>

Classes

class  indexed_map_traverser
 
class  indexed_traverser
 
class  json_proxy
 Used to iterate over a map from a json value. More...
 
class  map_traverser
 
class  traverser
 Traverse the children of the current value. More...
 

Public Types

enum  Type {
  JSON_NULL, JSON_BOOL, JSON_INT, JSON_REAL,
  JSON_STRING, JSON_KEY, JSON_ARRAY, JSON_MAP
}
 
using map_proxy = json_proxy< map_traverser >
 
using indexed_proxy = json_proxy< indexed_traverser >
 
using indexed_map_proxy = json_proxy< indexed_map_traverser >
 
using const_iterator = const traverser
 

Public Member Functions

 UT_JSONValue ()
 
 UT_JSONValue (Type type)
 
 UT_JSONValue (bool value)
 
 UT_JSONValue (int64 value)
 
 UT_JSONValue (fpreal64 value)
 
 UT_JSONValue (const char *string, int64 length=-1)
 
 UT_JSONValue (const UT_StringHolder &s)
 
 UT_JSONValue (const UT_JSONValue &v)
 
 ~UT_JSONValue ()
 
UT_JSONValueoperator= (const UT_JSONValue &v)
 
UT_JSONValue deepCopy () const
 
bool parseValue (UT_JSONParser &parser, UT_IStream *is=0, bool record_source_offsets=false)
 
bool parseValue (const UT_StringRef &json_source)
 
bool parseValue (std::istream &is)
 
bool loadFromFile (const char *file_name, bool record_source_offsets=false)
 Loads an entire JSON file into this value. More...
 
bool saveToFile (const char *file_name, bool binary=false, UT_CompressionType compressionType=UT_COMPRESSION_TYPE_NONE)
 Saves an entire JSON value to the specified file. More...
 
bool save (UT_JSONWriter &os) const
 Save the object the output stream. More...
 
void dump () const
 Dump the value to stdout (same as save to cout) More...
 
UT_StringHolder toString () const
 
SYS_NO_DISCARD_RESULT Type getType () const
 Get the type of data stored in the object. More...
 
SYS_NO_DISCARD_RESULT bool isMap () const
 
SYS_NO_DISCARD_RESULT bool isArray () const
 
SYS_NO_DISCARD_RESULT bool isNull () const
 
SYS_NO_DISCARD_RESULT bool isValueType () const
 
SYS_NO_DISCARD_RESULT bool getB () const
 Get the bool value. Interprets integer/float as bool. More...
 
SYS_NO_DISCARD_RESULT int64 getI () const
 
SYS_NO_DISCARD_RESULT fpreal64 getF () const
 Get the real value. Interprets bool/int as reals. More...
 
SYS_NO_DISCARD_RESULT const
UT_StringHolder
getString () const
 
SYS_NO_DISCARD_RESULT const char * getS () const
 Get the string value (may return a NULL pointer) More...
 
SYS_NO_DISCARD_RESULT int64 getSLength () const
 Return the string length (returns -1 if not a string) More...
 
SYS_NO_DISCARD_RESULT const
UT_StringHolder
getStringHolder () const
 Return the string value. More...
 
SYS_NO_DISCARD_RESULT int32 get (const UT_StringRef &key, int32 def_value) const
 
SYS_NO_DISCARD_RESULT int64 get (const UT_StringRef &key, int64 def_value) const
 
SYS_NO_DISCARD_RESULT
UT_StringHolder 
get (const UT_StringRef &key, const UT_StringRef &def_value) const
 
SYS_NO_DISCARD_RESULT
UT_StringArray 
get (const UT_StringRef &key, const UT_StringArray &def_value) const
 
SYS_NO_DISCARD_RESULT const char * getKey () const
 Get a key value. More...
 
SYS_NO_DISCARD_RESULT int64 getKeyLength () const
 Get the length of the key. More...
 
SYS_NO_DISCARD_RESULT const
UT_StringHolder
getKeyHolder () const
 Return a string holder for the key. More...
 
SYS_NO_DISCARD_RESULT
UT_JSONValueArray
getArray () const
 Get the array value (may return a NULL pointer) More...
 
SYS_NO_DISCARD_RESULT
UT_JSONValueMap
getMap () const
 Get the map value (may return a NULL pointer) More...
 
SYS_NO_DISCARD_RESULT Type getUniformArrayType () const
 
SYS_FORCE_INLINE bool import (bool &result) const
 Extract a bool (returns false if type is invalid) More...
 
SYS_FORCE_INLINE bool import (int64 &result) const
 Extract an integer (returns false if type is invalid) More...
 
SYS_FORCE_INLINE bool import (fpreal64 &result) const
 Extract an float (returns false if type is invalid) More...
 
bool import (UT_WorkBuffer &result) const
 Extract a string or key (returns false if type is invalid) More...
 
bool import (UT_StringHolder &result) const
 
bool import (int64 *result, int size) const
 
bool import (fpreal64 *result, int size) const
 
bool import (UT_Array< int64 > &array) const
 Extract a vector of integers from a JSON_Array. More...
 
bool import (UT_Array< fpreal64 > &array) const
 Extract a vector of reals from a JSON_Array. More...
 
bool import (UT_StringArray &array) const
 Extract a vector of strings from a JSON_Array. More...
 
template<typename T >
bool import (const UT_StringRef &key, T &reuslt) const
 Extract a value from the object. Only applies to json objects. More...
 
bool isNumber () const
 Returns whether the value can be interpreted as a number. More...
 
void setNull ()
 Set value to a null. More...
 
void setBool (bool v)
 Set value to an bool. More...
 
void setInt (int64 v)
 Set value to an int. More...
 
void setReal (fpreal64 v)
 Set value to an int. More...
 
void setString (const char *s, int64 length=-1)
 
void setString (const UT_StringHolder &s)
 
void setKey (const char *s, int64 length=-1)
 
void setKey (const UT_StringHolder &s)
 
void setArray (UT_JSONValueArray *array)
 Set value to the array. More...
 
void setMap (UT_JSONValueMap *map)
 Set value to the map. More...
 
UT_JSONValueArraystartArray ()
 Start building an array from scratch. More...
 
bool appendArray (const UT_JSONValue &v)
 
UT_JSONValueMapstartMap ()
 Start building a map from scratch. More...
 
bool appendMap (const UT_StringHolder &key, const UT_JSONValue &v)
 
UT_JSONValueMapaddMapChild (const UT_StringHolder &map_key)
 
UT_JSONValueArrayaddArrayChild (const UT_StringHolder &map_key)
 
bool setAsMap ()
 Set json value as a json map. More...
 
bool setAsArray ()
 Set json value as a json array. More...
 
SYS_NO_DISCARD_RESULT int getMapIndex () const
 Used internally by UT_JSONValueMap. More...
 
void setMapIndex (int i)
 Used internally by UT_JSONValueMap. More...
 
SYS_NO_DISCARD_RESULT int getSourceLine () const
 Used by UT_JSONValue parsing from a stream. More...
 
SYS_NO_DISCARD_RESULT int getSourceOffset () const
 
void setSourceOffset (int line, int offset)
 
SYS_NO_DISCARD_RESULT const
UT_JSONValue
operator() (int64 i) const
 
SYS_NO_DISCARD_RESULT
UT_JSONValue
operator() (int64 i)
 
SYS_NO_DISCARD_RESULT const
UT_JSONValue
operator() (const UT_StringRef &k) const
 
SYS_NO_DISCARD_RESULT
UT_JSONValue
operator() (const UT_StringRef &k)
 
SYS_NO_DISCARD_RESULT const
UT_JSONValue
operator[] (int64 i) const
 
SYS_NO_DISCARD_RESULT
UT_JSONValue
operator[] (int64 i)
 
SYS_NO_DISCARD_RESULT
UT_JSONValue
operator[] (const UT_StringRef &k)
 
SYS_NO_DISCARD_RESULT traverser begin ()
 
SYS_NO_DISCARD_RESULT traverser end ()
 
SYS_NO_DISCARD_RESULT
const_iterator 
begin () const
 
SYS_NO_DISCARD_RESULT
const_iterator 
end () const
 
SYS_NO_DISCARD_RESULT
const_iterator 
cbegin () const
 
SYS_NO_DISCARD_RESULT
const_iterator 
cend () const
 
SYS_NO_DISCARD_RESULT map_proxy items ()
 
SYS_NO_DISCARD_RESULT const
map_proxy 
items () const
 
SYS_NO_DISCARD_RESULT indexed_proxy enumerate ()
 
SYS_NO_DISCARD_RESULT const
indexed_proxy 
enumerate () const
 
SYS_NO_DISCARD_RESULT
indexed_map_proxy 
enumerateMap ()
 
SYS_NO_DISCARD_RESULT const
indexed_map_proxy 
enumerateMap () const
 
SYS_NO_DISCARD_RESULT traverser beginTraversal ()
 
SYS_NO_DISCARD_RESULT exint count () const
 Number of elements contained inside the json value. More...
 
std::pair< traverser, bool > insert (const UT_StringHolder &key, const UT_JSONValue &value)
 Add a key/value pair to the contained map. More...
 
template<typename... ARGS>
std::pair< traverser, bool > emplace (const UT_StringHolder &key, ARGS &&...args)
 Add an entry to the contained map. More...
 
traverser append (const UT_JSONValue &v)
 Insert a json value to the back of the contained array. More...
 
template<typename... ARGS>
traverser emplace_back (ARGS &&...args)
 Insert a json value to the back of the contained array. More...
 
traverser find (const UT_StringRef &key)
 
const_iterator find (const UT_StringRef &key) const
 
UT_JSONValueget (int64 idx)
 
const UT_JSONValueget (int64 idx) const
 
UT_JSONValueget (const UT_StringRef &k)
 
const UT_JSONValueget (const UT_StringRef &k) const
 
bool contains (const UT_StringRef &key) const
 
void remove (int64 index)
 
void erase (const UT_StringRef &k)
 
SYS_NO_DISCARD_RESULT
UT_JSONFindResult 
findValueRecursive (const UT_StringHolder &map_key, const char *key_value)
 
SYS_NO_DISCARD_RESULT
UT_JSONFindResult 
findParentValueRecursive (const UT_StringHolder &map_key, const char *key_value)
 
void removeNullValuesRecursive ()
 
SYS_NO_DISCARD_RESULT SYS_HashType hash () const
 Compute a hash. More...
 
bool setUniformArray (int nvalues, const int32 *data)
 
bool setUniformArray (int nvalues, const int64 *data)
 
bool setUniformArray (int nvalues, const fpreal16 *data)
 
bool setUniformArray (int nvalues, const fpreal32 *data)
 
bool setUniformArray (int nvalues, const fpreal64 *data)
 
bool setUniformArray (int nvalues, const UT_StringHolder *data)
 
SYS_NO_DISCARD_RESULT bool operator== (const UT_JSONValue &src) const
 
SYS_NO_DISCARD_RESULT bool operator!= (const UT_JSONValue &src) const
 

Detailed Description

Class to store JSON objects as C++ objects.

This class is able to represent a JSON object in its entirety. Arrays and Maps store arrays and maps of JSON values.

There are methods to load a JSONValue from a UT_JSONParser and to save to a UT_JSONWriter object.

To load an entire JSON file into memory, you can do something like

UT_JSONIStream *is(utistream);
if (!value.load(parser, *is))
reportFailure(parser.getErrors());

To save a value:

UT_JSONWriterSubclass &os;
value.save(os);

Alternatively, it's possible to use the UT_JSONValue class from within other UT_JSONHandle classes. For example, when loading key/value pairs for an arbitrary map:

bool
my_handle::jsonKey(UT_JSONParser &parser, const char *token, int64)
{
UT_String keyword;
keyword.harden(token);
if (!value.load(parser))
return false;
process(keyword, value);
return true;
}
See Also
UT_JSONParser, UT_JSONWriter, UT_JSONHandle, UT_JSONValueArray, UT_JSONValueMap
Examples:
mocapstream/MocapStreamRokokoHDK.C, packedshareddata/GU_PackedSharedData.C, tetprim/GEO_PrimTetra.C, and tetprim/GEO_PrimTetra.h.

Definition at line 99 of file UT_JSONValue.h.

Member Typedef Documentation

Definition at line 795 of file UT_JSONValue.h.

Definition at line 791 of file UT_JSONValue.h.

Member Enumeration Documentation

Types held in the UT_JSONValue. The number type has been broken out into an integer and a real.

Enumerator
JSON_NULL 
JSON_BOOL 
JSON_INT 
JSON_REAL 
JSON_STRING 
JSON_KEY 
JSON_ARRAY 
JSON_MAP 

Definition at line 104 of file UT_JSONValue.h.

Constructor & Destructor Documentation

UT_JSONValue::UT_JSONValue ( )
UT_JSONValue::UT_JSONValue ( Type  type)
explicit
UT_JSONValue::UT_JSONValue ( bool  value)
explicit
UT_JSONValue::UT_JSONValue ( int64  value)
explicit
UT_JSONValue::UT_JSONValue ( fpreal64  value)
explicit
UT_JSONValue::UT_JSONValue ( const char *  string,
int64  length = -1 
)
explicit
UT_JSONValue::UT_JSONValue ( const UT_StringHolder s)
explicit
UT_JSONValue::UT_JSONValue ( const UT_JSONValue v)
UT_JSONValue::~UT_JSONValue ( )

Member Function Documentation

UT_JSONValueArray* UT_JSONValue::addArrayChild ( const UT_StringHolder map_key)

Adds a new array child to this value. The current value must be either an array or a map. If this value is an array, the map_key parameter is ignored. This is due to overly convoluted JSON syntax design.

UT_JSONValueMap* UT_JSONValue::addMapChild ( const UT_StringHolder map_key)

Adds a new map child to this value. The current value must be either an array or a map. If this value is an array, the map_key parameter is ignored. This is due to overly convoluted JSON syntax design.

traverser UT_JSONValue::append ( const UT_JSONValue v)

Insert a json value to the back of the contained array.

bool UT_JSONValue::appendArray ( const UT_JSONValue v)

Add an element to an array (returns false if operation fails) The current value must be an array object

bool UT_JSONValue::appendMap ( const UT_StringHolder key,
const UT_JSONValue v 
)

Add an element to a map (returns false if operation fails) The current value must be a map object

SYS_NO_DISCARD_RESULT traverser UT_JSONValue::begin ( void  )
inline

{@ Iterate over contained values. Map: iterate over the json values of the map (excludes keys). Array: iterate over the json values in the array. Value: iterate over the single element contained in the json value.

Definition at line 801 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT const_iterator UT_JSONValue::begin ( void  ) const
inline

Definition at line 803 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT traverser UT_JSONValue::beginTraversal ( )
inline

Definition at line 858 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT const_iterator UT_JSONValue::cbegin ( ) const
inline

Definition at line 811 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT const_iterator UT_JSONValue::cend ( ) const
inline

Definition at line 815 of file UT_JSONValue.h.

bool UT_JSONValue::contains ( const UT_StringRef key) const

{@ Check if a key exists on the map.

SYS_NO_DISCARD_RESULT exint UT_JSONValue::count ( ) const

Number of elements contained inside the json value.

UT_JSONValue UT_JSONValue::deepCopy ( ) const

Normally JSON values store shared pointers to the array and map objects. This method will make a deep copy of the JSON Value.

void UT_JSONValue::dump ( ) const

Dump the value to stdout (same as save to cout)

template<typename... ARGS>
std::pair<traverser, bool> UT_JSONValue::emplace ( const UT_StringHolder key,
ARGS &&...  args 
)
inline

Add an entry to the contained map.

Definition at line 870 of file UT_JSONValue.h.

template<typename... ARGS>
traverser UT_JSONValue::emplace_back ( ARGS &&...  args)
inline

Insert a json value to the back of the contained array.

Definition at line 881 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT traverser UT_JSONValue::end ( void  )
inline

Definition at line 802 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT const_iterator UT_JSONValue::end ( void  ) const
inline

Definition at line 807 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT indexed_proxy UT_JSONValue::enumerate ( )
inline

{@ Return a proxy indexed object to iterate over [index, value] on the contained object.

Definition at line 837 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT const indexed_proxy UT_JSONValue::enumerate ( ) const
inline

Definition at line 842 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT indexed_map_proxy UT_JSONValue::enumerateMap ( )
inline

Definition at line 847 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT const indexed_map_proxy UT_JSONValue::enumerateMap ( ) const
inline

Definition at line 852 of file UT_JSONValue.h.

void UT_JSONValue::erase ( const UT_StringRef k)

{@ Erase an element by map key.

traverser UT_JSONValue::find ( const UT_StringRef key)

{@ Find the value contained in the json object by key. The json value must be a map object.

const_iterator UT_JSONValue::find ( const UT_StringRef key) const
SYS_NO_DISCARD_RESULT UT_JSONFindResult UT_JSONValue::findParentValueRecursive ( const UT_StringHolder map_key,
const char *  key_value 
)
SYS_NO_DISCARD_RESULT UT_JSONFindResult UT_JSONValue::findValueRecursive ( const UT_StringHolder map_key,
const char *  key_value 
)

Searches all children of this value recursively for another value with a child that contains the given map key set to the given value.

SYS_NO_DISCARD_RESULT int64 UT_JSONValue::get ( const UT_StringRef key,
int64  def_value 
) const
SYS_NO_DISCARD_RESULT UT_StringHolder UT_JSONValue::get ( const UT_StringRef key,
const UT_StringRef def_value 
) const
SYS_NO_DISCARD_RESULT UT_StringArray UT_JSONValue::get ( const UT_StringRef key,
const UT_StringArray def_value 
) const
UT_JSONValue* UT_JSONValue::get ( int64  idx)

{@ Access a value by index. nullptr is returned if the element does not exist.

const UT_JSONValue* UT_JSONValue::get ( int64  idx) const
UT_JSONValue* UT_JSONValue::get ( const UT_StringRef k)

{@ Lookup a value by key. The key is allowed to not exist.

const UT_JSONValue* UT_JSONValue::get ( const UT_StringRef k) const
SYS_NO_DISCARD_RESULT UT_JSONValueArray* UT_JSONValue::getArray ( ) const

Get the array value (may return a NULL pointer)

SYS_NO_DISCARD_RESULT bool UT_JSONValue::getB ( ) const

Get the bool value. Interprets integer/float as bool.

Examples:
mocapstream/MocapStreamRokokoHDK.C.
SYS_NO_DISCARD_RESULT fpreal64 UT_JSONValue::getF ( ) const

Get the real value. Interprets bool/int as reals.

Examples:
mocapstream/MocapStreamRokokoHDK.C.
SYS_NO_DISCARD_RESULT int64 UT_JSONValue::getI ( ) const

Get the integer value. Intereprets bool/real as integer

Note
Real values are cast to integer.
SYS_NO_DISCARD_RESULT const char* UT_JSONValue::getKey ( ) const

Get a key value.

SYS_NO_DISCARD_RESULT const UT_StringHolder* UT_JSONValue::getKeyHolder ( ) const

Return a string holder for the key.

SYS_NO_DISCARD_RESULT int64 UT_JSONValue::getKeyLength ( ) const

Get the length of the key.

SYS_NO_DISCARD_RESULT UT_JSONValueMap* UT_JSONValue::getMap ( ) const

Get the map value (may return a NULL pointer)

Examples:
mocapstream/MocapStreamRokokoHDK.C, and packedshareddata/GU_PackedSharedData.C.
SYS_NO_DISCARD_RESULT int UT_JSONValue::getMapIndex ( ) const
inline

Used internally by UT_JSONValueMap.

Definition at line 372 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT const char* UT_JSONValue::getS ( ) const

Get the string value (may return a NULL pointer)

Examples:
mocapstream/MocapStreamRokokoHDK.C.
SYS_NO_DISCARD_RESULT int64 UT_JSONValue::getSLength ( ) const

Return the string length (returns -1 if not a string)

SYS_NO_DISCARD_RESULT int UT_JSONValue::getSourceLine ( ) const
inline

Used by UT_JSONValue parsing from a stream.

Definition at line 379 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT int UT_JSONValue::getSourceOffset ( ) const
inline

Definition at line 381 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT const UT_StringHolder& UT_JSONValue::getString ( ) const
inline

Get the string value. If the value is not a string it returns the empty string. Either check the type prior to calling this function or use import<>() if you need to tell if there was an error.

Definition at line 184 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT const UT_StringHolder* UT_JSONValue::getStringHolder ( ) const

Return the string value.

SYS_NO_DISCARD_RESULT Type UT_JSONValue::getType ( ) const
inline

Get the type of data stored in the object.

Examples:
mocapstream/MocapStreamRokokoHDK.C, and packedshareddata/GU_PackedSharedData.C.

Definition at line 165 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT Type UT_JSONValue::getUniformArrayType ( ) const

Get the "uniform" type of an array. This will return:

  • JSON_NULL: The array is heterogeneous (or not an array)
  • JSON_BOOL: The array is only bool values
  • JSON_INT: The array is all bool or int values
  • JSON_REAL: The array is bool, int or real values
  • JSON_STRING: The array is all strings
SYS_NO_DISCARD_RESULT SYS_HashType UT_JSONValue::hash ( ) const

Compute a hash.

SYS_FORCE_INLINE bool UT_JSONValue::import ( bool &  result) const
inline

Extract a bool (returns false if type is invalid)

Definition at line 225 of file UT_JSONValue.h.

SYS_FORCE_INLINE bool UT_JSONValue::import ( int64 result) const
inline

Extract an integer (returns false if type is invalid)

Definition at line 244 of file UT_JSONValue.h.

SYS_FORCE_INLINE bool UT_JSONValue::import ( fpreal64 result) const
inline

Extract an float (returns false if type is invalid)

Definition at line 263 of file UT_JSONValue.h.

bool UT_JSONValue::import ( UT_WorkBuffer result) const

Extract a string or key (returns false if type is invalid)

bool UT_JSONValue::import ( UT_StringHolder result) const
bool UT_JSONValue::import ( int64 result,
int  size 
) const

Extract a tuple of integers from an JSON_Array. If there aren't enough elements in the array, this method fails

bool UT_JSONValue::import ( fpreal64 result,
int  size 
) const

Extract a tuple of floats from an JSON_Array. If there aren't enough elements in the array, this method fails

bool UT_JSONValue::import ( UT_Array< int64 > &  array) const

Extract a vector of integers from a JSON_Array.

bool UT_JSONValue::import ( UT_Array< fpreal64 > &  array) const

Extract a vector of reals from a JSON_Array.

bool UT_JSONValue::import ( UT_StringArray array) const

Extract a vector of strings from a JSON_Array.

template<typename T >
bool UT_JSONValue::import ( const UT_StringRef key,
T reuslt 
) const

Extract a value from the object. Only applies to json objects.

std::pair<traverser, bool> UT_JSONValue::insert ( const UT_StringHolder key,
const UT_JSONValue value 
)

Add a key/value pair to the contained map.

SYS_NO_DISCARD_RESULT bool UT_JSONValue::isArray ( ) const
inline

Definition at line 167 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT bool UT_JSONValue::isMap ( ) const
inline

Definition at line 166 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT bool UT_JSONValue::isNull ( ) const
inline

Definition at line 168 of file UT_JSONValue.h.

bool UT_JSONValue::isNumber ( ) const
inline

Returns whether the value can be interpreted as a number.

Definition at line 301 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT bool UT_JSONValue::isValueType ( ) const
inline

Definition at line 169 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT map_proxy UT_JSONValue::items ( )
inline

{@ Return a proxy map object to iterate over [key,value] on the contained map.

Definition at line 823 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT const map_proxy UT_JSONValue::items ( ) const
inline

Definition at line 828 of file UT_JSONValue.h.

bool UT_JSONValue::loadFromFile ( const char *  file_name,
bool  record_source_offsets = false 
)

Loads an entire JSON file into this value.

Test equality

Definition at line 940 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT const UT_JSONValue* UT_JSONValue::operator() ( int64  i) const
inline

{@ Helper access operators.

  • operator() allow for the value to not exist.
  • operator[] does not allow for the value to not exist.

Definition at line 390 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT UT_JSONValue* UT_JSONValue::operator() ( int64  i)
inline

Definition at line 394 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT const UT_JSONValue* UT_JSONValue::operator() ( const UT_StringRef k) const
inline

Definition at line 398 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT UT_JSONValue* UT_JSONValue::operator() ( const UT_StringRef k)
inline

Definition at line 402 of file UT_JSONValue.h.

UT_JSONValue& UT_JSONValue::operator= ( const UT_JSONValue v)
inline

Definition at line 125 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT bool UT_JSONValue::operator== ( const UT_JSONValue src) const

Test equality

SYS_NO_DISCARD_RESULT const UT_JSONValue& UT_JSONValue::operator[] ( int64  i) const
inline

Definition at line 406 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT UT_JSONValue& UT_JSONValue::operator[] ( int64  i)
inline

Definition at line 414 of file UT_JSONValue.h.

SYS_NO_DISCARD_RESULT UT_JSONValue& UT_JSONValue::operator[] ( const UT_StringRef k)
inline

Definition at line 422 of file UT_JSONValue.h.

bool UT_JSONValue::parseValue ( UT_JSONParser parser,
UT_IStream is = 0,
bool  record_source_offsets = false 
)

Read the next value from the parser and store it in this object

Parameters
parserThe parser
isIf specified, data will be read from this stream.
record_source_offsetsTrack offsets in stream for later seeking Otherwise, the stream associated with the parser will be used.
Examples:
mocapstream/MocapStreamRokokoHDK.C, and packedshareddata/GU_PackedSharedData.C.
bool UT_JSONValue::parseValue ( const UT_StringRef json_source)
bool UT_JSONValue::parseValue ( std::istream &  is)
void UT_JSONValue::remove ( int64  index)

{@ Remove a value by index.

void UT_JSONValue::removeNullValuesRecursive ( )

Removes NULL values from all arrays recursively. Note that maps are currently unsupported, and null values will not be removed from them.

bool UT_JSONValue::save ( UT_JSONWriter os) const

Save the object the output stream.

bool UT_JSONValue::saveToFile ( const char *  file_name,
bool  binary = false,
UT_CompressionType  compressionType = UT_COMPRESSION_TYPE_NONE 
)

Saves an entire JSON value to the specified file.

void UT_JSONValue::setArray ( UT_JSONValueArray array)

Set value to the array.

bool UT_JSONValue::setAsArray ( )

Set json value as a json array.

bool UT_JSONValue::setAsMap ( )

Set json value as a json map.

void UT_JSONValue::setBool ( bool  v)

Set value to an bool.

void UT_JSONValue::setInt ( int64  v)

Set value to an int.

void UT_JSONValue::setKey ( const char *  s,
int64  length = -1 
)
inline

Set string. If the length is not specified, the length of the string will be used.

Definition at line 323 of file UT_JSONValue.h.

void UT_JSONValue::setKey ( const UT_StringHolder s)
inline

Definition at line 325 of file UT_JSONValue.h.

void UT_JSONValue::setMap ( UT_JSONValueMap map)

Set value to the map.

void UT_JSONValue::setMapIndex ( int  i)
inline

Used internally by UT_JSONValueMap.

Definition at line 375 of file UT_JSONValue.h.

void UT_JSONValue::setNull ( )
inline

Set value to a null.

Definition at line 308 of file UT_JSONValue.h.

void UT_JSONValue::setReal ( fpreal64  v)

Set value to an int.

void UT_JSONValue::setSourceOffset ( int  line,
int  offset 
)
inline

Definition at line 383 of file UT_JSONValue.h.

void UT_JSONValue::setString ( const char *  s,
int64  length = -1 
)
inline

Set string. If the length is not specified, the length of the string will be used.

Definition at line 317 of file UT_JSONValue.h.

void UT_JSONValue::setString ( const UT_StringHolder s)
inline

Definition at line 319 of file UT_JSONValue.h.

bool UT_JSONValue::setUniformArray ( int  nvalues,
const int32 data 
)

Build a uniform array of values

bool UT_JSONValue::setUniformArray ( int  nvalues,
const int64 data 
)

Build a uniform array of values

bool UT_JSONValue::setUniformArray ( int  nvalues,
const fpreal16 data 
)

Build a uniform array of values

bool UT_JSONValue::setUniformArray ( int  nvalues,
const fpreal32 data 
)

Build a uniform array of values

bool UT_JSONValue::setUniformArray ( int  nvalues,
const fpreal64 data 
)

Build a uniform array of values

bool UT_JSONValue::setUniformArray ( int  nvalues,
const UT_StringHolder data 
)

Build a uniform array of values

UT_JSONValueArray* UT_JSONValue::startArray ( )

Start building an array from scratch.

See Also
appendArray
UT_JSONValueMap* UT_JSONValue::startMap ( )

Start building a map from scratch.

See Also
appendMap
UT_StringHolder UT_JSONValue::toString ( ) const

Member Data Documentation

UT_JSONValueArray* UT_JSONValue::myArray

Definition at line 957 of file UT_JSONValue.h.

bool UT_JSONValue::myBool

Definition at line 950 of file UT_JSONValue.h.

int64 UT_JSONValue::myInt

Definition at line 951 of file UT_JSONValue.h.

UT_JSONValueMap* UT_JSONValue::myMap

Definition at line 958 of file UT_JSONValue.h.

fpreal64 UT_JSONValue::myReal

Definition at line 952 of file UT_JSONValue.h.


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