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);
253 bool require_type =
true);
266 bool allow_type =
true,
267 bool allow_dict =
false);
270 void dump(std::ostream &os)
const;
291 : myOptions(i.myOptions)
292 , myIterator(i.myIterator)
296 {
return myIterator->first; }
298 {
return myIterator->second.get(); }
304 myOptions = i.myOptions;
305 myIterator = i.myIterator;
311 return myIterator == i.myIterator;
314 {
return !(*
this == i); }
316 bool atEnd()
const {
return myIterator == myEnd; }
327 MapType::const_iterator myIterator;
328 MapType::const_iterator myEnd;
344 , myValues(src.myValues)
351 {
return myKeys(myCurr); }
353 {
return myValues(myCurr); }
360 myValues = i.myValues;
368 if (i.
atEnd() && atEnd())
375 {
return !(*
this == i); }
392 bool operator()(
int a,
int b)
const
394 UT_ASSERT(a >= 0 && a < myKeys.entries());
395 UT_ASSERT(b >= 0 && b < myKeys.entries());
396 return myKeys(a) < myKeys(b);
402 explicit ordered_iterator(iterator it)
410 for (; !it.atEnd(); ++it, ++
index)
412 myKeys.append(it.name());
413 myValues.append(it.entry());
416 myOrder.sort(comparator(myKeys));
429 {
return iterator(*
this, myMap.begin(), myMap.end()); }
431 {
return iterator(*
this, myMap.end(), myMap.end()); }
549 exint index = 0)
const;
552 exint index = 0)
const;
655 unsigned hash()
const;
661 {
return !(*
this ==
src); }
681 void addError(
const char *filename,
int linecount,
682 const char *error_str)
const;
684 {
return mySendOptionChanges; }
686 { mySendOptionChanges =
f; }
690 char close_delim =
'\0');
693 template <
class ITER>
694 bool save(ITER
start,
const char *filename, std::ostream &os)
const;
697 bool mySendOptionChanges;
727 mySoftRef = s.mySoftRef;
728 mySharedRef = s.mySharedRef;
736 mySoftRef =
s.mySoftRef;
737 mySharedRef = std::move(
s.mySharedRef);
753 : mySoftRef((const
UT_Options *)SENTINEL_DATA)
754 , myHash(SENTINEL_HASH)
761 return uintptr_t(mySoftRef) == SENTINEL_DATA && myHash == SENTINEL_HASH;
768 myHash = SENTINEL_HASH;
769 mySoftRef = (
const UT_Options *) SENTINEL_DATA;
780 if (!mySharedRef.get())
783 return mySharedRef.unique();
792 if (!mySharedRef.get())
794 return mySharedRef.use_count();
801 mySoftRef = s.mySoftRef;
802 mySharedRef = s.mySharedRef;
829 if (result ==
nullptr)
830 return &theEmptyOptionsData;
850 if (myHash && s.myHash)
852 if (myHash != s.myHash)
893 UTswap(mySoftRef, other.mySoftRef);
894 UTswap(mySharedRef, other.mySharedRef);
895 UTswap(myHash, other.myHash);
919 explicit operator bool()
const {
return !isEmpty(); }
930 unsigned localhash = opt->
hash();
948 int64 mem = inclusive ?
sizeof(*this) : 0;
968 mySoftRef = s.mySoftRef;
969 mySharedRef = s.mySharedRef;
978 return mySharedRef.get();
996 static constexpr
uintptr_t SENTINEL_DATA = 1;
997 static constexpr
uint32 SENTINEL_HASH = 0xdeadbeef;
1003 template<
typename T>
1033 mySoftRef =
nullptr;
1035 mySharedRef = UTmakeShared<UT_Options>(*opt);
1037 mySharedRef.reset();
1043 mySoftRef =
nullptr;
1044 mySharedRef = std::move(opts);
1116 if (isSentinelOrNullPtr(mySoftRef))
1118 mySharedRef = UTmakeShared<UT_Options>(*mySoftRef);
1119 mySoftRef =
nullptr;
1134 mySharedRef = UTmakeShared<UT_Options>(*
options());
1135 mySoftRef =
nullptr;
1150 template <
typename OP>
1178 template <
typename T>
1179 struct DefaultClearer;
1188 static const bool clearNeedsDestruction =
false;
SYS_FORCE_INLINE UT_OptionsHolder(UT_UniquePtr< UT_Options > opts)
bool operator==(const UT_OptionsRef &s) const
bool getOptionB(const UT_StringRef &name) const
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
GLsizei const GLchar *const * string
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)
GLdouble GLdouble GLdouble z
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
GLboolean GLboolean GLboolean GLboolean a
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
**But if you need a result
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)
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)
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)
const UT_OptionEntry * operator*() const
GLint GLint GLsizei GLint GLenum format
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
GLuint const GLchar * name
bool operator!=(const UT_Options *s) const
bool operator!=(const iterator &i) const
GLboolean GLboolean GLboolean b
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.
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
GLenum GLsizei GLsizei GLint * values
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.
LeafData & operator=(const LeafData &)=delete
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)
GLubyte GLubyte GLubyte GLubyte w
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)
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)
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