11 #ifndef __UT_JSONParser__
12 #define __UT_JSONParser__
38 class ut_SimpleJSONObjectHandle;
102 bool seekg(
exint pos,
int dir,
bool reset =
true);
140 bool parseBool(
bool &
v);
145 bool parseInteger(
int64 &
v);
153 bool parseNumber(
int8 &
v);
154 bool parseNumber(
int16 &
v);
155 bool parseNumber(
int32 &
v);
157 bool parseNumber(
uint8 &
v);
181 template <
typename T>
185 int64 array_size = getUniformArraySize();
189 switch (getUniformArrayType())
192 i = UniformArrayHelper<int8, T>::load(it, data, load_size);
195 i = UniformArrayHelper<int16, T>::load(it, data, load_size);
198 i = UniformArrayHelper<int32, T>::load(it, data, load_size);
201 i = UniformArrayHelper<int64, T>::load(it, data, load_size);
204 i = UniformArrayHelper<fpreal16, T>::load(it, data, load_size);
207 i = UniformArrayHelper<fpreal32, T>::load(it, data, load_size);
210 i = UniformArrayHelper<fpreal64, T>::load(it, data, load_size);
223 for ( ; !it.
atEnd(); ++it, ++i)
226 if (!parseValue(val))
238 template <
typename T>
241 int64 unread_size = getUniformArrayUnreadSize();
245 switch (getUniformArrayType())
248 i = UniformArrayHelper<int8, T>::load(it, data, load_size);
251 i = UniformArrayHelper<int16, T>::load(it, data, load_size);
254 i = UniformArrayHelper<int32, T>::load(it, data, load_size);
257 i = UniformArrayHelper<int64, T>::load(it, data, load_size);
260 i = UniformArrayHelper<fpreal16, T>::load(it, data, load_size);
263 i = UniformArrayHelper<fpreal32, T>::load(it, data, load_size);
266 i = UniformArrayHelper<fpreal64, T>::load(it, data, load_size);
269 for (i = 0; !it.
atEnd() && i < len; ++it, ++i)
272 if (!parseValue(val))
290 template <
typename OP_TYPE,
typename T>
bool
291 loadPODUniformArray(OP_TYPE &op, iterator &it,
int64 size)
294 if (!it.readUniformArray(
b.array(),
size))
296 bool success = op.setArray((
const T*)
b, size);
300 template <
typename INTERNAL_T,
typename T>
301 class UniformArrayHelper
309 if (!it.readUniformArray(
b.array(),
size))
313 std::numeric_limits<INTERNAL_T>::digits >
314 std::numeric_limits<T>::digits)
324 data[i] =
static_cast<T>(
v);
331 data[i] = static_cast<T>(
b[i]);
337 template <
typename T>
338 class UniformArrayHelper<
T,
T>
343 static int64 load(iterator &it,
T *data,
int64 size)
345 if (!it.readUniformArray(data, size))
352 UT_JID getUniformArrayType()
const;
354 int64 getUniformArraySize()
const;
356 int64 getUniformArrayUnreadSize()
const;
373 template <
typename OP_TYPE,
typename POD_TYPE>
377 int64 n = getUniformArraySize();
378 switch (getUniformArrayType())
381 return loadPODUniformArray<OP_TYPE, int8>
384 return loadPODUniformArray<OP_TYPE, int16>
387 return loadPODUniformArray<OP_TYPE, int32>
390 return loadPODUniformArray<OP_TYPE, int64>
393 return loadPODUniformArray<OP_TYPE, fpreal16>
396 return loadPODUniformArray<OP_TYPE, fpreal32>
399 return loadPODUniformArray<OP_TYPE, fpreal64>
407 if (!parseNumber(val))
418 bool parseBeginMap(
bool &
error);
422 bool parseBeginArray(
bool &
error);
446 bool skipNextObject();
459 int64 getStreamLineCount()
const;
460 int64 getStreamLineStartPosition()
const;
461 int64 getStreamPosition()
const;
521 void addFatal(
const char *fmt, ...)
523 void addWarning(const
char *fmt, ...)
559 myParser = src.myParser;
561 myValid = src.myValid;
562 myError = src.myError;
572 bool atEnd()
const {
return !myValid || myError; }
575 if (myParser && !myError)
578 hit = (myMap) ? myParser->parseEndMap(myError)
579 : myParser->parseEndArray(myError);
591 template <
typename T>
594 if (myParser && myValid)
596 return myMap ? myParser->parseKey(key)
597 : myParser->parseString(key);
601 myParser->addWarning(
602 "Missing key while parsing map");
610 template <
typename T>
628 return myParser ? myParser->getUniformArrayType()
634 return myParser ? myParser->getUniformArraySize()
642 myParser->getUniformArrayUnreadSize() : -1;
648 template <
typename T>
652 return (myError =
false);
653 if (!myParser->readUniformArray(buffer, size))
654 return (myError =
false);
673 if ((myValid = myParser->parseBeginMap(myError)))
677 myValid = !myParser->parseEndMap(myError);
682 if ((myValid = myParser->parseBeginArray(myError)))
685 myValid = !myParser->parseEndArray(myError);
780 bool parseStream(
exint nobjects);
783 bool parseToken(
UT_JID &token);
786 bool parseSimpleObject(ut_SimpleJSONObjectHandle &
h);
793 bool readLength(
int64 &l);
797 bool readToken(ut_JValue &
value);
799 bool pushState(ut_JParseState state);
801 void setState(ut_JParseState state);
805 ut_JParseState getState()
const {
return myState; }
809 bool readNumber(ut_JValue &
value);
813 bool undefineToken();
815 void undefineToken(
int64 id);
826 ut_JValue *myPeekCache;
830 ut_JParseState myState;
832 int64 myLineStartPosition;
902 bool myAllocatedIStream;
The following byte represents an 8 bit integer.
*pool push(my_func, arg1,...)
GLenum GLuint GLenum GLsizei const GLchar * buf
No data follows the NULL token.
GT_API const UT_StringHolder filename
GLenum GLuint GLsizei bufsize
The following 4 bytes represent an 32 bit real (float)
UT_JID
The UT_JID enums are used in byte-stream encoding of binary JSON.
void setBinary(bool isBinary)
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Marks the end of an array object.
getFileOption("OpenEXR:storage") storage
0x23 and 0x24 are reserved for future use (32/64 bit unsigned)
int64 parseArrayValues(iterator &it, T *data, int64 len)
bool parseValue(fpreal64 &v)
UT_JSONHandle processes events from a UT_JSONParser parser.
int64 getUniformArraySize() const
Return the number of elements in the uniform array (0 if empty)
UT_JID getUniformArrayType() const
Return the uniform array type (UT_JID_NULL if not uniform array)
iterator & operator++()
++iterator
bool parseValue(fpreal16 &v)
JSON reader class which handles parsing of JSON or bJSON files.
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
**But if you need a result
unsigned long long uint64
const UT_StringArray & getErrors() const
Get resulting warnings/errors.
bool parseNumber(int64 &v)
The following 8 bytes represent an 64 bit real (float)
bool parseInt(int64 &v)
Alternate short-form.
The following 8 bytes represent an 64 bit integer.
bool readValue(int8 *v, exint n)
Convenience method to a int8 values.
const iterator & operator=(const iterator &src)
The following 2 bytes represent an 16 bit integer.
int64 getUniformArrayUnreadSize() const
bool parseValue(fpreal32 &v)
UT_JSONParser & operator*()
bool readValue(uint8 *v, exint n)
Convenience method to read uint8 values.
#define SYS_PRINTF_CHECK_ATTRIBUTE(string_index, first_to_check)
Traverse an array object in the parser.
bool parseValue(int64 &v)
bool getErrorState() const
The following 4 bytes represent an 32 bit integer.
GLboolean GLboolean GLboolean b
iterator(const iterator &src)
bool getBinary() const
Returns whether we're reading a binary or ASCII file.
int64 parseUniformArray(T *data, int64 len)
GLfloat GLfloat GLfloat GLfloat h
Marks the end of a map object.
bool parseValue(UT_WorkBuffer &v)
bool parseEndArray(bool &error)
LeafData & operator=(const LeafData &)=delete
SYS_NO_DISCARD_RESULT UT_StringRef toLower() const
bool loadPODArray(OP_TYPE &op)
UT_JSONParser * operator->()
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool readUniformArray(T *buffer, int64 size)
iterator & operator++(int)
Name readString(std::istream &is)
Class to store JSON objects as C++ objects.
bool parseValue(uint16 &v)
bool parseValue(int16 &v)
bool parseValue(UT_StringHolder &v)
GLubyte GLubyte GLubyte GLubyte w
bool parseEndMap(bool &error)
bool parseValue(int32 &v)
bool parseValue(uint8 &v)
void lower()
Convert string to lower case.
bool getLowerKey(T &key)
Get a lower case map key (for case insensitive maps)
bool parseNumber(fpreal64 &v)