HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Options.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_Options.h (C++, Utility Library)
7  *
8  * COMMENTS: This is a smaller, faster, more type-safe version of
9  * UT_OptionFile. The reason UT_OptionFile was not simply
10  * re-implemented is that when saving and loading UT_OptionFiles,
11  * no information about the type of each option is saved. This
12  * implementation writes out the type of each data item.
13  *
14  */
15 
16 #ifndef _UT_OPTIONS_H_
17 #define _UT_OPTIONS_H_
18 
19 #include "UT_API.h"
20 #include "UT_SmallObject.h"
21 #include "UT_StringArray.h"
22 #include "UT_StringHolder.h"
23 #include "UT_ArrayStringMap.h"
24 #include "UT_UniquePtr.h"
25 #include "UT_SharedPtr.h"
26 #include "UT_VectorTypes.h"
27 #include "UT_ValArray.h"
28 #include <SYS/SYS_TypeTraits.h>
29 #include <iosfwd>
30 #include <string>
31 #include <memory>
32 #include <utility>
33 
34 class UT_IStream;
35 class UT_JSONValue;
36 class UT_JSONValueMap;
37 class UT_JSONParser;
38 class UT_JSONWriter;
39 class UT_WorkBuffer;
40 
41 // NOTE: The values of UT_OptionType are saved to disk, thus we should NOT
42 // reorder these options if we want to maintain compatibility with older
43 // saved options.
45 {
59  UT_OPTION_STRINGRAW = 12, // used by getPyOptionString
60  UT_OPTION_INTARRAY = 13, // Array of integers
61  UT_OPTION_FPREALARRAY = 14, // Array of float/double
64  UT_OPTION_DICT = 17, // Option of option
66 
67  UT_OPTION_NUM_TYPES // Sentinal
68 };
69 
70 /// String formatting options for getOptionString
72 {
73  UT_OPTFMT_DISPLAY, // Format for display
74  UT_OPTFMT_PYTHON, // Format for python
75  UT_OPTFMT_VEX, // Format for VEX arguments
77 };
78 
79 class UT_OptionsHolder;
80 class UT_OptionEntry;
82 
83 /// A map of string to various well defined value types
85 {
86 private:
87  /// Storage type for the option map
89 
90 public:
91  // Default constructor (empty options)
92  UT_Options();
93  // Copy c-tor
94  UT_Options(const UT_Options &src);
95  virtual ~UT_Options();
96 
97  /// Variadic constructor that allows addition of options during
98  /// construction. Using this option requires very careful coding (as does
99  /// all variadic coding). For example, there is no type checking of
100  /// variadic arguments. If there are floating point arguments, they @b
101  /// must be specified as double (i.e. Not "0", but rather "0.0").
102  /// Type tokens expected are:
103  /// - "int" @n A single @b int value follows
104  /// - "int64" @n A single @b int64 value follows
105  /// - "bool" @n A single @b int follows
106  /// - "float" @n A single @b double follows
107  /// - "string" @n A single string value follows
108  /// - "vector2" @n Two (2) double arguments follow
109  /// - "vector3" @n Three (3) double arguments follow
110  /// - "vector4" @n Four (4) double arguments follow
111  /// - "quaternion" @n Four (4) double arguments follow
112  /// - "matrix2" @n Four (4) double arguments follow
113  /// - "matrix3" @n Nine (9) double arguments follow
114  /// - "matrix4" @n Sixteen (16) double arguments follow
115  /// - "uv" @n Two (2) double arguments follow
116  /// - "uvw" @n Three (3) double arguments follow
117  /// - "stringraw" @n A single string value follows
118  /// - "int[N]" @n
119  /// @c N @b int values follow (creating an integer array).
120  /// Replace @c N with the actual value (of course).
121  /// No spaces may occur in the type name.
122  /// - "int64[N]" @n
123  /// @c N @b int64 values follow (creating an integer array).
124  /// Replace @c N with the actual value (of course).
125  /// No spaces may occur in the type name.
126  /// - "float[N]" @n
127  /// @c N @b double values follow (creating a float array).
128  /// Replace @c N with the actual value (of course).
129  /// No spaces may occur in the type name.
130  /// - "string[N]" @n
131  /// @c N @b string values follow (creating a string array).
132  /// Replace @c N with the actual value (of course).
133  /// No spaces may occur in the type name.
134  ///
135  /// Special type tokens
136  /// - "i_vector2", "i_vector3", "i_vector4", @n
137  /// A single @b double is used to set all components of the vector
138  /// - "i_quaternion" @n
139  /// A single @b double is used to set all components of the vector
140  /// - "i_uv", "i_uvw" @n
141  /// A single @b double is used to set all components of the vector
142  /// - "i_matrix3", "i_matrix4" @n
143  /// A single @b double is used to set the diagonal of the matrix3.
144  /// - "i_int[N]" @n
145  /// A single @b int64 is used to set all components of the array
146  /// - "i_float[N]" @n
147  /// A single @b double is used to set all components of the array
148  ///
149  /// The option name should follow the type specifier (separated by a single
150  /// space).
151  ///
152  /// A nullptr keyword determines the end of the options.
153  ///
154  /// Examples: @code
155  /// UT_Options options("int ival", 0,
156  /// "int64 i64val", (int64)5,
157  /// "bool toggle", (int)1,
158  /// "float fval", (fpreal64)0,
159  /// "vector3 P", 0.0, 1.0, 2.0,
160  /// "string map", "texture.pic",
161  /// "int[2] iarray", int64(0), int64(1),
162  /// nullptr); <======= MUST TERMINATE =======
163  /// @code
164  /// Common errors include: @code
165  /// UT_Options options(
166  /// "int ival", (int64)0, // Error, must be int
167  /// "int64 ival", (int)0, // Error, must be int64
168  /// "vector3 fval", 0, 1.0, 2.0, // First entry is an int!
169  /// "float[3] farray", 0.0, 1.0, // Missing 3rd value
170  /// /* MISSING nullptr TERMINATOR */);
171  /// @endcode
172  ///
173  /// This function effectively does not call optionChanged.
174  UT_Options(const char *type_and_name, ...);
175 
176  /// Lookup an option type based on a keyword
177  static UT_OptionType optionType(const UT_StringRef &kwd);
178 
179  // This function does not call optionChanged.
180  void clear();
181 
182  // Returns true on success or if the file didn't exist;
183  // returns false only if the file encounters an error.
184  // The load methods can handle files saved either with this save
185  // or with saveAsJSON. saveAsJSON is preferable as it handles 64bit
186  // floats and ints, but can't be read before H10.5
187  // When 'compact' parameter is true, the info is not explicitly saved.
188  bool load(const char *filename);
189  bool save(const char *filename) const;
190  bool saveOrdered(const char *filename) const;
191  bool load(const char *filename, UT_IStream &is);
192  bool save(const char *filename, std::ostream &os) const;
193  bool saveOrdered(const char *filename, std::ostream &os) const;
194 
195  bool saveAsJSON(const char *filename,
196  bool binary = true,
197  bool compact = false) const;
198  bool saveAsJSON(const char *filename, std::ostream &os,
199  bool binary = true,
200  bool compact = false) const;
201 
202  // Remove an option.
203  void removeOption(const UT_StringHolder &name);
204 
205  // Get the string representation of any of our options. Note that, if
206  // the value contains binary data with null characters, you can't determine
207  // the length of the data with UT_String version of these methods.
208  bool getOptionString(const UT_StringHolder &name,
210  UT_WorkBuffer &result) const;
211  bool getOptionString(const UT_StringHolder &name,
212  UT_OptionFormat format,
213  UT_String &result) const;
214 
215  // Append the python dictionary representation of ALL our options to the
216  // buffer
217  bool appendPyDictionary(UT_WorkBuffer &result,
218  bool sorted=false) const;
219 
220  // Parse a python dictionary string and merge the results into our
221  // options.
222  bool setFromPyDictionary(const char *dict);
223 
224  // Parse a python formatted value and set it as the named option.
225  bool setPyOptionString(const UT_StringHolder &name,
226  const char *value);
227 
228  /// Save a UT_Options to JSON format using UT_JSONWriter
229  /// @param w The writer stream used to save the options
230  /// @param compact If true, the type info is not explicitly saved.
231  bool save(UT_JSONWriter &w, bool compact = false) const;
232 
233  /// Save a UT_Options to a UT_JSONValue
234  /// @param map The value used to store the UT_Options
235  /// @param compact If true, the type info is not explicitly saved.
236  void save(UT_JSONValueMap &map, bool compact = false) const;
237 
238  /// Load a UT_Options from a JSON parser.
239  /// @param parser Parser
240  /// @param do_clear Clear existing map before loading
241  /// If true and the first object in the JSON stream is not a map object,
242  /// then the parser will fail (with an error). Otherwise a warning will
243  /// be added and the object will be skipped.
244  /// @param is If this is specified, then data will be read from that
245  /// stream rather than the stream associated with the parser.
246  /// @param require_type If true, the JSON input must contain option entries
247  /// in a format that explicitly specifies both the 'type' and the 'value'.
248  /// Otherwise, JSON may specify value directly, and the type will be
249  /// deduced implicitly from the value.
250  bool load(UT_JSONParser &parser,
251  bool do_clear,
252  UT_IStream *is = 0,
253  bool require_type = true);
254 
255  /// Loads a UT_Options from a JSONValue map.
256  /// @param map The source map
257  /// @param do_clear Clear the UT_Options before loading values from the map
258  /// @param allow_type Controls if a map with "type" and "value" entries
259  /// will be interpreted as an explicit type request.
260  /// @param allow_dict Controls if a map will be turned into a nested
261  /// dictionary.
262  /// Note: if both 'allow_type' and 'allow_dict' are true , things that
263  /// look like types will be treated as such; the rest as dictionaries.
264  bool load(const UT_JSONValueMap &map,
265  bool do_clear,
266  bool allow_type = true,
267  bool allow_dict = false);
268 
269  /// Writes a JSON dump to ostream of the current options.
270  void dump(std::ostream &os) const;
271  /// Dump to stdout/cout
272  void dump() const;
273 
274  // Functions for accessing the options by name.
275  bool hasOption(const UT_StringRef &name) const;
276  UT_OptionType getOptionType(const UT_StringRef &name) const;
277  const UT_OptionEntry*getOptionEntry(const UT_StringRef &name) const;
278 
279  exint getNumOptions() const { return myMap.size(); }
280  exint size() const { return getNumOptions(); }
281  exint entries() const { return getNumOptions(); }
282 
283  // Functions for accessing all options sequentially.
285  {
286  public:
288  : myOptions(nullptr)
289  {}
290  iterator(const iterator &i)
291  : myOptions(i.myOptions)
292  , myIterator(i.myIterator)
293  , myEnd(i.myEnd)
294  {}
295  const UT_StringHolder &name() const
296  { return myIterator->first; }
297  const UT_OptionEntry *entry() const
298  { return myIterator->second.get(); }
299  UT_OptionType type() const;
300  const UT_OptionEntry *operator*() const { return entry(); }
301 
303  {
304  myOptions = i.myOptions;
305  myIterator = i.myIterator;
306  myEnd = i.myEnd;
307  return *this;
308  }
309  bool operator==(const iterator &i) const
310  {
311  return myIterator == i.myIterator;
312  }
313  bool operator!=(const iterator &i) const
314  { return !(*this == i); }
315  iterator &operator++() { advance(); return *this; }
316  bool atEnd() const { return myIterator == myEnd; }
317  void advance() { ++myIterator; }
318  private:
319  iterator(const UT_Options &opts, const MapType::const_iterator &it,
321  : myOptions(&opts)
322  , myIterator(it)
323  , myEnd(end)
324  {
325  }
326  const UT_Options *myOptions;
327  MapType::const_iterator myIterator;
328  MapType::const_iterator myEnd;
329  friend class UT_Options;
330  };
332  {
333  public:
335  : myKeys()
336  , myValues()
337  , myOrder()
338  , myPos(0)
339  , myCurr(0)
340  {
341  }
343  : myKeys(src.myKeys)
344  , myValues(src.myValues)
345  , myOrder(src.myOrder)
346  , myPos(src.myPos)
347  , myCurr(src.myCurr)
348  {
349  }
350  const UT_StringHolder &name() const
351  { return myKeys(myCurr); }
352  const UT_OptionEntry *entry() const
353  { return myValues(myCurr); }
354  UT_OptionType type() const;
355  const UT_OptionEntry *operator*() const { return entry(); }
356 
358  {
359  myKeys = i.myKeys;
360  myValues = i.myValues;
361  myOrder = i.myOrder;
362  myPos = i.myPos;
363  myCurr = i.myCurr;
364  return *this;
365  }
366  bool operator==(const ordered_iterator &i) const
367  {
368  if (i.atEnd() && atEnd())
369  return true;
370  // Iterators are only equal if they are both at
371  // the end.
372  return false;
373  }
374  bool operator!=(const ordered_iterator &i) const
375  { return !(*this == i); }
376  ordered_iterator &operator++() { advance(); return *this; }
377  bool atEnd() const { return myPos >= myOrder.entries(); }
378  void advance()
379  {
380  myPos++;
381  if (myPos < myOrder.entries())
382  myCurr = myOrder(myPos);
383  }
384  private:
385  class comparator
386  {
387  public:
388  comparator(const UT_ValArray<UT_StringHolder> &keys)
389  : myKeys(keys)
390  {
391  }
392  bool operator()(int a, int b) const
393  {
394  UT_ASSERT(a >= 0 && a < myKeys.entries());
395  UT_ASSERT(b >= 0 && b < myKeys.entries());
396  return myKeys(a) < myKeys(b);
397  }
398  private:
399  const UT_ValArray<UT_StringHolder> &myKeys;
400  };
401  // If you get an error here, maybe you meant to call obegin()?
402  explicit ordered_iterator(iterator it)
403  : myKeys()
404  , myValues()
405  , myOrder()
406  , myPos(0)
407  , myCurr(0)
408  {
409  int index = 0;
410  for (; !it.atEnd(); ++it, ++index)
411  {
412  myKeys.append(it.name());
413  myValues.append(it.entry());
414  myOrder.append(index);
415  }
416  myOrder.sort(comparator(myKeys));
417  if (myOrder.entries())
418  myCurr = myOrder(0);
419  }
420 
424  int myPos;
425  int myCurr;
426  friend class UT_Options;
427  };
428  iterator begin() const
429  { return iterator(*this, myMap.begin(), myMap.end()); }
430  iterator end() const
431  { return iterator(*this, myMap.end(), myMap.end()); }
433  { return ordered_iterator(begin()); }
435  { return ordered_iterator(end()); }
436 
437  // Convenience function that calls the appropriate function from below.
438  template <typename T>
439  T getOptionValue(const UT_StringHolder &name) const
440  {
441  using Y = SYS_RemoveCVRef_t<T>;
442  if constexpr (SYS_IsSame_v<Y, UT_StringHolder>)
443  {
444  return getOptionS(name);
445  }
446  else if constexpr (SYS_IsSame_v<Y, int64>)
447  {
448  return getOptionI(name);
449  }
450  else if constexpr (SYS_IsSame_v<Y, UT_StringArray>)
451  {
452  return getOptionSArray(name);
453  }
454  else if constexpr (SYS_IsSame_v<Y, UT_OptionsHolder>)
455  {
456  return getOptionDict(name);
457  }
458  else if constexpr (SYS_IsSame_v<Y, UT_Vector2D>)
459  {
460  return getOptionV2(name);
461  }
462  else
463  {
465  return Y();
466  }
467  }
468 
469  // Functions for accessing specific option values.
470  int64 getOptionI(const UT_StringRef &name) const;
471  bool getOptionB(const UT_StringRef &name) const;
472  fpreal64 getOptionF(const UT_StringRef &name) const;
473  const UT_Vector2D &getOptionV2(const UT_StringRef &name) const;
474  const UT_Vector3D &getOptionV3(const UT_StringRef &name) const;
475  const UT_Vector4D &getOptionV4(const UT_StringRef &name) const;
476  const UT_QuaternionD &getOptionQ(const UT_StringRef &name) const;
477  const UT_Matrix2D &getOptionM2(const UT_StringRef &name) const;
478  const UT_Matrix3D &getOptionM3(const UT_StringRef &name) const;
479  const UT_Matrix4D &getOptionM4(const UT_StringRef &name) const;
480  const UT_Vector2D &getOptionUV(const UT_StringRef &name) const;
481  const UT_Vector3D &getOptionUVW(const UT_StringRef &name) const;
482 
483  // Note that, if the string value contains binary data with null
484  // characters, the UT_String version of getOptionS will not be able to
485  // tell you the length of the data, since UT_String doesn't store the
486  // length.
487  const UT_StringHolder &getOptionS(const UT_StringRef &name) const;
488  void getOptionS(const UT_StringRef &name,
489  std::string &value) const;
490  void getOptionS(const UT_StringRef &name,
491  UT_String &value) const;
492  void getOptionS(const UT_StringRef &name,
493  UT_StringHolder &value) const;
494  void getOptionS(const UT_StringRef &,
495  UT_WorkBuffer &value) const;
496  const UT_OptionsHolder &getOptionDict(const UT_StringRef &name) const;
497 
498  const UT_Int64Array &getOptionIArray(const UT_StringRef &) const;
499  const UT_Fpreal64Array &getOptionFArray(const UT_StringRef &) const;
500  const UT_StringArray &getOptionSArray(const UT_StringRef &) const;
502 
503  // Returns a valid number if this option is a float or an int.
504  // In the case of an int, it is converted to a float.
505  fpreal64 getOptionNum(const UT_StringRef &) const;
506 
507  // Functions for accessing option values. These methods will perform some
508  // minimal "casting".
509  // importOption(... bool &value) - Tests integers and string options
510  // importOption(... fpreal &value) - Evaluates integer/bool options
511  // importOption(... UT_Vector2 &) - Evaluates Vector2 or UV
512  // importOption(... UT_Vector3 &) - Evaluates Vector3 or UVW
513  //
514  bool importOption(const UT_StringRef &name, int &value) const;
515  bool importOption(const UT_StringRef &name, int64 &value) const;
516  bool importOption(const UT_StringRef &name, bool &value) const;
517  bool importOption(const UT_StringRef &name,
518  fpreal32 &value) const;
519  bool importOption(const UT_StringRef &name,
520  fpreal64 &value) const;
521  bool importOption(const UT_StringRef &name,
522  std::string &value) const;
523  bool importOption(const UT_StringRef &name,
524  UT_String &value) const;
525  bool importOption(const UT_StringRef &name,
526  UT_StringHolder &value) const;
527  bool importOption(const UT_StringRef &name,
528  UT_OptionsHolder &value) const;
529  bool importOption(const UT_StringRef &name,
530  UT_Vector2F &value) const;
531  bool importOption(const UT_StringRef &name,
532  UT_Vector3F &value) const;
533  bool importOption(const UT_StringRef &name,
534  UT_Vector4F &value) const;
535  bool importOption(const UT_StringRef &name,
536  UT_QuaternionF &value) const;
537  bool importOption(const UT_StringRef &name,
538  UT_Matrix2F &value) const;
539  bool importOption(const UT_StringRef &name,
540  UT_Matrix3F &value) const;
541  bool importOption(const UT_StringRef &name,
542  UT_Matrix4F &value) const;
543  bool importOption(const UT_StringRef &name,
544  UT_Vector2D &value) const;
545  bool importOption(const UT_StringRef &name,
546  UT_Vector3D &value) const;
547  bool importOption(const UT_StringRef &name,
548  UT_Vector4D &value) const;
549  bool importOption(const UT_StringRef &name,
550  UT_QuaternionD &value) const;
551  bool importOption(const UT_StringRef &name,
552  UT_Matrix2D &value) const;
553  bool importOption(const UT_StringRef &name,
554  UT_Matrix3D &value) const;
555  bool importOption(const UT_StringRef &name,
556  UT_Matrix4D &value) const;
557 
558  // Generic import which handles arbitrary length int/float data
559  bool importOption(const UT_StringRef &name,
560  UT_Array<int32> &value) const;
561  bool importOption(const UT_StringRef &name,
562  UT_Array<int64> &value) const;
563  bool importOption(const UT_StringRef &name,
564  UT_Array<fpreal32> &value) const;
565  bool importOption(const UT_StringRef &name,
566  UT_Array<fpreal64> &value) const;
567 
568  // Import a string array
569  bool importOption(const UT_StringRef &name,
570  UT_StringArray &value) const;
571  bool importOption(const UT_StringRef &name,
572  UT_Array<UT_StringHolder> &value) const;
573 
574  // Import a dictionary array.
575  bool importOption(const UT_StringRef &name,
576  UT_Array<UT_OptionsHolder> &value) const;
577 
578  // Import a single element from a scalar, vector, matrix or array
579  bool importElement(const UT_StringRef &name,
580  fpreal &value,
581  exint index = 0) const;
582  bool importElement(const UT_StringRef &name,
583  int64 &value,
584  exint index = 0) const;
585 
586 
587  // Convenience function that calls the appropriate function from below.
588  template <typename T>
589  UT_Options &setOptionValue(const UT_StringHolder &name, const T &value)
590  {
591  if constexpr (SYS_IsSame_v<T, UT_StringHolder>)
592  {
593  return setOptionS(name, value);
594  }
595  else if constexpr (SYS_IsSame_v<T, int64>)
596  {
597  return setOptionI(name, value);
598  }
599  else if constexpr (SYS_IsSame_v<T, UT_StringArray>)
600  {
601  return setOptionSArray(name, value);
602  }
603  else if constexpr (SYS_IsSame_v<T, UT_OptionsHolder>)
604  {
605  return setOptionDict(name, value);
606  }
607  else if constexpr (SYS_IsSame_v<T, UT_Vector2D>)
608  {
609  return setOptionV2(name, value);
610  }
611  else
612  {
614  return *this;
615  }
616  }
617  // All these functions cause optionChanged to be called.
619  int64 value);
621  bool value);
623  fpreal64 value);
624  // Note that you can store binary data (that can contain null characters
625  // or that isn't null-terminated) in a string option by passing in a
626  // UT_WorkBuffer, or std::string.
628  const UT_StringHolder &value);
629  // setOptionSRaw() is the same as setOptionS() instead of it being
630  // additionally tagged as a "raw" string so that getPyOptionString() and
631  // appendPyDictionary() won't add quotes around the value. To retrieve its
632  // value, use getOptionS().
634  const UT_StringHolder &value);
636  const UT_OptionsHolder &value);
638  const UT_Vector2F &value);
640  const UT_Vector2D &value);
642  fpreal64 x, fpreal64 y);
644  const UT_Vector3F &value);
646  const UT_Vector3D &value);
650  const UT_Vector4F &value);
652  const UT_Vector4D &value);
654  fpreal64 x, fpreal64 y,
655  fpreal64 z, fpreal64 w);
657  const UT_QuaternionF &value);
659  const UT_QuaternionD &value);
661  const UT_Matrix2F &value);
663  const UT_Matrix2D &value);
665  const UT_Matrix3F &value);
667  const UT_Matrix3D &value);
669  const UT_Matrix4F &value);
671  const UT_Matrix4D &value);
673  const UT_Vector2F &value);
675  const UT_Vector2D &value);
677  const UT_Vector3F &value);
679  const UT_Vector3D &value);
680  /// @{
681  /// Set integer array options
683  const int32 *values, size_t size);
685  const int64 *values, size_t size);
687  const UT_Array<int64> &value);
688  /// @}
689  /// @{
690  /// Set float/double array options
692  const fpreal32 *values, size_t size);
694  const fpreal64 *values, size_t size);
696  const UT_Array<fpreal64> &value);
697  /// @}
698 
699  /// Set string array options
701  const UT_StringHolder *values,
702  size_t size);
704  const char *const*values,
705  size_t size);
707  const UT_StringArray &value);
708 
709  /// Set dict array options
711  const UT_OptionsHolder *values,
712  size_t size);
714  const UT_Array<UT_OptionsHolder> &value);
715 
716  /// Get a hash code for the options
717  unsigned hash() const;
718 
719  /// Comparison operator
720  bool operator==(const UT_Options &src) const
721  { return isEqual(src, 0.0); }
722  bool operator!=(const UT_Options &src) const
723  { return !(*this == src); }
724 
725  /// Comparison operator with a tolerance for float values.
726  bool isEqual(const UT_Options &src, fpreal64 tol) const;
727 
728  /// Assignment operator
729  const UT_Options &operator=(const UT_Options &src);
730  void merge(const UT_Options &src);
731  void merge(const UT_Options &src,
732  bool (*match)(const UT_StringHolder &name,
733  const UT_OptionEntry *, void *),
734  void *data);
735  virtual int64 getMemoryUsage(bool inclusive) const;
736 
737  // This will steal the option from the unique ptr.
738  void setOption(const UT_StringHolder &name,
739  UT_OptionEntryPtr value);
740 
741 protected:
742  const UT_StringHolder *findOptionS(const UT_StringRef &name) const;
743  void addError(const char *filename, int linecount,
744  const char *error_str) const;
745  bool sendOptionChanges() const
746  { return mySendOptionChanges; }
748  { mySendOptionChanges = f; }
749  virtual void optionChanged(const char *name);
750  UT_OptionEntryPtr parsePyValue(const char *&value,
751  char sep_delim,
752  char close_delim = '\0');
753 
754 private:
755  template <class ITER>
756  bool save(ITER start, const char *filename, std::ostream &os) const;
757 
758  MapType myMap;
759  bool mySendOptionChanges;
760 };
761 
762 /// A holder for a options, which caches the hash value.
763 /// A UT_OptionsRef does not necessarily own the options, and it is therefore
764 /// not safe to e.g. store a UT_OptionsRef in a container or member variable.
765 /// @see UT_OptionsHolder
767 {
768 public:
770 
773  {
774  init();
775  }
776 
777  /// Will make a shallow reference.
780  {
781  init();
782  reference(opt);
783  }
784 
785  /// Shares a reference with the source.
788  {
789  mySoftRef = s.mySoftRef;
790  mySharedRef = s.mySharedRef;
791  myHash = s.myHash;
792  }
793 
794  /// Move constructor. Steals the working data from the original.
797  {
798  mySoftRef = s.mySoftRef;
799  mySharedRef = std::move(s.mySharedRef);
800  myHash = s.myHash;
801  s.init();
802  }
803 
806  {
807  }
808 
809  /// Special sentinel value support
810  /// @{
811  enum UT_OptionsSentinelType { SENTINEL };
812 
813  SYS_FORCE_INLINE explicit
815  : mySoftRef((const UT_Options *)SENTINEL_DATA)
816  , myHash(SENTINEL_HASH)
817  {
818  }
819 
821  bool isSentinel() const
822  {
823  return uintptr_t(mySoftRef) == SENTINEL_DATA && myHash == SENTINEL_HASH;
824  }
825 
828  {
829  init();
830  myHash = SENTINEL_HASH;
831  mySoftRef = (const UT_Options *) SENTINEL_DATA;
832  }
833  /// @}
834 
835  /// Returns true this object is the sole owner of the underlying options
836  bool isUnique() const
837  {
838  // Soft references are not unique. (This includes sentinels)
839  if (mySoftRef)
840  return false;
841  // If the shared ref is null, it isn't unique.
842  if (!mySharedRef.get())
843  return false;
844 
845  return mySharedRef.unique();
846  }
847 
848  /// Returns the shared ptr use count. 0 if not a shared
849  /// pointer. (null or soft ref)
850  int use_count() const
851  {
852  if (mySoftRef)
853  return 0;
854  if (!mySharedRef.get())
855  return 0;
856  return mySharedRef.use_count();
857  }
858 
859  /// Shares a reference with the source.
861  {
862  // Can now blindly copy.
863  mySoftRef = s.mySoftRef;
864  mySharedRef = s.mySharedRef;
865  myHash = s.myHash;
866  return *this;
867  }
868 
869  /// Move the contents of about-to-be-destructed options
870  /// s to this string.
873  {
874  // Can just swap, since s is about to be destructed.
875  swap(s);
876  return *this;
877  }
878 
880  const UT_Options *optionsOrNull() const
881  {
882  if (isSentinel())
883  return nullptr;
884  return rawOptions();
885  }
886 
888  const UT_Options *options() const
889  {
890  const UT_Options *result = optionsOrNull();
891  if (result == nullptr)
892  return &theEmptyOptionsData;
893  return result;
894  }
895 
896  bool operator==(const UT_OptionsRef &s) const
897  {
898  const UT_Options *a = rawOptions();
899  const UT_Options *b = s.rawOptions();
900 
901  if (a == b)
902  return true;
903 
904  // If they are not equal, we have to test null and sentinel.
905  // If either one is null or sentinel, we know they must be
906  // unequal.
907  if (!a || !b || (uintptr_t(a) == SENTINEL_DATA) || (uintptr_t(b) == SENTINEL_DATA))
908  return false;
909 
910  // If we have hashes and they are unequal, we must
911  // be unequal.
912  if (myHash && s.myHash)
913  {
914  if (myHash != s.myHash)
915  return false;
916  }
917 
918  // Now we have de-referenceable options pointers.
919  return (*a == *b);
920  }
921 
922  bool operator==(const UT_Options *b) const
923  {
924  const UT_Options *a = rawOptions();
925 
926  if (a == b)
927  return true;
928 
929  // If they are not equal, we have to test null and sentinel.
930  // If either one is null or sentinel, we know they must be
931  // unequal.
932  if (!a || !b || (uintptr_t(a) == SENTINEL_DATA) || (uintptr_t(b) == SENTINEL_DATA))
933  return false;
934 
935  // Can't test hashes as we don't have it for a raw pointer.
936 
937  // Now we have de-referenceable options pointers.
938  return (*a == *b);
939  }
940 
941  bool operator!=(const UT_OptionsRef &s) const
942  { return !operator==(s); }
943  bool operator!=(const UT_Options *s) const
944  { return !operator==(s); }
945 
946  /// Comparison operator with a tolerance for float values.
947  bool isEqual(const UT_OptionsRef &s, fpreal64 tol) const;
948 
949  SYS_FORCE_INLINE const UT_Options *operator->() const { return options(); }
950  SYS_FORCE_INLINE const UT_Options &operator*() const { return *options(); }
951 
953  void swap( UT_OptionsRef &other )
954  {
955  UTswap(mySoftRef, other.mySoftRef);
956  UTswap(mySharedRef, other.mySharedRef);
957  UTswap(myHash, other.myHash);
958  }
959 
960  /// Friend specialization of std::swap() to use UT_OptionsRef::swap()
961  friend void swap(UT_OptionsRef& a, UT_OptionsRef& b) { a.swap(b); }
962 
964  void clear()
965  {
966  init();
967  }
968 
969  bool isEmpty() const
970  {
971  const UT_Options *opt = optionsOrNull();
972  if (!opt)
973  return true;
974 
975  if (opt->getNumOptions() == 0)
976  return true;
977 
978  return false;
979  }
980 
981  explicit operator bool() const { return !isEmpty(); }
982 
983  unsigned hash() const
984  {
985  if (myHash)
986  return myHash;
987 
988  const UT_Options *opt = optionsOrNull();
989  if (!opt)
990  return 0;
991 
992  unsigned localhash = opt->hash();
993  if (!localhash)
994  localhash++;
995  myHash = localhash;
996  return myHash;
997  }
998 
999  /// Make a light weight reference to the source.
1000  /// Caller must make sure src lives for the duration of this object,
1001  /// and any objects value copied from this!
1002  void reference(const UT_Options *src)
1003  {
1004  init();
1005  mySoftRef = src;
1006  }
1007 
1008  int64 getMemoryUsage(bool inclusive) const
1009  {
1010  int64 mem = inclusive ? sizeof(*this) : 0;
1011 
1012  const UT_Options *opt = optionsOrNull();
1013  if (opt)
1014  mem += opt->getMemoryUsage(true);
1015  return mem;
1016  }
1017 
1018  static const UT_Options &emptyOptions() { return theEmptyOptionsData; }
1019 
1020 private:
1021  void init()
1022  {
1023  mySoftRef = nullptr;
1024  mySharedRef.reset();
1025  myHash = 0;
1026  }
1027 
1028  void copy(const UT_OptionsRef &s)
1029  {
1030  mySoftRef = s.mySoftRef;
1031  mySharedRef = s.mySharedRef;
1032  myHash = s.myHash;
1033  }
1034 
1036  const UT_Options *rawOptions() const
1037  {
1038  if (mySoftRef)
1039  return mySoftRef;
1040  return mySharedRef.get();
1041  }
1042 
1043 
1044  /// Either softref or shared ref should be set, never both.
1045  /// Note that this might be possible to collapse into a single
1046  /// shared ptr using the semantic that use_count==0 means soft ref.
1047  const UT_Options *mySoftRef;
1048  UT_SharedPtr<UT_Options> mySharedRef;
1049 
1050  /// Optional hash, 0 if not computed yet.
1051  mutable int myHash;
1052 
1053  // UT_OptionsHolder needs to be a friend class so that the
1054  // UT_OptionsHolder(const UT_OptionsRef &) constructor can access myHash and
1055  // getHolder() for the UT_OptionsRef that is passed in.
1056  friend class UT_OptionsHolder;
1057 
1058  static constexpr uintptr_t SENTINEL_DATA = 1;
1059  static constexpr uint32 SENTINEL_HASH = 0xdeadbeef;
1060 
1061  // Because we want a null options pointer to return an empty options,
1062  // we need a canonical empty options to return.
1063  static const UT_Options theEmptyOptionsData;
1064 
1065  template<typename T>
1066  static SYS_FORCE_INLINE bool isSentinelOrNullPtr(const T *p)
1067  {
1068  return uintptr_t(p) <= SENTINEL_DATA;
1069  }
1070 };
1071 
1073 {
1074  return opt.hash();
1075 }
1076 
1077 
1079 {
1080 public:
1081  /// UT_OptionsHolder can be constructed with UT_OptionsHolder::REFERENCE to
1082  /// create a shallow reference to the const char *.
1083  enum UT_OptionsReferenceType { REFERENCE };
1084 
1087  : UT_OptionsRef()
1088  {
1089  }
1090 
1091  /// Will make a copy of the provided options.
1094  {
1095  mySoftRef = nullptr;
1096  if (opt)
1097  mySharedRef = UTmakeShared<UT_Options>(*opt);
1098  else
1099  mySharedRef.reset();
1100  }
1101 
1104  {
1105  mySoftRef = nullptr;
1106  mySharedRef = std::move(opts);
1107  }
1108 
1109  /// Will make a shallow reference.
1112  : UT_OptionsRef(opt)
1113  {
1114  }
1115 
1116  /// Makes a shallow reference to the contents of the UT_OptionsRef.
1119  : UT_OptionsRef(ref)
1120  {
1121  }
1122 
1123  /// Makes a deep copy of the provided UT_OptionsRef.
1124  /// This constructor is not marked explicit since we often want this
1125  /// conversion (e.g. when inserting a UT_OptionsRef into a UT_OptionsMap, as
1126  /// with the const char* constructor).
1128 
1129  /// Construct as a sentinel value
1130  SYS_FORCE_INLINE explicit
1132  : UT_OptionsRef(sentinel)
1133  {
1134  }
1135 
1136  /// Makes a copy of the provided options.
1139  : UT_OptionsRef(str)
1140  {
1141  }
1142 
1143  /// Move constructor. Steals the working data from the original.
1146  : UT_OptionsRef(std::move(a))
1147  {
1148  }
1149 
1150  /// Makes a bit-wise copy of the options and adjust the reference count.
1153  {
1155  return *this;
1156  }
1157 
1158  /// Move the contents of about-to-be-destructed options
1159  /// s to this options.
1162  {
1163  UT_OptionsRef::operator=(std::move(s));
1164  return *this;
1165  }
1166 
1168  void swap(UT_OptionsHolder &other)
1169  {
1170  UT_OptionsRef::swap(other);
1171  }
1172 
1174  void swap(UT_OptionsRef &other)
1175  {
1176  UT_OptionsRef::swap(other);
1177  // harden ourselves like UT_OptionsHolder::operator=(UT_OptionsRef&)
1178  if (isSentinelOrNullPtr(mySoftRef))
1179  return; // already a holder
1180  mySharedRef = UTmakeShared<UT_Options>(*mySoftRef);
1181  mySoftRef = nullptr;
1182  }
1183 
1184  /// Returns a writeable UT_Options which will modify the contents
1185  /// of this options holder. When this is copied or deleted, the
1186  /// returned pointer must not be used any more. (Ideally we could
1187  /// erase ourself and return a UniquePtr for correct life time,
1188  /// but we can't steal from a shared pointer)
1189  ///
1190  /// Use update() whereever possible instead as it is much safer.
1192  {
1193  // Harden if soft.
1194  if (!isUnique())
1195  {
1196  mySharedRef = UTmakeShared<UT_Options>(*options());
1197  mySoftRef = nullptr;
1198  }
1199  UT_ASSERT(isUnique());
1200 
1201  // Since we are going to be edited, we must reset our hash.
1202  myHash = 0;
1203 
1204  return SYSconst_cast(options());
1205  }
1206 
1207  /// Updates the contents of this option, first making sure it is
1208  /// unique. The provided operator should take a reference to
1209  /// a UT_Options that it will update.
1210  /// UT_OptionsHolder value;
1211  /// value.update([](UT_Options &opt) { opt.setOptionS("test", "bar"); });
1212  template <typename OP>
1213  void update(const OP &op)
1214  {
1215  UT_Options *opt = makeUnique();
1216  op(*opt);
1217  }
1218 
1219  /// Friend specialization of std::swap() to use UT_OptionsHolder::swap()
1220  /// @{
1221  friend void swap(UT_OptionsHolder& a, UT_OptionsRef& b) { a.swap(b); }
1222  friend void swap(UT_OptionsHolder& a, UT_OptionsHolder& b) { a.swap(b); }
1223  /// @}
1224 
1225  /// In some functions it's nice to be able to return a const-reference to a
1226  /// UT_OptionsHolder. However, in error cases, you likely want to return an
1227  /// empty options. This would mean that you'd have to return a real
1228  /// UT_OptionsHolder (not a const reference). This static lets you return a
1229  /// reference to an empty options.
1231 
1233 
1234 protected:
1235 };
1236 
1237 SYS_FORCE_INLINE size_t
1239 {
1240  return opt.hash();
1241 }
1242 
1243 // For UT::ArraySet.
1244 namespace UT
1245 {
1246 template <typename T>
1247 struct DefaultClearer;
1248 
1249 template <>
1251 {
1252  static void clear(UT_OptionsHolder &v) { v.makeSentinel(); }
1253  static bool isClear(const UT_OptionsHolder &v) { return v.isSentinel(); }
1255  { new ((void *)p) UT_OptionsHolder(UT_OptionsRef::SENTINEL); }
1256  static const bool clearNeedsDestruction = false;
1257 };
1258 } // namespace UT
1259 
1260 UT_API size_t format(char *buffer, size_t buffer_size, const UT_Options &v);
1261 UT_API size_t format(char *buffer, size_t buffer_size, const UT_OptionsRef &v);
1262 
1263 // Most people only include UT_Options. But we can't include this at the start
1264 // as we are a pre-req.
1265 #include "UT_OptionEntry.h"
1266 
1267 #endif
SYS_FORCE_INLINE UT_OptionsHolder(UT_UniquePtr< UT_Options > opts)
Definition: UT_Options.h:1103
type
Definition: core.h:556
bool operator==(const UT_OptionsRef &s) const
Definition: UT_Options.h:896
bool getOptionB(const UT_StringRef &name) const
SYS_FORCE_INLINE UT_OptionsRef()
Definition: UT_Options.h:772
SYS_FORCE_INLINE bool isSentinel() const
Definition: UT_Options.h:821
GT_API const UT_StringHolder filename
const UT_Vector2D & getOptionV2(const UT_StringRef &name) const
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
int int32
Definition: SYS_Types.h:39
const UT_StringHolder & name() const
Definition: UT_Options.h:350
const UT_OptionEntry * operator*() const
Definition: UT_Options.h:300
int64 getMemoryUsage(bool inclusive) const
Definition: UT_Options.h:1008
friend void swap(UT_OptionsRef &a, UT_OptionsRef &b)
Friend specialization of std::swap() to use UT_OptionsRef::swap()
Definition: UT_Options.h:961
SYS_FORCE_INLINE void swap(UT_OptionsRef &other)
Definition: UT_Options.h:953
bool isEqual(const UT_Options &src, fpreal64 tol) const
Comparison operator with a tolerance for float values.
void UTswap(T &a, T &b)
Definition: UT_Swap.h:35
const UT_StringArray & getOptionSArray(const UT_StringRef &) const
int myOrder
Definition: GT_CurveEval.h:263
SYS_FORCE_INLINE UT_OptionsHolder(UT_OptionsHolder &&a) noexcept
Move constructor. Steals the working data from the original.
Definition: UT_Options.h:1145
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
SYS_FORCE_INLINE const UT_Options & operator*() const
Definition: UT_Options.h:950
const GLdouble * v
Definition: glcorearb.h:837
uint128_t uintptr_t
Definition: format.h:479
GLuint start
Definition: glcorearb.h:475
GLsizei const GLfloat * value
Definition: glcorearb.h:824
bool isEmpty() const
Definition: UT_Options.h:969
UT_Options & setOptionDictArray(const UT_StringHolder &name, const UT_OptionsHolder *values, size_t size)
Set dict array options.
SYS_FORCE_INLINE size_t hash_value(const UT_OptionsRef &opt)
Definition: UT_Options.h:1072
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
Definition: SYS_Types.h:136
UT_OptionType
Definition: UT_Options.h:44
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
static const UT_OptionsHolder theSentinel
Definition: UT_Options.h:1232
void addError(const char *filename, int linecount, const char *error_str) const
UT_Options & setOptionUVW(const UT_StringHolder &name, const UT_Vector3F &value)
int64 exint
Definition: SYS_Types.h:125
bool operator!=(const UT_Options &src) const
Definition: UT_Options.h:722
UT_Options & setOptionV3(const UT_StringHolder &name, const UT_Vector3F &value)
exint size() const
Definition: UT_Options.h:280
int64 getOptionI(const UT_StringRef &name) const
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLdouble s
Definition: glad.h:3009
void swap(T &lhs, T &rhs)
Definition: pugixml.cpp:7440
void setOption(const UT_StringHolder &name, UT_OptionEntryPtr value)
UT_OptionEntryPtr parsePyValue(const char *&value, char sep_delim, char close_delim= '\0')
const UT_Vector3D & getOptionV3(const UT_StringRef &name) const
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
ordered_iterator oend() const
Definition: UT_Options.h:434
#define UT_API
Definition: UT_API.h:14
GLint y
Definition: glcorearb.h:103
SYS_FORCE_INLINE UT_OptionsHolder(UT_OptionsReferenceType, const UT_Options *opt)
Will make a shallow reference.
Definition: UT_Options.h:1111
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
SYS_FORCE_INLINE UT_OptionsHolder()
Definition: UT_Options.h:1086
const UT_Matrix3D & getOptionM3(const UT_StringRef &name) const
**But if you need a result
Definition: thread.h:622
SYS_FORCE_INLINE UT_OptionsHolder & operator=(const UT_OptionsHolder &s)
Makes a bit-wise copy of the options and adjust the reference count.
Definition: UT_Options.h:1152
typename SYS_RemoveCVRef< T >::type SYS_RemoveCVRef_t
const UT_Fpreal64Array & getOptionFArray(const UT_StringRef &) const
static const UT_Options & emptyOptions()
Definition: UT_Options.h:1018
float fpreal32
Definition: SYS_Types.h:200
bool atEnd() const
Definition: UT_Options.h:316
GLuint buffer
Definition: glcorearb.h:660
bool operator==(const UT_Options &src) const
Comparison operator.
Definition: UT_Options.h:720
UT_OptionsRef & operator=(const UT_OptionsRef &s)
Shares a reference with the source.
Definition: UT_Options.h:860
exint entries() const
Definition: UT_Options.h:281
OutGridT const XformOp bool bool
UT_Options & setOptionM4(const UT_StringHolder &name, const UT_Matrix4F &value)
void setSendOptionChanges(bool f)
Definition: UT_Options.h:747
void reference(const UT_Options *src)
Definition: UT_Options.h:1002
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
UT_Options & setOptionIArray(const UT_StringHolder &name, const int32 *values, size_t size)
SYS_FORCE_INLINE UT_OptionsHolder(UT_OptionsSentinelType sentinel)
Construct as a sentinel value.
Definition: UT_Options.h:1131
ordered_iterator & operator=(const ordered_iterator &i)
Definition: UT_Options.h:357
iterator end() const
Definition: UT_Options.h:430
double fpreal64
Definition: SYS_Types.h:201
const UT_StringHolder * findOptionS(const UT_StringRef &name) const
ordered_iterator(const ordered_iterator &src)
Definition: UT_Options.h:342
SYS_FORCE_INLINE const UT_Options * optionsOrNull() const
Definition: UT_Options.h:880
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
T getOptionValue(const UT_StringHolder &name) const
Definition: UT_Options.h:439
SYS_FORCE_INLINE UT_OptionsRef(UT_OptionsRef &&s) noexcept
Move constructor. Steals the working data from the original.
Definition: UT_Options.h:796
UT_Options & setOptionSArray(const UT_StringHolder &name, const UT_StringHolder *values, size_t size)
Set string array options.
UT_Options & setOptionValue(const UT_StringHolder &name, const T &value)
Definition: UT_Options.h:589
GLfloat f
Definition: glcorearb.h:1926
UT_Options & setOptionI(const UT_StringHolder &name, int64 value)
fpreal64 getOptionNum(const UT_StringRef &) const
SYS_FORCE_INLINE void clear()
Definition: UT_Options.h:964
UT_Options & setOptionUV(const UT_StringHolder &name, const UT_Vector2F &value)
GLint ref
Definition: glcorearb.h:124
void update(const OP &op)
Definition: UT_Options.h:1213
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
UT_Options value_type
Definition: UT_Options.h:769
SYS_FORCE_INLINE void swap(UT_OptionsRef &other)
Definition: UT_Options.h:1174
unsigned hash() const
Get a hash code for the options.
UT_Options & setOptionQ(const UT_StringHolder &name, const UT_QuaternionF &value)
GLuint GLuint end
Definition: glcorearb.h:475
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
const UT_OptionEntry * operator*() const
Definition: UT_Options.h:355
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
ordered_iterator obegin() const
Definition: UT_Options.h:432
static const UT_OptionsHolder theEmptyOptions
Definition: UT_Options.h:1230
friend void swap(UT_OptionsHolder &a, UT_OptionsRef &b)
Definition: UT_Options.h:1221
SYS_FORCE_INLINE UT_OptionsRef(UT_OptionsSentinelType)
Definition: UT_Options.h:814
const UT_Vector3D & getOptionUVW(const UT_StringRef &name) const
const UT_Array< UT_OptionsHolder > & getOptionDictArray(const UT_StringRef &) const
UT_Options & setOptionV4(const UT_StringHolder &name, const UT_Vector4F &value)
UT_Options & setOptionB(const UT_StringHolder &name, bool value)
const UT_StringHolder & name() const
Definition: UT_Options.h:295
UT_Options & setOptionM3(const UT_StringHolder &name, const UT_Matrix3F &value)
virtual void optionChanged(const char *name)
long long int64
Definition: SYS_Types.h:116
SYS_FORCE_INLINE UT_OptionsRef(const UT_OptionsRef &s)
Shares a reference with the source.
Definition: UT_Options.h:787
const UT_Matrix2D & getOptionM2(const UT_StringRef &name) const
iterator & operator++()
Definition: UT_Options.h:315
UT_Options & setOptionM2(const UT_StringHolder &name, const UT_Matrix2F &value)
iterator(const iterator &i)
Definition: UT_Options.h:290
const UT_QuaternionD & getOptionQ(const UT_StringRef &name) const
GLuint const GLchar * name
Definition: glcorearb.h:786
bool operator!=(const UT_Options *s) const
Definition: UT_Options.h:943
bool operator!=(const iterator &i) const
Definition: UT_Options.h:313
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
bool operator==(const UT_Options *b) const
Definition: UT_Options.h:922
const UT_Int64Array & getOptionIArray(const UT_StringRef &) const
virtual int64 getMemoryUsage(bool inclusive) const
static bool isClear(const UT_OptionsHolder &v)
Definition: UT_Options.h:1253
SYS_FORCE_INLINE ~UT_OptionsRef()
Definition: UT_Options.h:805
bool isUnique() const
Returns true this object is the sole owner of the underlying options.
Definition: UT_Options.h:836
bool save(const char *filename) const
friend class UT_OptionsHolder
Definition: UT_Options.h:1056
iterator begin() const
Definition: UT_Options.h:428
static void clear(UT_OptionsHolder &v)
Definition: UT_Options.h:1252
SYS_FORCE_INLINE UT_OptionsHolder(UT_OptionsReferenceType, const UT_OptionsRef &ref)
Makes a shallow reference to the contents of the UT_OptionsRef.
Definition: UT_Options.h:1118
GLsizeiptr size
Definition: glcorearb.h:664
A map of string to various well defined value types.
Definition: UT_Options.h:84
UT_Options * makeUnique()
Definition: UT_Options.h:1191
SYS_FORCE_INLINE UT_OptionsRef & operator=(UT_OptionsRef &&s)
Definition: UT_Options.h:872
SYS_FORCE_INLINE UT_OptionsHolder & operator=(UT_OptionsHolder &&s)
Definition: UT_Options.h:1161
exint getNumOptions() const
Definition: UT_Options.h:279
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
SYS_FORCE_INLINE void makeSentinel()
Definition: UT_Options.h:827
const UT_Vector4D & getOptionV4(const UT_StringRef &name) const
bool operator!=(const ordered_iterator &i) const
Definition: UT_Options.h:374
SYS_FORCE_INLINE const UT_Options * options() const
Definition: UT_Options.h:888
ordered_iterator & operator++()
Definition: UT_Options.h:376
bool operator!=(const UT_OptionsRef &s) const
Definition: UT_Options.h:941
fpreal64 fpreal
Definition: SYS_Types.h:278
SYS_FORCE_INLINE UT_OptionsHolder(const UT_OptionsHolder &str)
Makes a copy of the provided options.
Definition: UT_Options.h:1138
LeafData & operator=(const LeafData &)=delete
iterator & operator=(const iterator &i)
Definition: UT_Options.h:302
SYS_FORCE_INLINE UT_OptionsHolder(const UT_Options *opt)
Will make a copy of the provided options.
Definition: UT_Options.h:1093
GLuint index
Definition: glcorearb.h:786
UT_Options & setOptionS(const UT_StringHolder &name, const UT_StringHolder &value)
const UT_Vector2D & getOptionUV(const UT_StringRef &name) const
bool importElement(const UT_StringRef &name, fpreal &value, exint index=0) const
const UT_Matrix4D & getOptionM4(const UT_StringRef &name) const
UT_API size_t format(char *buffer, size_t buffer_size, const UT_Options &v)
#define SYS_UNIMPLEMENTED_TEMPLATE(T)
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
friend void swap(UT_OptionsHolder &a, UT_OptionsHolder &b)
Definition: UT_Options.h:1222
unsigned int uint32
Definition: SYS_Types.h:40
bool sendOptionChanges() const
Definition: UT_Options.h:745
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
unsigned hash() const
Definition: UT_Options.h:983
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
const UT_OptionEntry * entry() const
Definition: UT_Options.h:352
int use_count() const
Definition: UT_Options.h:850
OutGridT XformOp bool bool MergePolicy merge
UT_OptionFormat
String formatting options for getOptionString.
Definition: UT_Options.h:71
const UT_OptionEntry * entry() const
Definition: UT_Options.h:297
UT_Options & setOptionDict(const UT_StringHolder &name, const UT_OptionsHolder &value)
UT_Options & setOptionSRaw(const UT_StringHolder &name, const UT_StringHolder &value)
SYS_FORCE_INLINE UT_OptionsRef(const UT_Options *opt)
Will make a shallow reference.
Definition: UT_Options.h:779
UT_Options & setOptionFArray(const UT_StringHolder &name, const fpreal32 *values, size_t size)
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate and *a name There is also one special expression reference
SYS_FORCE_INLINE void swap(UT_OptionsHolder &other)
Definition: UT_Options.h:1168
bool operator==(const iterator &i) const
Definition: UT_Options.h:309
bool operator==(const ordered_iterator &i) const
Definition: UT_Options.h:366
UT_Options & setOptionF(const UT_StringHolder &name, fpreal64 value)
bool importOption(const UT_StringRef &name, int &value) const
fpreal64 getOptionF(const UT_StringRef &name) const
UT_UniquePtr< UT_OptionEntry > UT_OptionEntryPtr
Definition: format.h:1821
const UT_OptionsHolder & getOptionDict(const UT_StringRef &name) const
UT_Options & setOptionV2(const UT_StringHolder &name, const UT_Vector2F &value)
SYS_FORCE_INLINE const UT_Options * operator->() const
Definition: UT_Options.h:949
GLenum src
Definition: glcorearb.h:1793
static void clearConstruct(UT_OptionsHolder *p)
Definition: UT_Options.h:1254
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.
Definition: node.h:566
const UT_StringHolder & getOptionS(const UT_StringRef &name) const