HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_JSONWriter.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_JSONWriter.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __UT_JSONWriter__
12 #define __UT_JSONWriter__
13 
14 #include "UT_Compression.h"
15 #include "UT_IntArray.h"
16 #include "UT_JSONDefines.h"
17 #include "UT_StringMap.h"
18 #include "UT_WorkBuffer.h"
19 #include "UT_Set.h"
20 #include <ostream>
21 #include <streambuf>
22 #include <string>
23 
24 class UT_Options;
25 class UT_BitArray;
26 class UT_JSONValue;
27 
28 /// @brief Class which writes ASCII or binary JSON streams
29 ///
30 /// The JSON format (http://www.json.org) is a generic way to store data.
31 /// Houdini extends JSON to a byte-stream binary encoding (see UT_JID for
32 /// details). The UT_JSONWriter class is used to write JSON (binary or
33 /// ASCII) to a stream.
34 /// @see UT_JID, UT_JSONValue, UT_AutoJSONWriter
36 {
37 public:
38  /// @param options @n
39  /// A UT_Options class which sets specific format options.
40  /// @see setOptions()
41  UT_JSONWriter(const UT_Options *options=0);
42  virtual ~UT_JSONWriter();
43 
44  /// Allocate a JSON Writer which will fill a UT_WorkBuffer.
45  /// Please delete when finished with the writer.
46  static UT_JSONWriter *allocWriter(UT_WorkBuffer &buffer);
47 
48  /// Allocate a JSON Writer which writes to an output stream.
49  /// Please delete when finished with the writer.
50  static UT_JSONWriter *allocWriter(
51  std::ostream &os,
52  bool binary,
54 
55  /// Allocate a JSON Writer which writes to a named file.
56  /// Please delete when finished with the writer.
57  static UT_JSONWriter *allocWriter(
58  const char *filename,
59  bool binary,
61 
62  /// Allocate a JSON Writer which writes into a given UT_JSONValue. The
63  /// value will only be set properly at the conclusion of writing.
64  /// Please delete when finished with the writer.
65  static UT_JSONWriter *allocWriter(UT_JSONValue &value);
66 
67  /// Set formatting/control options base on the UT_Options. The following
68  /// options are scanned:
69  /// - @b int @b "json:precision" -- ASCII float precision [9].
70  /// Note half-precision floats will use half this precision, while double
71  /// precision will use twice the digits.
72  /// - @b int @b "json:indentstep" -- ASCII indent step for maps/arrays [8]
73  /// - @b int @b "json:textwidth" -- ASCII wrap lines after byte count [256]
74  /// - @b bool @b "json:comments" -- Allow comments in ASCII stream [false]
75  /// - @b bool @b "json:prettyprint" -- Pretty print ASCII stream [true]
76  /// - @b bool @b "json:usetokens" -- Binary string token compression [true]
77  /// - @b bool @b "json:prettycompact" -- Add a space after separators, a
78  /// more compact pretty print matching Python [false]
79  void setOptions(const UT_Options &options);
80 
81  /// Get the current options. This will set the token/values in
82  /// the UT_Options based on options from setOptions()
83  void getOptions(UT_Options &options) const;
84 
85  /// Direct access to options.
86  void setPrecision(int precision) { myPrecision = SYSmax(1, precision); }
87  int getPrecision() const { return myPrecision; }
88  void setIndentStep(int indentstep) { myIndentStep = indentstep; }
89  int getIndentStep() const { return myIndentStep; }
90  void setUseTokens(bool usetokens) { myTokenStrings = usetokens; }
91  bool getUseTokens() const { return myTokenStrings; }
92  void setTextWidth(int width) { myTextWidth = width; }
93  int getTextWidth() const { return myTextWidth; }
94  void setComments(bool comment) { myComments = comment; }
95  bool getComments() const { return myComments; }
96  void setPrettyPrint(bool prettyprint) { myPrettyPrint = prettyprint; }
97  bool getPrettyPrint() const { return myPrettyPrint; }
98  void setPrettyCompact(bool compact) { myPrettyCompact = compact; }
99  bool getPrettyCompact() const { return myPrettyCompact; }
100 
101  /// Turn the JSON writer into a binary JSON (bJSON) writer.
102  /// @warning This method must be called before any other data is written to
103  /// the JSON file. It's a @b good idea to call in the sub-class
104  /// constructor.
105  bool setBinary(bool bin);
106 
107  /// Return whether writing binary or ASCII JSON
108  bool getBinary() const { return myBinary; }
109 
110  /// Get the number of bytes written to output so far.
111  int64 getNumBytesWritten() const { return myCurrentFilePosition; }
112 
113  /// Start a new embedded file
114  void startNewFile();
115 
116  /// End a started embedded file
117  void endNewFile();
118 
119  /// Output a comment in the JSON stream. Not all JSON parsers (actually
120  /// very few) support comments. The json:comments must be enabled for this
121  /// statement to have any effect.
122  bool jsonComment(const char *format, ...)
124 
125  // Standard JSON types
126  /// Write a @b null to the stream
127  bool jsonNull();
128  /// Write true/false
129  bool jsonBool(bool value);
130  /// Write an integer value
131  bool jsonInt(int32 value);
132  /// Write a 64 bit integer value
133  bool jsonInt(int64 value);
134  /// Write a 64 bit integer as a 64 bit integer
135  bool jsonInt64(int64 value);
136  /// Write a 16 bit real
137  bool jsonReal(fpreal16 value);
138  bool jsonRealPreserveType(fpreal16 value);
139  /// Write a 32 bit real
140  bool jsonReal(fpreal32 value);
141  bool jsonRealPreserveType(fpreal32 value);
142  /// Write a 64 bit real
143  bool jsonReal(fpreal64 value);
144  bool jsonRealPreserveType(fpreal64 value);
145  /// Write a quoted string.
146  /// @warning Please use jsonKey() to write key strings.
147  /// @note Use jsonStringToken() to take advantage of token compression
148  /// (this can be turned off with the @c usetokens option in the
149  /// constructor).
150  /// @see UT_JID
151  bool jsonString(const char *value, int64 length=0);
152 
153  /// For binary streams, common strings can be output more efficiently using
154  /// the token interface. Token strings will appear as strings in ASCII
155  /// streams.
156  bool jsonStringToken(const UT_StringRef &value);
157  bool jsonStringToken(const char *value, int64 length)
158  {
160  if (length <= 0)
161  result.reference(value);
162  else
163  result.fastReferenceWithStrlen(value, length);
164  return jsonStringToken(result);
165  }
166 
167  /// @{
168  /// Write a standard JSON value to the stream. Overloaded method to allow
169  /// convenient use in templated code.
170  bool jsonValue(bool value) { return jsonBool(value); }
171  bool jsonValue(int8 value) { return jsonInt((int32)value); }
172  bool jsonValue(int16 value) { return jsonInt((int32)value); }
173  bool jsonValue(int32 value) { return jsonInt(value); }
174  bool jsonValue(unsigned value) { return jsonInt((int32)value); }
175  bool jsonValue(int64 value) { return jsonInt(value); }
176  bool jsonValue(fpreal16 value) { return jsonReal(value); }
177  bool jsonValue(fpreal32 value) { return jsonReal(value); }
178  bool jsonValue(fpreal64 value) { return jsonReal(value); }
179  bool jsonValue(const char *v) { return jsonStringToken(v); }
180  bool jsonValue(const UT_String &v)
181  { return jsonStringToken(v.c_str(), v.length()); }
182  bool jsonValue(const std::string &v)
183  { return jsonStringToken(v.c_str(), v.length()); }
184  bool jsonValue(const UT_StringRef &v) { return jsonStringToken(v); }
185  bool jsonValue(const UT_Int16Array &v)
186  { return jsonUniformArray(v); }
187  bool jsonValue(const UT_Int32Array &v)
188  { return jsonUniformArray(v); }
189  bool jsonValue(const UT_Int64Array &v)
190  { return jsonUniformArray(v); }
192  { return jsonUniformArray(v); }
194  { return jsonUniformArray(v); }
196  { return jsonStringTokenArray(v); }
197  bool jsonValue(const UT_JSONValue &v);
198  template <typename T>
199  bool jsonValue(const UT_Set<T>& v)
200  {
201  return jsonSetAsArray(v);
202  }
203  /// @}
204 
205  /// Begin a map/object dictionary
206  bool jsonBeginMap();
207  /// Write a quoted key for the object
208  /// @note Use jsonKeyToken() to take advantage of token compression
209  /// (this can be turned off with the @c usetokens option in the
210  /// constructor).
211  /// @see UT_JID
212  bool jsonKey(const char *value, int64 length=0);
213  /// For binary streams, common key strings can be output more efficiently
214  /// using the token interface. Token key strings will appear as strings in
215  /// ASCII streams.
216  bool jsonKeyToken(const UT_StringRef &value);
217  bool jsonKeyToken(const char *value, int64 length)
218  {
220  if (length <= 0)
221  result.reference(value);
222  else
223  result.fastReferenceWithStrlen(value, length);
224  return jsonKeyToken(result);
225  }
226 
227  /// @{
228  /// Convenience method to write the key/value pair to a map
229  template <typename T> SYS_FORCE_INLINE bool
230  jsonKeyValue(const UT_StringRef &key, const T &value)
231  {
232  bool ok = jsonKeyToken(key);
233  return ok && jsonValue(value);
234  }
235 
236  template <typename T> SYS_FORCE_INLINE bool
237  jsonKeyTokenValue(const UT_StringRef &key, const T &value)
238  {
239  bool ok = jsonKeyToken(key);
240  return ok && jsonValue(value);
241  }
242  /// @}
243 
244  /// End the object
245  bool jsonEndMap();
246 
247  /// Begin a generic array object
248  bool jsonBeginArray();
249  /// End a generic array object
250  /// By default, a new line will be output for pretty printing. The newline
251  /// can give a hint to omit the new line before the end of the array
252  /// marker.
253  bool jsonEndArray(bool newline=true);
254 
255  /// When writing binary JSON files, uniform arrays can be encoded without
256  /// repetition of the type information which results in a more compressed
257  /// data format.
258  ///
259  /// @c beingUniformArray() starts a uniform array.
260  /// The @c id should be one of:
261  /// - UT_JID_BOOL
262  /// - UT_JID_INT8
263  /// - UT_JID_INT16
264  /// - UT_JID_INT32
265  /// - UT_JID_INT64
266  /// - UT_JID_UINT8
267  /// - UT_JID_UINT16
268  /// - UT_JID_REAL16
269  /// - UT_JID_REAL32
270  /// - UT_JID_REAL64
271  /// - UT_JID_STRING
272  bool beginUniformArray(int64 length, UT_JID id);
273  /// Write a bool value to a uniform array. The bool values are packed into
274  /// a bit array (where each 32-bit word stores 32 bits).
275  bool uniformWrite(bool value);
276  /// Write an 8 bit integer value to the uniform array
277  bool uniformWrite(int8 value);
278  /// Write an 16 bit integer value to the uniform array
279  bool uniformWrite(int16 value);
280  /// Write an 32 bit integer value to the uniform array
281  bool uniformWrite(int32 value);
282  /// Write an 64 bit integer value to the uniform array
283  bool uniformWrite(int64 value);
284  /// Write an 16 bit float/real value to the uniform array
285  bool uniformWrite(fpreal16 value);
286  /// Write an 32 bit float/real value to the uniform array
287  bool uniformWrite(fpreal32 value);
288  /// Write an 64 bit float/real value to the uniform array
289  bool uniformWrite(fpreal64 value);
290  /// Write an 8 bit unsigned integer value to the uniform array
291  bool uniformWrite(uint8 value);
292  /// Write an 16 bit unsigned integer value to the uniform array
293  bool uniformWrite(uint16 value);
294  /// Write a string to the uniform array
295  bool uniformWrite(const char *value, int64 length=0);
296  /// Write a block of 8 bit integer values to the uniform array
297  bool uniformBlockWrite(const int8 *value, int64 count);
298  /// Write a block of 16 bit integer values to the uniform array
299  bool uniformBlockWrite(const int16 *value, int64 count);
300  /// Write a block of 32 bit integer values to the uniform array
301  bool uniformBlockWrite(const int32 *value, int64 count);
302  /// Write a block of 64 bit integer values to the uniform array
303  bool uniformBlockWrite(const int64 *value, int64 count);
304  /// Write a block of 16 bit float/real values to the uniform array
305  bool uniformBlockWrite(const fpreal16 *value, int64 count);
306  /// Write a block of 32 bit float/real values to the uniform array
307  bool uniformBlockWrite(const fpreal32 *value, int64 count);
308  /// Write a block of 64 bit float/real values to the uniform array
309  bool uniformBlockWrite(const fpreal64 *value, int64 count);
310  /// Write a block of 8 bit unsigned integer values to the uniform array
311  bool uniformBlockWrite(const uint8 *value, int64 count);
312  /// Write a block of 16 bit unsigned integer values to the uniform array
313  bool uniformBlockWrite(const uint16 *value, int64 count);
314  /// End the uniform array.
315  /// @param nwritten @n
316  /// If provided, the number of items written is returned.
317  /// @note The JSONWriter class will automatically clamp or fill the uniform
318  /// array with 0, but nwritten will return the actual number of calls to
319  /// uniformWrite().
320  bool endUniformArray(int64 *nwritten=0);
321 
322  /// Internally called to write raw data to output.
323  virtual bool writeData(const void *data, int64 bytes);
324 
325  /// Returns the JID that matches the given type.
326  static UT_JID jidFromValue(const bool *) { return UT_JID_BOOL; }
327  static UT_JID jidFromValue(const int8 *) { return UT_JID_INT8; }
328  static UT_JID jidFromValue(const int16 *) { return UT_JID_INT16; }
329  static UT_JID jidFromValue(const int32 *) { return UT_JID_INT32; }
330  static UT_JID jidFromValue(const int64 *) { return UT_JID_INT64; }
331  static UT_JID jidFromValue(const fpreal16 *) { return UT_JID_REAL16; }
332  static UT_JID jidFromValue(const fpreal32 *) { return UT_JID_REAL32; }
333  static UT_JID jidFromValue(const fpreal64 *) { return UT_JID_REAL64; }
334  static UT_JID jidFromValue(const uint8 *) { return UT_JID_UINT8; }
335  static UT_JID jidFromValue(const uint16 *) { return UT_JID_UINT16; }
336 
337  /// Efficent method of writing a uniform array of int8 values
338  bool jsonUniformArray(int64 length, const int8 *value);
339  /// Efficent method of writing a uniform array of int16 values
340  bool jsonUniformArray(int64 length, const int16 *value);
341  /// Efficent method of writing a uniform array of int32 values
342  bool jsonUniformArray(int64 length, const int32 *value);
343  /// Efficent method of writing a uniform array of int64 values
344  bool jsonUniformArray(int64 length, const int64 *value);
345  /// Efficent method of writing a uniform array of fpreal16 values
346  bool jsonUniformArray(int64 length, const fpreal16 *value);
347  /// Efficent method of writing a uniform array of fpreal32 values
348  bool jsonUniformArray(int64 length, const fpreal32 *value);
349  /// Efficent method of writing a uniform array of fpreal64 values
350  bool jsonUniformArray(int64 length, const fpreal64 *value);
351 
352  /// Efficent method of writing a uniform array of uint8 values
353  bool jsonUniformArray(int64 length, const uint8 *value);
354  /// Efficent method of writing a uniform array of uint16 values
355  bool jsonUniformArray(int64 length, const uint16 *value);
356 
357  /// Efficient method of writing a uniform array of bool values
358  bool jsonUniformArray(int64 length, const UT_BitArray &value,
359  bool verbose_ascii = false);
360 
361  /// @{
362  /// Convenience method for saving common array types
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()); }
373  /// @}
374 
375  /// Convenience method to save a set as an array of strings
376  template <typename T>
378  {
379  if (!jsonBeginArray())
380  return false;
381 
382  for (auto&& v : a)
383  jsonValue(v);
384 
385  return jsonEndArray();
386  }
387 
388  /// Convenience method to save an array of strings
389  bool jsonStringArray(const UT_StringArray &a);
390  /// Convenience method to save an array of strings (as tokens)
391  bool jsonStringTokenArray(const UT_StringArray &a);
392 
393  /// A TiledStream allows you to write a blob of binary data to a JSON
394  /// stream in an efficient manner. The data is buffered into uniform
395  /// arrays which are output into a standard JSON array. The resulting data
396  /// looks something like: @code
397  /// [ {options} tile1-data tile2-data ]
398  /// @endcode
399  /// The tile-data is written as JSON string objects. You can read these
400  /// yourself, or use the TiledStream in UT_JSONParser.
401  ///
402  /// You should never write to the JSONWriter while the TiledStream is open.
403  ///
404  /// An example of using this might be something like: @code
405  /// bool storeStream(UT_IStream &is)
406  /// {
407  /// UT_JSONWriter::TiledStream os(writer);
408  /// char buffer[128];
409  /// int nread;
410  /// while ((nread = is.bread(buffer, 128)) > 0)
411  /// if (!os.write(buffer, nread)) return false;
412  /// return true;
413  /// }
414  /// @endcode
415  class UT_API TiledStreamBuf : public std::streambuf
416  {
417  public:
419  ~TiledStreamBuf() override;
420 
421  protected:
422  // write one character
423  int_type overflow(int_type c) override;
424 
425  // write multiple characters
426  std::streamsize xsputn(const char* s, std::streamsize num) override;
427 
428  private:
429  bool write(const void *data, exint bytes);
430  void close();
431 
432  bool writeTile(const char *data, exint bytes);
433  bool flush();
434  UT_JSONWriter &myWriter;
435  char *myBuffer;
436  exint myLength;
437  };
438 
439  class UT_API TiledStream : public std::ostream
440  {
441  public:
443  ~TiledStream() override;
444 
445  private:
446  TiledStreamBuf myBuf;
447  };
448 
449 protected:
450  /// The sub-class must implement this method to write data
451  virtual bool subclassWriteData(const void* data, int64 bytes) = 0;
452 
453 protected:
454  /// Get the nesting level (i.e. how deeply nested in maps/arrays)
455  int getNesting() const { return myStack.entries(); }
456 private:
457  int precision16() const { return (myPrecision+1)/2; }
458  int precision32() const { return myPrecision; }
459  int precision64() const { return myPrecision*2; }
460  /// @private: ASCII indent
461  bool indent();
462  /// @private: ASCII prefix
463  bool prefix();
464  /// @private: Convenience method to write a UT_JID
465  bool writeId(UT_JID id);
466  /// @private: Convenience method to write an encoded length @see UT_JID
467  bool writeLength(int64 length);
468  /// @private: Write a token string
469  bool writeTokenString(const UT_StringRef &str);
470  /// @private: Write a string of data (not quoted)
471  bool writeString(const char *str, int64 bytes=0);
472  /// @private: Write a quoted string
473  bool quotedString(const char *str, int64 bytes=0);
474  /// @private: Write an ASCII "bool" value
475  bool writeAB(bool i);
476  /// @private: Write an ASCII "integer" value
477  bool writeAI(int64 i);
478  /// @private: Write an ASCII "float" value
479  bool writeAF(fpreal64 i, int precision);
480  /// @private: Write an ASCII "float" value and ensure it has a decimal point
481  bool writeAFPreserveType(fpreal64, int precision);
482  /// @private: Start an array (possibly uniform encoding)
483  bool startArray(UT_JID id, UT_JID type=UT_JID_NULL);
484  /// @private: Finish array
485  bool finishArray(UT_JID id, bool newline=true);
486  /// @private: Flush bits for a uniform array of bools
487  bool flushBits();
488  /// @private: Push nesting of map/array
489  void pushState(UT_JID id);
490  /// @private: Pop state
491  void popState(UT_JID id);
492  /// @private: Set the prefix for ASCII encoding
493  void setPrefix();
494  /// @private: Build indent string
495  void bumpIndent(int dir);
496  /// @private: New line & indent
497  bool newLine(bool force=false);
498 
499  /// Method to detail with long lines in ASCII files
500  bool countAndWrite(const void *data, int64 bytes);
501 
502  template <typename T> bool
503  uniformArrayI(UT_JID id, int64 length, const T *data);
504  template <typename T> bool
505  uniformArrayF(UT_JID id, int64 length, const T *data);
506  template <typename T> bool
507  uniformBlockWriteImplI(const T *data, int64 count);
508  template <typename T> bool
509  uniformBlockWriteImplF(const T *data, int64 count, int prec);
510 
511  enum
512  {
513  PREFIX_FIRST, // First element (no prefix)
514  PREFIX_ARRAY, // Use array prefix
515  PREFIX_MAP, // Use object prefix
516  };
517 
518  UT_IntArray myStack;
519  UT_WorkBuffer myIndentString;
520  UT_StringMap<int64> myTokens;
521  UT_Int64Array myTokenCountStack;
522  int64 myCurrentFilePosition;
523  int64 myUWriteSize; // Uniform write size
524  int64 myUWriteCount; // Uniform entities written
525  int64 myTokenCount;
526  UT_JID myUniform; // Type of data for fixed array
527  uint32 myBitValue; // For packing bit arrays
528  int myBitCount;
529  int myPrefix;
530 
531  bool myBinary; // ASCII or binary
532 
533  // Options
534  int myPrecision; // ASCII float precision
535  int myIndentStep; // ASCII indent step
536  int myTextWidth; // ASCII max line length
537  bool myTokenStrings; // Use token strings
538  bool myComments; // Emit comments
539  bool myPrettyPrint; // Pretty print
540  bool myPrettyCompact; // Python style, spaces after sepators, no newlines.
541 
542  // State required for formatting.
543  bool myNewLine; // Pending newline, for line wrapping
544  bool myJoinNext;
545  int myIndent; // ASCII indent level
546  int myLineLength; // ASCII line length
547 };
548 
549 /// Convenience class to allocate a writer which is automatically deleted
550 /// For example: @code
551 /// bool save(UT_JSONWriter &w) { ... } // Method to save to standard writer
552 ///
553 /// bool save(UT_WorkBuffer &buffer) // Save to a UT_WorkBuffer
554 /// {
555 /// UT_AutoJSONWriter w(buffer);
556 /// return save(w);
557 /// }
558 /// bool save(UT_JSONValue &value) // Save to a UT_JSONValue
559 /// {
560 /// UT_AutoJSONWriter w(value);
561 /// return save(w);
562 /// }
563 /// @endcode
565 {
566 public:
567  /// Write directly to the UT_WorkBuffer
569  : myWriter(UT_JSONWriter::allocWriter(b))
570  {
571  }
572  /// Write to the given ostream (binary and optionally gzipped)
573  UT_AutoJSONWriter(std::ostream &os,
574  bool binary,
575  UT_CompressionType compressionType = UT_COMPRESSION_TYPE_NONE )
576  : myWriter(UT_JSONWriter::allocWriter(os, binary, compressionType))
577  {
578  }
579  /// Write to the given filename (binary and optionally gzipped)
580  UT_AutoJSONWriter(const char *filename,
581  bool binary,
583  : myWriter(UT_JSONWriter::allocWriter(filename, binary, compressionType))
584  {
585  }
586  /// Write directly to the UT_JSONValue
588  : myWriter(UT_JSONWriter::allocWriter(value))
589  {
590  }
592  {
593  delete myWriter;
594  }
595 
596  /// @{
597  /// Access to the writer
598  UT_JSONWriter &writer() const { return *myWriter; }
599  UT_JSONWriter &operator*() const { return *myWriter; }
600  UT_JSONWriter *operator->() const { return myWriter; }
601  /// @}
602 
603  /// Allow implicit casting between an auto-writer and the underlying writer
604  operator UT_JSONWriter &() { return *myWriter; }
605 
606  /// Close the stream (causing all data to be flushed)
607  void close()
608  {
609  delete myWriter;
610  myWriter = NULL;
611  }
612 private:
613  UT_JSONWriter *myWriter;
614 };
615 
616 #endif
UT_JSONWriter & operator*() const
The following byte represents an 8 bit integer.
#define SYSmax(a, b)
Definition: SYS_Math.h:1535
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
Definition: glcorearb.h:1221
unsigned short uint16
Definition: SYS_Types.h:38
static UT_JID jidFromValue(const int64 *)
Definition: UT_Set.h:58
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.
int int32
Definition: SYS_Types.h:39
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
Definition: UT_JSONWriter.h:91
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)
Definition: Compression.h:363
bool jsonValue(int32 value)
0x23 and 0x24 are reserved for future use (32/64 bit unsigned)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
const GLfloat * c
Definition: glew.h:16631
int64 exint
Definition: SYS_Types.h:125
The following byte represents an unsigned 8 bit integer.
#define UT_API
Definition: UT_API.h:14
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
bool jsonValue(fpreal16 value)
void close() override
UT_JSONWriter & writer() const
bool jsonValue(const UT_String &v)
float fpreal32
Definition: SYS_Types.h:200
bool jsonUniformArray(const UT_Int32Array &a)
GLuint buffer
Definition: glcorearb.h:659
exint size() const
Definition: UT_Array.h:479
const char * c_str() const
Definition: UT_String.h:498
bool jsonValue(const char *v)
unsigned length() const
Return length of string.
Definition: UT_String.h:536
bool getComments() const
Definition: UT_JSONWriter.h:95
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
void setPrettyPrint(bool prettyprint)
Definition: UT_JSONWriter.h:96
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.
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
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)
Definition: Name.h:31
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)
Definition: SYS_Types.h:447
const GLdouble * v
Definition: glcorearb.h:836
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
GLuint num
Definition: glew.h:2695
bool getPrettyCompact() const
Definition: UT_JSONWriter.h:99
bool jsonValue(int16 value)
long long int64
Definition: SYS_Types.h:116
GLint GLsizei count
Definition: glcorearb.h:404
bool jsonValue(unsigned value)
signed char int8
Definition: SYS_Types.h:35
The following 4 bytes represent an 32 bit integer.
int getPrecision() const
Definition: UT_JSONWriter.h:87
void setPrettyCompact(bool compact)
Definition: UT_JSONWriter.h:98
GLint GLsizei width
Definition: glcorearb.h:102
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)
GLenum GLint GLint * precision
Definition: glcorearb.h:1924
void setComments(bool comment)
Definition: UT_JSONWriter.h:94
GLboolean * data
Definition: glcorearb.h:130
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:107
void setIndentStep(int indentstep)
Definition: UT_JSONWriter.h:88
bool jsonUniformArray(const UT_Fpreal32Array &a)
A map of string to various well defined value types.
Definition: UT_Options.h:84
static UT_JID jidFromValue(const int8 *)
static UT_JID jidFromValue(const uint16 *)
bool jsonValue(const std::string &v)
short int16
Definition: SYS_Types.h:37
UT_CompressionType
T * data()
Definition: UT_Array.h:655
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)
GLsizei const GLfloat * value
Definition: glcorearb.h:823
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.
Definition: UT_JSONValue.h:77
unsigned int uint32
Definition: SYS_Types.h:40
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
Definition: UT_JSONWriter.h:89
bool jsonUniformArray(const UT_Fpreal64Array &a)
#define const
Definition: zconf.h:214
bool jsonValue(const UT_Fpreal64Array &v)
void setTextWidth(int width)
Definition: UT_JSONWriter.h:92
bool jsonValue(fpreal64 value)
void write(T &out, bool v)
Definition: ImfXdr.h:332
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 *)
GLdouble s
Definition: glew.h:1395
bool getPrettyPrint() const
Definition: UT_JSONWriter.h:97
void setUseTokens(bool usetokens)
Definition: UT_JSONWriter.h:90
bool jsonValue(const UT_Set< T > &v)
bool jsonValue(const UT_StringArray &v)
Definition: format.h:3611
int getTextWidth() const
Definition: UT_JSONWriter.h:93
void setPrecision(int precision)
Direct access to options.
Definition: UT_JSONWriter.h:86
bool jsonValue(const UT_Int64Array &v)