16 #ifndef _UT_OPTIONS_H_
17 #define _UT_OPTIONS_H_
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;
195 bool saveAsJSON(
const char *filename,
197 bool compact =
false)
const;
198 bool saveAsJSON(
const char *filename, std::ostream &os,
200 bool compact =
false)
const;
218 bool sorted=
false)
const;
222 bool setFromPyDictionary(
const char *dict);
251 bool require_type =
true);
262 bool allow_type =
true,
263 bool allow_dict =
false);
266 void dump(std::ostream &os)
const;
287 : myOptions(i.myOptions)
288 , myIterator(i.myIterator)
292 {
return myIterator->first; }
294 {
return myIterator->second.get(); }
300 myOptions = i.myOptions;
301 myIterator = i.myIterator;
307 return myIterator == i.myIterator;
310 {
return !(*
this == i); }
312 bool atEnd()
const {
return myIterator == myEnd; }
323 MapType::const_iterator myIterator;
324 MapType::const_iterator myEnd;
340 , myValues(src.myValues)
347 {
return myKeys(myCurr); }
349 {
return myValues(myCurr); }
356 myValues = i.myValues;
364 if (i.
atEnd() && atEnd())
371 {
return !(*
this == i); }
388 bool operator()(
int a,
int b)
const
390 UT_ASSERT(a >= 0 && a < myKeys.entries());
391 UT_ASSERT(b >= 0 && b < myKeys.entries());
392 return myKeys(a) < myKeys(b);
398 explicit ordered_iterator(iterator it)
406 for (; !it.atEnd(); ++it, ++
index)
408 myKeys.append(it.name());
409 myValues.append(it.entry());
412 myOrder.sort(comparator(myKeys));
425 {
return iterator(*
this, myMap.begin(), myMap.end()); }
427 {
return iterator(*
this, myMap.end(), myMap.end()); }
545 exint index = 0)
const;
548 exint index = 0)
const;
651 unsigned hash()
const;
657 {
return !(*
this ==
src); }
677 void addError(
const char *filename,
int linecount,
678 const char *error_str)
const;
680 {
return mySendOptionChanges; }
682 { mySendOptionChanges =
f; }
686 char close_delim =
'\0');
689 template <
class ITER>
690 bool save(ITER
start,
const char *filename, std::ostream &os)
const;
693 bool mySendOptionChanges;
723 mySoftRef = s.mySoftRef;
724 mySharedRef = s.mySharedRef;
732 mySoftRef =
s.mySoftRef;
733 mySharedRef = std::move(
s.mySharedRef);
750 , myHash(SENTINEL_HASH)
757 return uintptr_t(mySoftRef) == SENTINEL_DATA && myHash == SENTINEL_HASH;
764 myHash = SENTINEL_HASH;
765 mySoftRef = (
const UT_Options *) SENTINEL_DATA;
776 if (!mySharedRef.get())
779 return mySharedRef.unique();
788 if (!mySharedRef.get())
790 return mySharedRef.use_count();
797 mySoftRef = s.mySoftRef;
798 mySharedRef = s.mySharedRef;
825 if (result ==
nullptr)
826 return &theEmptyOptionsData;
846 if (myHash && s.myHash)
848 if (myHash != s.myHash)
889 UTswap(mySoftRef, other.mySoftRef);
890 UTswap(mySharedRef, other.mySharedRef);
891 UTswap(myHash, other.myHash);
915 explicit operator bool()
const {
return !isEmpty(); }
926 unsigned localhash = opt->
hash();
944 int64 mem = inclusive ?
sizeof(*this) : 0;
964 mySoftRef = s.mySoftRef;
965 mySharedRef = s.mySharedRef;
974 return mySharedRef.get();
992 static constexpr
uintptr_t SENTINEL_DATA = 1;
993 static constexpr
uint32 SENTINEL_HASH = 0xdeadbeef;
1029 mySoftRef =
nullptr;
1031 mySharedRef = UTmakeShared<UT_Options>(*opt);
1033 mySharedRef.reset();
1105 if (isSentinelOrNullPtr(mySoftRef))
1107 mySharedRef = UTmakeShared<UT_Options>(*mySoftRef);
1108 mySoftRef =
nullptr;
1123 mySharedRef = UTmakeShared<UT_Options>(*
options());
1124 mySoftRef =
nullptr;
1139 template <
typename OP>
1167 template <
typename T>
1168 struct DefaultClearer;
1177 static const bool clearNeedsDestruction =
false;
bool operator==(const UT_OptionsRef &s) const
bool getOptionB(const UT_StringRef &name) const
const UT_Options & operator=(const UT_Options &src)
Assignment operator.
GLboolean GLboolean GLboolean b
SYS_FORCE_INLINE UT_OptionsRef()
SYS_FORCE_INLINE bool isSentinel() const
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.
const UT_StringHolder & name() const
const UT_OptionEntry * operator*() const
int64 getMemoryUsage(bool inclusive) const
friend void swap(UT_OptionsRef &a, UT_OptionsRef &b)
Friend specialization of std::swap() to use UT_OptionsRef::swap()
SYS_FORCE_INLINE void swap(UT_OptionsRef &other)
bool isEqual(const UT_Options &src, fpreal64 tol) const
Comparison operator with a tolerance for float values.
const UT_StringArray & getOptionSArray(const UT_StringRef &) const
SYS_FORCE_INLINE UT_OptionsHolder(UT_OptionsHolder &&a) noexcept
Move constructor. Steals the working data from the original.
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
SYS_FORCE_INLINE const UT_Options & operator*() const
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)
const GLuint GLenum const void * binary
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
static const UT_OptionsHolder theSentinel
GLenum const void GLuint GLint reference
void addError(const char *filename, int linecount, const char *error_str) const
UT_Options & setOptionUVW(const UT_StringHolder &name, const UT_Vector3F &value)
bool operator!=(const UT_Options &src) const
UT_Options & setOptionV3(const UT_StringHolder &name, const UT_Vector3F &value)
int64 getOptionI(const UT_StringRef &name) const
void swap(T &lhs, T &rhs)
void setOption(const UT_StringHolder &name, UT_OptionEntryPtr value)
UT_OptionEntryPtr parsePyValue(const char *&value, char sep_delim, char close_delim= '\0')
fallback_uintptr uintptr_t
const UT_Vector3D & getOptionV3(const UT_StringRef &name) const
JSON reader class which handles parsing of JSON or bJSON files.
ordered_iterator oend() const
SYS_FORCE_INLINE UT_OptionsHolder(UT_OptionsReferenceType, const UT_Options *opt)
Will make a shallow reference.
Class which writes ASCII or binary JSON streams.
SYS_FORCE_INLINE UT_OptionsHolder()
const UT_Matrix3D & getOptionM3(const UT_StringRef &name) const
GLuint const GLchar * name
SYS_FORCE_INLINE UT_OptionsHolder & operator=(const UT_OptionsHolder &s)
Makes a bit-wise copy of the options and adjust the reference count.
const UT_Fpreal64Array & getOptionFArray(const UT_StringRef &) const
static const UT_Options & emptyOptions()
bool operator==(const UT_Options &src) const
Comparison operator.
UT_OptionsRef & operator=(const UT_OptionsRef &s)
Shares a reference with the source.
UT_Options & setOptionM4(const UT_StringHolder &name, const UT_Matrix4F &value)
void setSendOptionChanges(bool f)
void reference(const UT_Options *src)
GLenum GLsizei GLsizei GLint * values
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
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.
ordered_iterator & operator=(const ordered_iterator &i)
GLubyte GLubyte GLubyte GLubyte w
const UT_StringHolder * findOptionS(const UT_StringRef &name) const
ordered_iterator(const ordered_iterator &src)
SYS_FORCE_INLINE const UT_Options * optionsOrNull() const
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
SYS_FORCE_INLINE UT_OptionsRef(UT_OptionsRef &&s) noexcept
Move constructor. Steals the working data from the original.
UT_Options & setOptionSArray(const UT_StringHolder &name, const UT_StringHolder *values, size_t size)
Set string array options.
Parent::const_iterator const_iterator
UT_Options & setOptionI(const UT_StringHolder &name, int64 value)
fpreal64 getOptionNum(const UT_StringRef &) const
SYS_FORCE_INLINE void clear()
UT_Options & setOptionUV(const UT_StringHolder &name, const UT_Vector2F &value)
void update(const OP &op)
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
SYS_FORCE_INLINE void swap(UT_OptionsRef &other)
unsigned hash() const
Get a hash code for the options.
UT_Options & setOptionQ(const UT_StringHolder &name, const UT_QuaternionF &value)
GLboolean GLboolean GLboolean GLboolean a
GLsizei const GLchar *const * string
const UT_OptionEntry * operator*() const
ordered_iterator obegin() const
static const UT_OptionsHolder theEmptyOptions
friend void swap(UT_OptionsHolder &a, UT_OptionsRef &b)
SYS_FORCE_INLINE UT_OptionsRef(UT_OptionsSentinelType)
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)
GLdouble GLdouble GLdouble z
UT_Options & setOptionB(const UT_StringHolder &name, bool value)
const UT_StringHolder & name() const
UT_Options & setOptionM3(const UT_StringHolder &name, const UT_Matrix3F &value)
virtual void optionChanged(const char *name)
SYS_FORCE_INLINE UT_OptionsRef(const UT_OptionsRef &s)
Shares a reference with the source.
const UT_Matrix2D & getOptionM2(const UT_StringRef &name) const
UT_Options & setOptionM2(const UT_StringHolder &name, const UT_Matrix2F &value)
iterator(const iterator &i)
const UT_QuaternionD & getOptionQ(const UT_StringRef &name) const
bool operator!=(const UT_Options *s) const
bool operator!=(const iterator &i) const
bool operator==(const UT_Options *b) const
const UT_Int64Array & getOptionIArray(const UT_StringRef &) const
virtual int64 getMemoryUsage(bool inclusive) const
static bool isClear(const UT_OptionsHolder &v)
SYS_FORCE_INLINE ~UT_OptionsRef()
bool isUnique() const
Returns true this object is the sole owner of the underlying options.
bool save(const char *filename) const
friend class UT_OptionsHolder
static void clear(UT_OptionsHolder &v)
SYS_FORCE_INLINE UT_OptionsHolder(UT_OptionsReferenceType, const UT_OptionsRef &ref)
Makes a shallow reference to the contents of the UT_OptionsRef.
GLint GLint GLsizei GLint GLenum format
A map of string to various well defined value types.
UT_Options * makeUnique()
SYS_FORCE_INLINE UT_OptionsRef & operator=(UT_OptionsRef &&s)
SYS_FORCE_INLINE UT_OptionsHolder & operator=(UT_OptionsHolder &&s)
exint getNumOptions() const
SYS_FORCE_INLINE void makeSentinel()
const UT_Vector4D & getOptionV4(const UT_StringRef &name) const
bool operator!=(const ordered_iterator &i) const
SYS_FORCE_INLINE const UT_Options * options() const
ordered_iterator & operator++()
bool operator!=(const UT_OptionsRef &s) const
SYS_FORCE_INLINE UT_OptionsHolder(const UT_OptionsHolder &str)
Makes a copy of the provided options.
iterator & operator=(const iterator &i)
SYS_FORCE_INLINE UT_OptionsHolder(const UT_Options *opt)
Will make a copy of the provided options.
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)
Class to store JSON objects as C++ objects.
friend void swap(UT_OptionsHolder &a, UT_OptionsHolder &b)
bool sendOptionChanges() const
void merge(const UT_Options &src)
const UT_OptionEntry * entry() const
UT_OptionFormat
String formatting options for getOptionString.
const UT_OptionEntry * entry() const
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.
UT_Options & setOptionFArray(const UT_StringHolder &name, const fpreal32 *values, size_t size)
SYS_FORCE_INLINE void swap(UT_OptionsHolder &other)
bool operator==(const iterator &i) const
bool operator==(const ordered_iterator &i) const
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
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
static void clearConstruct(UT_OptionsHolder *p)
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.
const UT_StringHolder & getOptionS(const UT_StringRef &name) const