11 #ifndef __UT_JSONWriter__
12 #define __UT_JSONWriter__
104 bool setBinary(
bool bin);
121 bool jsonComment(
const char *
format, ...)
128 bool jsonBool(
bool value);
130 bool jsonInt(
int32 value);
132 bool jsonInt(
int64 value);
134 bool jsonInt64(
int64 value);
137 bool jsonRealPreserveType(
fpreal16 value);
140 bool jsonRealPreserveType(
fpreal32 value);
143 bool jsonRealPreserveType(
fpreal64 value);
163 return jsonStringToken(result);
182 {
return jsonStringToken(v.c_str(), v.length()); }
185 {
return jsonUniformArray(v); }
187 {
return jsonUniformArray(v); }
189 {
return jsonUniformArray(v); }
191 {
return jsonUniformArray(v); }
193 {
return jsonUniformArray(v); }
195 {
return jsonStringTokenArray(v); }
218 return jsonKeyToken(result);
226 bool ok = jsonKeyToken(key);
227 return ok && jsonValue(value);
233 bool ok = jsonKeyToken(key);
234 return ok && jsonValue(value);
242 bool jsonBeginArray();
247 bool jsonEndArray(
bool newline=
true);
269 bool uniformWrite(
bool value);
271 bool uniformWrite(
int8 value);
273 bool uniformWrite(
int16 value);
275 bool uniformWrite(
int32 value);
277 bool uniformWrite(
int64 value);
285 bool uniformWrite(
uint8 value);
287 bool uniformWrite(
uint16 value);
289 bool uniformWrite(
const char *value,
int64 length=0);
314 bool endUniformArray(
int64 *nwritten=0);
353 bool verbose_ascii =
false);
358 {
return jsonUniformArray(a.
size(), a.
data()); }
360 {
return jsonUniformArray(a.
size(), a.
data()); }
362 {
return jsonUniformArray(a.
size(), a.
data()); }
364 {
return jsonUniformArray(a.
size(), a.
data()); }
366 {
return jsonUniformArray(a.
size(), a.
data()); }
407 std::streamsize xsputn(
const char*
s, std::streamsize
num)
override;
413 bool writeTile(
const char *data,
exint bytes);
432 virtual bool subclassWriteData(
const void*
data,
int64 bytes) = 0;
438 int precision16()
const {
return (myPrecision+1)/2; }
439 int precision32()
const {
return myPrecision; }
440 int precision64()
const {
return myPrecision*2; }
454 bool quotedString(
const char *str,
int64 bytes=0);
456 bool writeAB(
bool i);
458 bool writeAI(
int64 i);
466 bool finishArray(
UT_JID id,
bool newline=
true);
470 void pushState(
UT_JID id);
476 void bumpIndent(
int dir);
478 bool newLine(
bool force=
false);
481 bool countAndWrite(
const void *
data,
int64 bytes);
483 template <
typename T>
bool
485 template <
typename T>
bool
487 template <
typename T>
bool
489 template <
typename T>
bool
503 int64 myCurrentFilePosition;
521 bool myPrettyCompact;
557 : myWriter(
UT_JSONWriter::allocWriter(os, binary, compressionType))
564 : 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 *)
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)
GLint GLint GLint GLint GLint GLint GLsizei width
bool jsonValue(int32 value)
0x23 and 0x24 are reserved for future use (32/64 bit unsigned)
GLboolean GLboolean GLboolean GLboolean a
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
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.
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.
GLint GLenum GLsizei GLint GLsizei const void * data
const GLuint GLenum const void * binary
static UT_JID jidFromValue(const fpreal16 *)
#define SYS_PRINTF_CHECK_ATTRIBUTE(string_index, first_to_check)
GLubyte GLubyte GLubyte GLubyte w
bool getPrettyCompact() const
bool jsonValue(int16 value)
GLuint GLsizei GLsizei * length
bool jsonValue(unsigned value)
The following 4 bytes represent an 32 bit integer.
GLuint GLuint GLsizei GLenum type
void setPrettyCompact(bool compact)
void fastReferenceWithStrlen(const char *src, exint length)
bool jsonUniformArray(const UT_Int16Array &a)
bool jsonValue(const UT_Int16Array &v)
bool jsonUniformArray(const UT_Int64Array &a)
void setComments(bool comment)
GLdouble GLdouble GLdouble b
GLsizei const GLchar *const * string
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)
SYS_FORCE_INLINE bool jsonKeyValue(const UT_StringRef &key, const T &value)
GLuint GLuint GLsizei count
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 *)
GLenum GLint GLint * precision
GLsizei const GLfloat * value
bool getPrettyPrint() const
void setUseTokens(bool usetokens)
bool jsonValue(const UT_StringArray &v)
void setPrecision(int precision)
Direct access to options.
bool jsonValue(const UT_Int64Array &v)