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