11 #ifndef __UT_JSONWriter__
12 #define __UT_JSONWriter__
112 bool setBinary(
bool bin);
129 bool jsonComment(
const char *
format, ...)
136 bool jsonBool(
bool value);
138 bool jsonInt(
int32 value);
140 bool jsonInt(
int64 value);
142 bool jsonInt64(
int64 value);
145 bool jsonRealPreserveType(
fpreal16 value);
148 bool jsonRealPreserveType(
fpreal32 value);
151 bool jsonRealPreserveType(
fpreal64 value);
158 bool jsonString(const
char *value,
int64 length=0);
164 bool jsonStringToken(const
char *value,
int64 length)
171 return jsonStringToken(result);
190 {
return jsonStringToken(v.c_str(), v.length()); }
193 {
return jsonUniformArray(v); }
195 {
return jsonUniformArray(v); }
197 {
return jsonUniformArray(v); }
199 {
return jsonUniformArray(v); }
201 {
return jsonUniformArray(v); }
203 {
return jsonStringTokenArray(v); }
205 template <
typename T>
208 return jsonSetAsArray(v);
231 return jsonKeyToken(result);
239 bool ok = jsonKeyToken(key);
240 return ok && jsonValue(value);
246 bool ok = jsonKeyToken(key);
247 return ok && jsonValue(value);
255 bool jsonBeginArray();
260 bool jsonEndArray(
bool newline=
true);
282 bool uniformWrite(
bool value);
284 bool uniformWrite(
int8 value);
286 bool uniformWrite(
int16 value);
288 bool uniformWrite(
int32 value);
290 bool uniformWrite(
int64 value);
298 bool uniformWrite(
uint8 value);
300 bool uniformWrite(
uint16 value);
302 bool uniformWrite(
const char *value,
int64 length=0);
327 bool endUniformArray(
int64 *nwritten=0);
355 template <
typename T>
358 if constexpr (SYSisSame<T, bool>())
360 else if constexpr (SYSisSame<T, int8>())
362 else if constexpr (SYSisSame<T, int16>())
364 else if constexpr (SYSisSame<T, int32>())
366 else if constexpr (SYSisSame<T, int64>())
368 else if constexpr (SYSisSame<T, fpreal16>())
370 else if constexpr (SYSisSame<T, fpreal32>())
372 else if constexpr (SYSisSame<T, fpreal64>())
374 else if constexpr (SYSisSame<T, uint8>())
376 else if constexpr (SYSisSame<T, uint16>())
382 static_assert(!SYSisSame<T, T>(),
"Unsupported type for UT_JID");
408 bool verbose_ascii =
false);
413 {
return jsonUniformArray(a.
size(), a.
data()); }
415 {
return jsonUniformArray(a.
size(), a.
data()); }
417 {
return jsonUniformArray(a.
size(), a.
data()); }
419 {
return jsonUniformArray(a.
size(), a.
data()); }
421 {
return jsonUniformArray(a.
size(), a.
data()); }
425 template <
typename T>
428 if (!jsonBeginArray())
434 return jsonEndArray();
475 int_type overflow(int_type
c)
override;
478 std::streamsize xsputn(
const char*
s, std::streamsize num)
override;
484 bool writeTile(
const char *data,
exint bytes);
505 virtual bool subclassWriteData(
const void*
data,
int64 bytes) = 0;
511 int precision16()
const {
return (myPrecision+1)/2; }
512 int precision32()
const {
return myPrecision; }
513 int precision64()
const {
return myPrecision*2; }
527 bool quotedString(
const char *str,
int64 bytes=0);
529 bool writeAB(
bool i);
531 bool writeAI(
int64 i);
539 bool finishArray(
UT_JID id,
bool newline=
true);
543 void pushState(
UT_JID id);
549 void bumpIndent(
int dir);
551 bool newLine(
bool force=
false);
556 template <
typename T>
bool
558 template <
typename T>
bool
560 template <
typename T>
bool
562 template <
typename T>
bool
578 int64 myCurrentFilePosition;
596 bool myPrettyCompact;
632 : myWriter(
UT_JSONWriter::allocWriter(os, binary, compression_type))
639 : myWriter(
UT_JSONWriter::allocWriter(filename, binary, compression_type))
UT_JSONWriter & operator*() const
The following byte represents an 8 bit integer.
bool jsonValue(bool value)
UT_AutoJSONWriter(std::ostream &os, bool binary, UT_CompressionType compression_type=UT_COMPRESSION_TYPE_NONE)
Write to the given ostream (binary and optionally gzipped)
No data follows the NULL token.
GT_API const UT_StringHolder filename
int64 getNumBytesWritten() const
Get the number of bytes written to output so far.
UT_AutoJSONWriter(UT_WorkBuffer &b)
Write directly to the UT_WorkBuffer.
The following 4 bytes represent an 32 bit real (float)
bool jsonKeyToken(const char *value, int64 length)
UT_JID
The UT_JID enums are used in byte-stream encoding of binary JSON.
bool getUseTokens() const
bool getBinary() const
Return whether writing binary or ASCII JSON.
void writeData(std::ostream &os, const T *data, Index count, uint32_t compression)
bool jsonValue(int32 value)
GLsizei const GLfloat * value
0x23 and 0x24 are reserved for future use (32/64 bit unsigned)
const GLuint GLenum const void * binary
GLboolean GLboolean GLboolean GLboolean a
GLuint GLsizei GLsizei * length
The following byte represents an unsigned 8 bit integer.
Class which writes ASCII or binary JSON streams.
**But if you need a result
bool jsonValue(fpreal16 value)
UT_JSONWriter & writer() const
bool jsonValue(const UT_String &v)
bool jsonUniformArray(const UT_Int32Array &a)
const char * c_str() const
bool jsonValue(const char *v)
unsigned length() const
Return length of string.
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
void setPrettyPrint(bool prettyprint)
The following 8 bytes represent an 64 bit real (float)
The following 8 bytes represent an 64 bit integer.
bool jsonValue(const UT_Fpreal32Array &v)
bool jsonValue(const UT_StringRef &v)
GLint GLint GLsizei GLint GLenum GLenum type
The following 2 bytes represent an 16 bit integer.
static UT_JID jid()
Returns the JID that matches the given type.
SYS_FORCE_INLINE bool jsonKeyTokenValue(const UT_StringRef &key, const T &value)
void writeString(std::ostream &os, const Name &name)
UT_AutoJSONWriter(UT_JSONValue &value)
Write directly to the UT_JSONValue.
#define SYS_PRINTF_CHECK_ATTRIBUTE(string_index, first_to_check)
GLint GLint GLsizei GLint GLenum format
bool getPrettyCompact() const
bool jsonValue(int16 value)
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
bool jsonValue(unsigned value)
The following 4 bytes represent an 32 bit integer.
GLboolean GLboolean GLboolean b
void setPrettyCompact(bool compact)
void fastReferenceWithStrlen(const char *src, exint length)
old name of method:
bool jsonUniformArray(const UT_Int16Array &a)
bool jsonValue(const UT_Int16Array &v)
bool jsonUniformArray(const UT_Int64Array &a)
GLenum GLint GLint * precision
void setComments(bool comment)
void setIndentStep(int indentstep)
bool jsonUniformArray(const UT_Fpreal32Array &a)
A map of string to various well defined value types.
SIM_API const UT_StringHolder force
bool jsonValue(const std::string &v)
LeafData & operator=(const LeafData &)=delete
bool jsonSetAsArray(const UT_Set< T > &a)
Convenience method to save a set as an array of strings.
SYS_FORCE_INLINE bool jsonKeyValue(const UT_StringRef &key, const T &value)
bool jsonValue(int8 value)
bool jsonValue(const UT_Int32Array &v)
Class to store JSON objects as C++ objects.
UT_JSONWriter * operator->() const
void reference(const char *src)
bool jsonValue(int64 value)
int getNesting() const
Get the nesting level (i.e. how deeply nested in maps/arrays)
GLubyte GLubyte GLubyte GLubyte w
int getIndentStep() const
bool jsonUniformArray(const UT_Fpreal64Array &a)
bool jsonValue(const UT_Fpreal64Array &v)
void setTextWidth(int width)
UT_AutoJSONWriter(const char *filename, bool binary, UT_CompressionType compression_type=UT_COMPRESSION_TYPE_NONE)
Write to the given filename (binary and optionally gzipped)
bool jsonValue(fpreal64 value)
The following 2 bytes represents an unsigned 16 bit integer.
void close()
Close the stream (causing all data to be flushed)
bool jsonValue(fpreal32 value)
bool getPrettyPrint() const
void setUseTokens(bool usetokens)
bool jsonValue(const UT_Set< T > &v)
bool jsonValue(const UT_StringArray &v)
void setPrecision(int precision)
Direct access to options.
bool jsonValue(const UT_Int64Array &v)