11 #ifndef __UT_JSONWriter__
12 #define __UT_JSONWriter__
105 bool setBinary(
bool bin);
122 bool jsonComment(
const char *
format, ...)
129 bool jsonBool(
bool value);
131 bool jsonInt(
int32 value);
133 bool jsonInt(
int64 value);
135 bool jsonInt64(
int64 value);
138 bool jsonRealPreserveType(
fpreal16 value);
141 bool jsonRealPreserveType(
fpreal32 value);
144 bool jsonRealPreserveType(
fpreal64 value);
164 return jsonStringToken(result);
183 {
return jsonStringToken(v.c_str(), v.length()); }
186 {
return jsonUniformArray(v); }
188 {
return jsonUniformArray(v); }
190 {
return jsonUniformArray(v); }
192 {
return jsonUniformArray(v); }
194 {
return jsonUniformArray(v); }
196 {
return jsonStringTokenArray(v); }
198 template <
typename T>
201 return jsonSetAsArray(v);
224 return jsonKeyToken(result);
232 bool ok = jsonKeyToken(key);
233 return ok && jsonValue(value);
239 bool ok = jsonKeyToken(key);
240 return ok && jsonValue(value);
248 bool jsonBeginArray();
253 bool jsonEndArray(
bool newline=
true);
275 bool uniformWrite(
bool value);
277 bool uniformWrite(
int8 value);
279 bool uniformWrite(
int16 value);
281 bool uniformWrite(
int32 value);
283 bool uniformWrite(
int64 value);
291 bool uniformWrite(
uint8 value);
293 bool uniformWrite(
uint16 value);
295 bool uniformWrite(
const char *value,
int64 length=0);
320 bool endUniformArray(
int64 *nwritten=0);
359 bool verbose_ascii =
false);
364 {
return jsonUniformArray(a.
size(), a.
data()); }
366 {
return jsonUniformArray(a.
size(), a.
data()); }
368 {
return jsonUniformArray(a.
size(), a.
data()); }
370 {
return jsonUniformArray(a.
size(), a.
data()); }
372 {
return jsonUniformArray(a.
size(), a.
data()); }
376 template <
typename T>
379 if (!jsonBeginArray())
385 return jsonEndArray();
426 std::streamsize xsputn(
const char*
s, std::streamsize
num)
override;
432 bool writeTile(
const char *data,
exint bytes);
451 virtual bool subclassWriteData(
const void*
data,
int64 bytes) = 0;
457 int precision16()
const {
return (myPrecision+1)/2; }
458 int precision32()
const {
return myPrecision; }
459 int precision64()
const {
return myPrecision*2; }
473 bool quotedString(
const char *str,
int64 bytes=0);
475 bool writeAB(
bool i);
477 bool writeAI(
int64 i);
485 bool finishArray(
UT_JID id,
bool newline=
true);
489 void pushState(
UT_JID id);
495 void bumpIndent(
int dir);
497 bool newLine(
bool force=
false);
502 template <
typename T>
bool
504 template <
typename T>
bool
506 template <
typename T>
bool
508 template <
typename T>
bool
522 int64 myCurrentFilePosition;
540 bool myPrettyCompact;
576 : myWriter(
UT_JSONWriter::allocWriter(os, binary, compressionType))
583 : myWriter(
UT_JSONWriter::allocWriter(filename, binary, compressionType))
UT_JSONWriter & operator*() const
The following byte represents an 8 bit integer.
bool jsonValue(bool value)
UT_AutoJSONWriter(const char *filename, bool binary, UT_CompressionType compressionType=UT_COMPRESSION_TYPE_NONE)
Write to the given filename (binary and optionally gzipped)
static UT_JID jidFromValue(const fpreal32 *)
GLboolean GLboolean GLboolean b
static UT_JID jidFromValue(const int64 *)
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
static UT_JID jidFromValue(const bool *)
Returns the JID that matches the given type.
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)
0x23 and 0x24 are reserved for future use (32/64 bit unsigned)
const GLuint GLenum const void * binary
The following byte represents an unsigned 8 bit integer.
Class which writes ASCII or binary JSON streams.
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.
GLubyte GLubyte GLubyte GLubyte w
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)
The following 2 bytes represent an 16 bit integer.
static UT_JID jidFromValue(const fpreal64 *)
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.
static UT_JID jidFromValue(const fpreal16 *)
#define SYS_PRINTF_CHECK_ATTRIBUTE(string_index, first_to_check)
GLboolean GLboolean GLboolean GLboolean a
GLsizei const GLchar *const * string
bool getPrettyCompact() const
bool jsonValue(int16 value)
bool jsonValue(unsigned value)
The following 4 bytes represent an 32 bit integer.
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)
GLuint GLsizei GLsizei * length
GLint GLint GLsizei GLint GLenum format
void setIndentStep(int indentstep)
bool jsonUniformArray(const UT_Fpreal32Array &a)
A map of string to various well defined value types.
static UT_JID jidFromValue(const int8 *)
static UT_JID jidFromValue(const uint16 *)
bool jsonValue(const std::string &v)
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)
static UT_JID jidFromValue(const uint8 *)
bool jsonValue(int8 value)
bool jsonValue(const UT_Int32Array &v)
UT_AutoJSONWriter(std::ostream &os, bool binary, UT_CompressionType compressionType=UT_COMPRESSION_TYPE_NONE)
Write to the given ostream (binary and optionally gzipped)
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)
static UT_JID jidFromValue(const int32 *)
int getIndentStep() const
bool jsonUniformArray(const UT_Fpreal64Array &a)
bool jsonValue(const UT_Fpreal64Array &v)
void setTextWidth(int width)
bool jsonValue(fpreal64 value)
void write(T &out, bool v)
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)
static UT_JID jidFromValue(const int16 *)
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)