16 #ifndef _UT_OPTIONS_H_
17 #define _UT_OPTIONS_H_
183 bool save(
const char *filename)
const;
184 bool saveOrdered(
const char *filename)
const;
185 bool load(
const char *filename,
UT_IStream &is);
186 bool save(
const char *filename, std::ostream &os)
const;
187 bool saveOrdered(
const char *filename, std::ostream &os)
const;
189 bool saveAsJSON(
const char *filename,
190 bool binary =
true)
const;
191 bool saveAsJSON(
const char *filename, std::ostream &os,
192 bool binary =
true)
const;
210 bool sorted=
false)
const;
214 bool setFromPyDictionary(
const char *dict);
245 bool allow_type =
true,
246 bool allow_dict =
false);
249 void dump(std::ostream &os)
const;
259 int getNumOptions()
const;
267 : myOptions(i.myOptions)
268 , myIterator(i.myIterator)
272 {
return myIterator->first; }
274 {
return myIterator->second.get(); }
280 myOptions = i.myOptions;
281 myIterator = i.myIterator;
287 return myIterator == i.myIterator;
290 {
return !(*
this == i); }
292 bool atEnd()
const {
return myIterator == myEnd; }
303 MapType::const_iterator myIterator;
304 MapType::const_iterator myEnd;
320 , myValues(src.myValues)
327 {
return myKeys(myCurr); }
329 {
return myValues(myCurr); }
336 myValues = i.myValues;
344 if (i.
atEnd() && atEnd())
351 {
return !(*
this == i); }
368 bool operator()(
int a,
int b)
const
370 UT_ASSERT(a >= 0 && a < myKeys.entries());
371 UT_ASSERT(b >= 0 && b < myKeys.entries());
372 return myKeys(a) < myKeys(b);
378 explicit ordered_iterator(iterator it)
386 for (; !it.atEnd(); ++it, ++
index)
388 myKeys.append(it.name());
389 myValues.append(it.entry());
392 myOrder.stdsort( comparator(myKeys) );
405 {
return iterator(*
this, myMap.begin(), myMap.end()); }
407 {
return iterator(*
this, myMap.end(), myMap.end()); }
525 exint index = 0)
const;
528 exint index = 0)
const;
631 unsigned hash()
const;
636 {
return !(*
this ==
src); }
656 void addError(
const char *filename,
int linecount,
657 const char *error_str)
const;
659 {
return mySendOptionChanges; }
661 { mySendOptionChanges =
f; }
665 char close_delim =
'\0');
668 template <
class ITER>
669 bool save(ITER
start,
const char *filename, std::ostream &os)
const;
672 bool mySendOptionChanges;
702 mySoftRef = s.mySoftRef;
703 mySharedRef = s.mySharedRef;
711 mySoftRef =
s.mySoftRef;
712 mySharedRef = std::move(
s.mySharedRef);
729 , myHash(SENTINEL_HASH)
736 return uintptr_t(mySoftRef) == SENTINEL_DATA && myHash == SENTINEL_HASH;
743 myHash = SENTINEL_HASH;
744 mySoftRef = (
const UT_Options *) SENTINEL_DATA;
755 if (!mySharedRef.get())
758 return mySharedRef.unique();
767 if (!mySharedRef.get())
769 return mySharedRef.use_count();
776 mySoftRef = s.mySoftRef;
777 mySharedRef = s.mySharedRef;
804 if (result ==
nullptr)
805 return &theEmptyOptionsData;
820 if (!a || !b || (uintptr_t(a) == SENTINEL_DATA) || (uintptr_t(b) == SENTINEL_DATA))
825 if (myHash && s.myHash)
827 if (myHash != s.myHash)
845 if (!a || !b || (uintptr_t(a) == SENTINEL_DATA) || (uintptr_t(b) == SENTINEL_DATA))
868 UTswap(mySoftRef, other.mySoftRef);
869 UTswap(mySharedRef, other.mySharedRef);
870 UTswap(myHash, other.myHash);
894 explicit operator bool()
const {
return !isEmpty(); }
905 unsigned localhash = opt->
hash();
923 int64 mem = inclusive ?
sizeof(*this) : 0;
943 mySoftRef = s.mySoftRef;
944 mySharedRef = s.mySharedRef;
953 return mySharedRef.get();
971 static constexpr uintptr_t SENTINEL_DATA = 1;
972 static constexpr
uint32 SENTINEL_HASH = 0xdeadbeef;
981 return uintptr_t(p) <= SENTINEL_DATA;
1008 mySoftRef =
nullptr;
1010 mySharedRef = UTmakeShared<UT_Options>(*opt);
1012 mySharedRef.reset();
1084 if (isSentinelOrNullPtr(mySoftRef))
1086 mySharedRef = UTmakeShared<UT_Options>(*mySoftRef);
1087 mySoftRef =
nullptr;
1102 mySharedRef = UTmakeShared<UT_Options>(*
options());
1103 mySoftRef =
nullptr;
1118 template <
typename OP>
1146 template <
typename T>
1147 struct DefaultClearer;
1156 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.
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
GLuint const GLchar * name
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.
FMT_CONSTEXPR auto begin(const C &c) -> decltype(c.begin())
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)
GLboolean GLboolean GLboolean GLboolean a
int getNumOptions() const
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
GLint GLsizei const GLuint64 * values
static const UT_OptionsHolder theSentinel
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')
const UT_Vector3D & getOptionV3(const UT_StringRef &name) const
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
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
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()
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)
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)
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)
GLint GLint GLint GLint GLint x
GLint GLint GLint GLint GLint GLint y
void update(const OP &op)
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
GLint GLenum GLsizei GLint GLsizei const void * data
const GLuint GLenum const void * binary
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)
GLubyte GLubyte GLubyte GLubyte w
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)
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
GLdouble GLdouble GLdouble b
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.
GLsizei const GLchar *const * string
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)
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.
OIIO_API bool copy(string_view from, string_view to, std::string &err)
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)
GLenum const void GLuint GLint reference
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)
GLsizei const GLfloat * 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)
const UT_StringHolder & getOptionS(const UT_StringRef &name) const