11 #ifndef __UT_JSONWriter__
12 #define __UT_JSONWriter__
110 bool setBinary(
bool bin);
127 bool jsonComment(
const char *
format, ...)
134 bool jsonBool(
bool value);
136 bool jsonInt(
int32 value);
138 bool jsonInt(
int64 value);
140 bool jsonInt64(
int64 value);
143 bool jsonRealPreserveType(
fpreal16 value);
146 bool jsonRealPreserveType(
fpreal32 value);
149 bool jsonRealPreserveType(
fpreal64 value);
156 bool jsonString(const
char *value,
int64 length=0);
162 bool jsonStringToken(const
char *value,
int64 length)
169 return jsonStringToken(result);
188 {
return jsonStringToken(v.c_str(), v.length()); }
191 {
return jsonUniformArray(v); }
193 {
return jsonUniformArray(v); }
195 {
return jsonUniformArray(v); }
197 {
return jsonUniformArray(v); }
199 {
return jsonUniformArray(v); }
201 {
return jsonStringTokenArray(v); }
203 template <
typename T>
206 return jsonSetAsArray(v);
229 return jsonKeyToken(result);
237 bool ok = jsonKeyToken(key);
238 return ok && jsonValue(value);
244 bool ok = jsonKeyToken(key);
245 return ok && jsonValue(value);
253 bool jsonBeginArray();
258 bool jsonEndArray(
bool newline=
true);
280 bool uniformWrite(
bool value);
282 bool uniformWrite(
int8 value);
284 bool uniformWrite(
int16 value);
286 bool uniformWrite(
int32 value);
288 bool uniformWrite(
int64 value);
296 bool uniformWrite(
uint8 value);
298 bool uniformWrite(
uint16 value);
300 bool uniformWrite(
const char *value,
int64 length=0);
325 bool endUniformArray(
int64 *nwritten=0);
364 bool verbose_ascii =
false);
369 {
return jsonUniformArray(a.
size(), a.
data()); }
371 {
return jsonUniformArray(a.
size(), a.
data()); }
373 {
return jsonUniformArray(a.
size(), a.
data()); }
375 {
return jsonUniformArray(a.
size(), a.
data()); }
377 {
return jsonUniformArray(a.
size(), a.
data()); }
381 template <
typename T>
384 if (!jsonBeginArray())
390 return jsonEndArray();
434 std::streamsize xsputn(
const char*
s, std::streamsize num)
override;
440 bool writeTile(
const char *data,
exint bytes);
461 virtual bool subclassWriteData(
const void*
data,
int64 bytes) = 0;
467 int precision16()
const {
return (myPrecision+1)/2; }
468 int precision32()
const {
return myPrecision; }
469 int precision64()
const {
return myPrecision*2; }
483 bool quotedString(
const char *str,
int64 bytes=0);
485 bool writeAB(
bool i);
487 bool writeAI(
int64 i);
495 bool finishArray(
UT_JID id,
bool newline=
true);
499 void pushState(
UT_JID id);
505 void bumpIndent(
int dir);
507 bool newLine(
bool force=
false);
512 template <
typename T>
bool
514 template <
typename T>
bool
516 template <
typename T>
bool
518 template <
typename T>
bool
534 int64 myCurrentFilePosition;
552 bool myPrettyCompact;
588 : myWriter(
UT_JSONWriter::allocWriter(os, binary, compressionType))
595 : 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)
bool jsonValue(int32 value)
GLsizei const GLchar *const * string
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.
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)
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.
static UT_JID jidFromValue(const int8 *)
SIM_API const UT_StringHolder force
static UT_JID jidFromValue(const uint16 *)
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)
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 *)
GLubyte GLubyte GLubyte GLubyte w
int getIndentStep() const
bool jsonUniformArray(const UT_Fpreal64Array &a)
bool jsonValue(const UT_Fpreal64Array &v)
void setTextWidth(int width)
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)
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)