11 #ifndef __UT_JSONValue__
12 #define __UT_JSONValue__
43 explicit operator bool()
const {
return myValue !=
nullptr; }
162 bool record_source_offsets =
false);
165 bool parseValue(std::istream& is);
169 bool loadFromFile(
const char* file_name,
170 bool record_source_offsets =
false);
173 bool saveToFile(
const char* file_name,
192 return !isMap() && !isArray();
254 result = myData.myInt != 0;
257 result = myData.myReal != 0;
270 result = myData.myBool ? 1 : 0;
289 result = myData.myBool ? 1. : 0.;
318 template <
typename T>
324 return myType == JSON_REAL || myType == JSON_INT ||
331 void setBool(
bool v);
339 { setStringType(s,
length, JSON_STRING); }
341 { setStringType(s, JSON_STRING); }
345 { setStringType(s,
length, JSON_KEY); }
347 { setStringType(s, JSON_KEY); }
384 bool setUniformArray(
int nvalues,
const uint8 *
data);
385 bool setUniformArray(
int nvalues,
const int8 *
data);
386 bool setUniformArray(
int nvalues,
const int16 *
data);
387 bool setUniformArray(
int nvalues,
const int32 *
data);
388 bool setUniformArray(
int nvalues,
const int64 *
data);
389 bool setUniformArray(
int nvalues,
const fpreal16 *
data);
390 bool setUniformArray(
int nvalues,
const fpreal32 *
data);
391 bool setUniformArray(
int nvalues,
const fpreal64 *
data);
397 {
return myMapIndex; }
404 {
return mySourceLine; }
406 {
return mySourceOffset; }
408 { mySourceLine = line; mySourceOffset =
offset; }
481 myCurrArrayPos = myNumArrayEntries = 0;
491 myValue = src.myValue;
492 myIsValid = src.myIsValid;
493 myCurrArrayPos = src.myCurrArrayPos;
494 myNumArrayEntries = src.myNumArrayEntries;
495 myValueType = src.myValueType;
496 myMapKeys = src.myMapKeys;
506 return myCurrArrayPos == rhs.myCurrArrayPos
507 && myIsValid == rhs.myIsValid;
511 return !(*
this == rhs);
529 bool atEnd()
const {
return !myIsValid; }
532 if(myValue && myIsValid)
534 if(myValueType == JSON_MAP)
537 if(myCurrArrayPos >= myMapKeys.entries())
540 else if(myValueType == JSON_ARRAY)
543 if(myCurrArrayPos >= myNumArrayEntries)
558 if (myValue && myIsValid)
559 return iteratorValue();
564 if (myValue && myIsValid)
570 if (myValue && myIsValid
571 && (myValueType == JSON_ARRAY || myValueType == JSON_MAP))
573 return myCurrArrayPos;
591 if (!getLowerCaseKey(tmp))
599 if(myValue && myIsValid)
601 if(myValueType == JSON_MAP)
603 key = myMapKeys(myCurrArrayPos);
634 myNumArrayEntries = 0;
638 : myValue(value_in), myIsValid(false), myCurrArrayPos(start_idx)
640 myNumArrayEntries = 0;
650 int64 myCurrArrayPos;
651 int64 myNumArrayEntries;
663 using pointer = std::pair<exint, UT_JSONValue*>;
673 return std::make_pair(
692 using reference = std::tuple<exint, UT_StringHolder, UT_JSONValue&>;
693 using pointer = std::tuple<exint, UT_StringHolder, UT_JSONValue*>;
705 return std::make_tuple(
712 return std::make_tuple(
718 if (myValue && myIsValid)
720 if (myValueType == JSON_MAP)
722 return myMapKeys(myCurrArrayPos);
758 if (myValue && myIsValid)
760 if (myValueType == JSON_MAP)
762 return myMapKeys(myCurrArrayPos);
772 template <
typename IteratorT>
778 return IteratorT(myValue);
782 return IteratorT(myValue, myValue->count());
787 return IteratorT(me->myValue);
789 const IteratorT
end()
const
792 return IteratorT(me->myValue, me->myValue->
count());
876 std::pair<traverser, bool>
insert(
881 template <
typename... ARGS>
892 template <
typename... ARGS>
937 const char *key_value);
940 const char *key_value);
953 {
return !(*
this ==
src); }
959 void setStringType(
const char *
s,
int64 l,
Type t);
983 template <std::
size_t N, std::enable_if_t<N == 0,
int> = 0>
991 template <std::
size_t N, std::enable_if_t<N == 1,
int> = 0>
998 template <std::
size_t N, std::enable_if_t<N==0,
int> = 0>
1002 return it.getArrayIndex();
1005 template <std::
size_t N, std::enable_if_t<N == 1,
int> = 0>
1012 template <std::
size_t N, std::enable_if_t<N==0,
int> = 0>
1016 return it.getArrayIndex();
1019 template <std::
size_t N, std::enable_if_t<N == 1,
int> = 0>
1026 template <std::
size_t N, std::enable_if_t<N == 2,
int> = 0>
1037 :
public std::integral_constant<std::size_t, 2>
1040 template <std::
size_t N>
1043 using type = decltype(get<N>(std::declval<UT_JSONValue::map_traverser>()));
1048 :
public std::integral_constant<std::size_t, 2>
1051 template <std::
size_t N>
1054 using type = decltype(get<N>(std::declval<UT_JSONValue::indexed_traverser>()));
1059 :
public std::integral_constant<std::size_t, 3>
1062 template <std::
size_t N>
1065 using type = decltype(get<N>(
1066 std::declval<UT_JSONValue::indexed_map_traverser>()));
Used to iterate over a map from a json value.
const traverser const_iterator
traverser find(const UT_StringRef &key)
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
SYS_NO_DISCARD_RESULT const_iterator begin() const
#define SYS_DEPRECATED(__V__)
const UT_JSONValue & value() const
SYS_NO_DISCARD_RESULT UT_JSONValue * operator()(const UT_StringRef &k)
SYS_NO_DISCARD_RESULT traverser begin()
bool isNumber() const
Returns whether the value can be interpreted as a number.
SYS_FORCE_INLINE void clear()
GLsizei const GLfloat * value
void setNull()
Set value to a null.
void setKey(const UT_StringHolder &s)
const GLuint GLenum const void * binary
UT_JSONValueArray stores a list of UT_JSONValue objects.
SYS_NO_DISCARD_RESULT const UT_JSONValue * operator()(const UT_StringRef &k) const
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
SYS_NO_DISCARD_RESULT UT_JSONValue & operator[](const UT_StringRef &k)
std::size_t SYS_HashType
Define the type for hash values.
UT_JSONValueArray * myArray
void erase(const UT_StringRef &k)
SYS_NO_DISCARD_RESULT int getSourceOffset() const
GLuint GLsizei GLsizei * length
map_traverser(UT_JSONValue *v)
const UT_StringHolder & key() const
JSON reader class which handles parsing of JSON or bJSON files.
SYS_NO_DISCARD_RESULT bool isMap() const
UT_JSONValue & operator=(const UT_StringHolder &s)
Class which writes ASCII or binary JSON streams.
void removeNullValuesRecursive()
**But if you need a result
bool getLowerCaseKey(UT_StringHolder &key)
Get a lower case map key (for case insensitive maps)
const UT_JSONValue * operator->() const
decltype(get< N >(std::declval< UT_JSONValue::map_traverser >())) type
SYS_NO_DISCARD_RESULT traverser beginTraversal()
UT_API size_t UTformatBuffer(char *buffer, size_t buffer_size, const UT_JSONValue &v)
const UT_JSONValue * getValue() const
const UT_JSONValue * operator->() const
indexed_traverser(UT_JSONValue *v, exint end_len)
__hostdev__ float getValue(uint32_t i) const
SYS_NO_DISCARD_RESULT UT_JSONValue * operator()(int64 i)
bool contains(const UT_StringRef &key) const
SYS_NO_DISCARD_RESULT int getSourceLine() const
Used by UT_JSONValue parsing from a stream.
SYS_NO_DISCARD_RESULT bool isValueType() const
void setSourceOffset(int line, int offset)
SYS_NO_DISCARD_RESULT const_iterator end() const
GLint GLint GLsizei GLint GLenum GLenum type
decltype(get< N >(std::declval< UT_JSONValue::indexed_traverser >())) type
void setKey(const char *s, int64 length=-1)
json_proxy< indexed_traverser > indexed_proxy
traverser emplace_back(ARGS &&...args)
Insert a json value to the back of the contained array.
const UT_JSONValue & value() const
const traverser & operator=(const traverser &src)
decltype(get< N >(std::declval< UT_JSONValue::indexed_map_traverser >())) type
std::pair< traverser, bool > insert(const UT_StringHolder &key, const UT_JSONValue &value)
Add a key/value pair to the contained map.
SYS_NO_DISCARD_RESULT indexed_map_proxy enumerateMap()
SYS_NO_DISCARD_RESULT UT_JSONFindResult findParentValueRecursive(const UT_StringHolder &map_key, const char *key_value)
static const UT_StringHolder theEmptyString
json_proxy< indexed_map_traverser > indexed_map_proxy
UT_JSONValue & operator=(fpreal64 v)
Traverse the children of the current value.
SYS_NO_DISCARD_RESULT const indexed_proxy enumerate() const
const UT_JSONValue & operator*() const
int64 getArrayIndex() const
indexed_map_traverser(UT_JSONValue *v, exint end_len)
traverser(const traverser &src)
SYS_NO_DISCARD_RESULT indexed_proxy enumerate()
friend class UT_JSONValue
#define SYS_NO_DISCARD_RESULT
SYS_NO_DISCARD_RESULT bool isArray() const
UT_JSONValue & operator=(const UT_JSONValue &v)
std::forward_iterator_tag iterator_category
SYS_NO_DISCARD_RESULT SYS_HashType hash() const
Compute a hash.
UT_JSONValue * operator->()
indexed_traverser(UT_JSONValue *v)
UT_JSONValue & operator=(int64 v)
SYS_NO_DISCARD_RESULT const UT_JSONValue & operator[](int64 i) const
SYS_NO_DISCARD_RESULT const UT_JSONValue * operator()(int64 i) const
bool getKey(UT_StringHolder &key) const
traverser & operator++()
++iterator
void setString(const UT_StringHolder &s)
SYS_NO_DISCARD_RESULT UT_JSONValue & operator[](int64 i)
const UT_JSONValue & value() const
const UT_StringHolder & key() const
SYS_NO_DISCARD_RESULT const map_proxy items() const
const UT_JSONValue & operator*() const
bool operator==(const traverser &rhs) const
No post increment as it is harmful.
void setString(const char *s, int64 length=-1)
UT_JSONFindResult(UT_JSONValue *v=nullptr, int64 idx=-1)
SYS_NO_DISCARD_RESULT int getMapIndex() const
Used internally by UT_JSONValueMap.
SYS_NO_DISCARD_RESULT exint count() const
Number of elements contained inside the json value.
SYS_NO_DISCARD_RESULT UT_StringRef toLower() const
SYS_NO_DISCARD_RESULT map_proxy items()
GA_API const UT_StringHolder N
SYS_NO_DISCARD_RESULT const_iterator cend() const
SYS_NO_DISCARD_RESULT Type getType() const
Get the type of data stored in the object.
json_proxy< map_traverser > map_proxy
Class to store JSON objects as C++ objects.
**If you just want to fire and args
UT_JSONValue * getValue()
SYS_NO_DISCARD_RESULT bool isNull() const
SYS_NO_DISCARD_RESULT bool operator!=(const UT_JSONValue &src) const
const IteratorT end() const
UT_JSONValue * operator->()
bool getKey(UT_String &key)
Deprecated in favour of UT_StringHolder method.
map_traverser(UT_JSONValue *v, exint end_len)
UT_JSONValue & operator=(bool v)
SYS_NO_DISCARD_RESULT UT_JSONFindResult findValueRecursive(const UT_StringHolder &map_key, const char *key_value)
UT_JSONValue & operator*()
traverser append(const UT_JSONValue &v)
Insert a json value to the back of the contained array.
SYS_NO_DISCARD_RESULT const UT_StringHolder & getString() const
indexed_map_traverser(UT_JSONValue *v)
const IteratorT begin() const
SYS_NO_DISCARD_RESULT const indexed_map_proxy enumerateMap() const
std::pair< traverser, bool > emplace(const UT_StringHolder &key, ARGS &&...args)
Add an entry to the contained map.
void setMapIndex(int i)
Used internally by UT_JSONValueMap.
bool operator!=(const traverser &rhs) const
SYS_NO_DISCARD_RESULT traverser end()
SYS_NO_DISCARD_RESULT const_iterator cbegin() const