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