9 #ifndef __PDG_ATTRIBUTE_REF_H__
10 #define __PDG_ATTRIBUTE_REF_H__
51 inline operator bool()
const
90 static bool attributeError(
97 static void attributeModified(
116 template <
typename Attribute,
typename Holder>
142 return myHolder->template attribute<const Attribute>();
149 return myHolder->template attribute<const T>();
161 return myHolder->template hasData<Attribute>();
167 return myHolder->isOwner();
173 return myHolder->type();
179 return myHolder->flags();
185 return myHolder->hasAnyFlags();
191 return myHolder->hasFlag(flag);
197 return myHolder->hasFlags(flags);
203 return myHolder->hasAnyFlags(flags);
231 SYShashCombine(result, myName);
236 if (!
attribute()->hash(attrib_hash, index, errors))
239 SYShashCombine(result, attrib_hash);
243 SYShashCombine(result,
flags());
255 bool has_component)
const
261 return myHolder->template attribute<PDG_AttributePyObject>()->
query(
262 number, query, index);
268 return myHolder->template attribute<PDG_AttributeDictionary>()->
query(
269 number, query, query_index, index);
272 return asNumber(number, index);
282 if (myHolder->template attribute<PDG_AttributeInteger>()->value(
293 if (myHolder->template attribute<PDG_AttributeFloat>()->value(
307 template <
typename Array>
312 auto&& attr = myHolder->template attribute<PDG_AttributeInteger>();
313 for (
exint i = 0; i < attr->size(); i++)
314 array.append(attr->value(i));
319 auto&& attr = myHolder->template attribute<PDG_AttributeFloat>();
320 for (
exint i = 0; i < attr->size(); i++)
321 array.append(attr->value(i));
341 if (!myHolder->template attribute<PDG_AttributeString>()->value(
356 myHolder->template attribute<PDG_AttributeFile>()->valueForTag(
385 auto&&
values = myHolder->template
386 attribute<PDG_AttributeString>()->
values();
405 auto&&
values = myHolder->template
406 attribute<PDG_AttributeFile>()->
values();
411 path =
value.localizePath(scheduler);
435 bool own =
false)
const
441 switch (myHolder->type())
445 if (!myHolder->template attribute<PDG_AttributePyObject>()->str(
456 if (!myHolder->template attribute<PDG_AttributeString>()->value(
468 if (myHolder->template attribute<PDG_AttributeFile>()->value(
471 file_path = temp.
data();
474 file_tag = temp.
tag();
477 file_hash = temp.
hash();
489 file =
PDG_File(file_path, file_tag, file_hash, own);
501 bool has_component)
const
507 return myHolder->template attribute<PDG_AttributePyObject>()->
query(
508 buffer, query, index);
514 return myHolder->template attribute<PDG_AttributeDictionary>()->
query(
515 buffer, query, query_index, index);
518 return asString(buffer, index, pad);
527 switch (myHolder->type())
532 if (myHolder->template attribute<PDG_AttributeInteger>()->value(
544 if (myHolder->template attribute<PDG_AttributeFloat>()->value(
563 if (myHolder->template attribute<PDG_AttributeString>()->value(
566 buffer.
sprintf(
"%s", temp.c_str());
575 if (myHolder->template attribute<PDG_AttributeFile>()->value(
586 if (myHolder->template attribute<PDG_AttributeDictionary>()->desc(
587 buffer, index,
false))
598 if (myHolder->template attribute<PDG_AttributePyObject>()->str(
617 switch (myHolder->type())
622 myHolder->template attribute<PDG_AttributeInteger>();
624 for (
exint i = 0; i < attr->size(); i++)
626 buffer.
format(
"{}", attr->value(i));
636 myHolder->template attribute<PDG_AttributeFloat>();
638 for (
exint i = 0; i < attr->size(); i++)
640 buffer.
format(
"{}", attr->value(i));
650 myHolder->template attribute<PDG_AttributeString>();
652 for (
exint i = 0; i < attr->size(); i++)
653 array.
append(attr->value(i));
661 myHolder->template attribute<PDG_AttributeFile>();
663 for (
exint i = 0; i < attr->size(); i++)
664 array.
append(attr->value(i).data());
672 myHolder->template attribute<PDG_AttributeDictionary>();
674 for (
exint i = 0; i < attr->size(); i++)
676 attr->desc(buffer, i,
false);
694 switch (myHolder->type())
698 auto&&
values = myHolder->template
699 attribute<PDG_AttributeInteger>()->
values();
708 auto&&
values = myHolder->template
709 attribute<PDG_AttributeFloat>()->
values();
728 auto&&
values = myHolder->template
729 attribute<PDG_AttributeString>()->
values();
743 auto&&
values = myHolder->template
744 attribute<PDG_AttributeFile>()->
values();
758 if (myHolder->template attribute<PDG_AttributeDictionary>()->desc(
769 if (myHolder->template attribute<PDG_AttributePyObject>()->str(
791 return asOptions(options, myName, overwrite);
808 switch (myHolder->type())
818 myHolder->template attribute<PDG_AttributeInteger>();
819 if (attr->size() == 1)
844 myHolder->template attribute<PDG_AttributeFloat>();
845 if (attr->size() == 1)
850 key, attr->values().
data(), attr->size());
865 myHolder->template attribute<PDG_AttributeString>();
866 if (attr->size() == 1)
883 myHolder->template attribute<PDG_AttributeFile>();
884 if (attr->size() == 1)
889 for (
auto&&
value : attr->values())
906 myHolder->template attribute<PDG_AttributeDictionary>();
907 if (attr->size() == 1)
924 switch (myHolder->type())
980 template <
typename Attribute>
996 template <
typename Attribute>
1037 :
Base(std::move(other))
1038 , myModified(other.myModified)
1040 other.myModified =
false;
1072 myModified = other.myModified;
1073 other.myModified =
false;
1084 if (Base::myOwner && myModified)
1085 Base::attributeModified(Base::myOwner,
Base::type(), Base::myName);
1101 Base::myHolder->own();
1102 Base::myHolder->setIsChanged(
true);
1105 return Base::myHolder->template attribute<Attribute>();
1121 if (!Base::isValid())
1124 if (Base::myOwner && !Base::myOwner->isAttribFlagValid(flag))
1127 changed = Base::myHolder->setFlag(flag, set);
1136 return setFlag(flag, set, discard);
1143 if (!Base::isValid())
1146 if (Base::myOwner && !Base::myOwner->areAttribFlagsValid(flags))
1149 changed = Base::myHolder->setFlags(flags);
1158 return setFlags(flags, discard);
1164 switch (Base::myHolder->
type())
1168 return Base::myHolder->template
attribute<
1174 return Base::myHolder->template
attribute<
1180 return Base::myHolder->template
attribute<
1186 return Base::myHolder->template
attribute<
1192 return Base::myHolder->template
attribute<
UT_OptionType getOptionType(const UT_StringRef &name) const
const T * attributeT() const
PDG_AttributeError setFlags(uint16 flags)
Sets all flags.
static UT_StringHolder localizePath(const UT_StringHolder &path, const PDG_Scheduler *scheduler)
Localizes a path with the specified scheduler.
Never overwrite the attribute.
bool isOwner() const
Returns true if the contained attribute holder owns its data.
GLsizei const GLfloat * value
UT_Options & setOptionDictArray(const UT_StringHolder &name, const UT_OptionsHolder *values, size_t size)
Set dict array options.
const UT_StringHolder & name() const
Returns the name of the attribute referenced by this attrib ref.
GLsizei const GLchar *const * path
bool isEmpty() const
Same as !isstring()
bool isArray() const
Returns true if the attribute is an array.
SYS_FORCE_INLINE const char * buffer() const
std::size_t SYS_HashType
Define the type for hash values.
GLuint GLsizei GLsizei * length
PDG_RWAttributeRef(PDG_AttributeHolder *holder, const UT_StringHolder &name, const PDG_AttributeOwner *owner, PDG_AttributeError error=PDG_AttributeError::eNone)
PDG_AttributeError setFlag(PDG_AttributeFlag flag, bool set, bool &changed)
**But if you need a result
PDG_AttributeRefT(Holder *holder, const UT_StringHolder &name, const PDG_AttributeOwner *owner, PDG_AttributeError error=PDG_AttributeError::eNone)
bool hash(SYS_HashType &result, exint index, bool include_value, bool include_name, bool include_flags, UT_WorkBuffer &errors) const
Returns a hash of the name, flags and values of the attribute.
SYS_FORCE_INLINE const char * data() const
UT_Options & setOptionIArray(const UT_StringHolder &name, const int32 *values, size_t size)
~PDG_RWAttributeRef()
Emits data changed events if this attribute ref recorded a modification.
bool hasAnyFlags(uint16 flags) const
Returns true if the contained holder has any of the specified flags set.
Cast failed due to a type mismatch (string vs. int)
bool hasFlag(PDG_AttributeFlag flag) const
Returns true if the contained holder has the specified flag set.
const char * buffer() const
UT_Options & setOptionSArray(const UT_StringHolder &name, const UT_StringHolder *values, size_t size)
Set string array options.
A single PDG_ApplicationShim::Geometry instance.
No error was specified, i.e. the ref is valid.
void truncate(int length)
Truncates the array stored in the attribute.
int64 Hash
The file hash/modtime type.
bool removeTrailingSpace()
Remove trailing whitespace, return true if whitespace was removed.
UT_Options & setOptionI(const UT_StringHolder &name, int64 value)
PDG_AttributeCast asString(UT_WorkBuffer &buffer, exint &query_index, const PDG_AttributeQuery &query, int index, int pad, bool has_component) const
const UT_StringHolder & tag() const
UT_StringHolder localizePath(const PDG_Scheduler *scheduler) const
Updates and return the local_path.
bool hasAnyFlags() const
Returns true if the contained holder has any flags set.
void clearEvents()
Clears any pending events.
constexpr auto set(type rhs) -> int
static const UT_StringHolder theEmptyString
PDG_AttributeCast
Enumeration of attribute cast results.
PDG_AttributeCast asOptions(UT_Options &options, const UT_StringHolder &key, PDG_AttributeOverwrite overwrite) const
Attribute * operator->()
Returns a non-const pointer to the underlying attribute instance.
PDG_AttributeCast asNumber(fpreal &number, int index) const
PDG_AttributeCast asFile(PDG_File &file, int index, const UT_StringHolder &tag=UT_StringHolder::theEmptyString, PDG_File::Hash hash=0, bool own=false) const
bool hasData() const
Returns true if the contained attribute has any data.
Holder * holder() const
Returns the underlying attribute holder.
PDG_AttributeType
Enumeration of possible attribute types.
PDG_AttributeError setFlag(PDG_AttributeFlag flag, bool set)
Sets the specific flag on or off.
SYS_FORCE_INLINE const char * c_str() const
PDG_RWAttributeRef(const UT_StringHolder &name, const PDG_AttributeOwner *owner)
Constructs an uninitialized RW ref.
const UT_StringHolder & data() const
static bool isArrayType(PDG_AttributeType type)
Returns true if the specified type is an array type.
An array of UT_StringHolder values.
GLuint const GLchar * name
const Attribute * attribute() const
Returns a const pointer to the underlying attribute instance.
const PDG_AttributeOwner * myOwner
PDG_AttributeFlag
Enumeration of extra attribute flags. Flags can be ORed together.
const PDG_AttributeOwner * owner() const
Returns the PDG_AttributeOwner that owns the underlying attribute.
An array of fpreal values.
fpreal32 SYSrint(fpreal32 val)
PDG_AttributeCast asNumbers(Array &array) const
int sprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
PDG_AttributeCast asFilePathValues(UT_WorkBuffer &buffer, const UT_StringHolder &tag, const PDG_Scheduler *scheduler, bool localize)
PDG_RWAttributeRef(const Self &other)
A map of string to various well defined value types.
size_t format(const char *fmt, const Args &...args)
int int appendSprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
int size() const
Returns the size of the data stored in the attribute.
PDG_AttributeError setFlags(uint16 flags, bool &changed)
Directly sets the flag bits to the specified flags.
The ref is uninitialized and needs to be created at a later point.
GLenum GLsizei GLsizei GLint * values
PDG_AttributeCast asStringValues(UT_WorkBuffer &buffer, int pad=0) const
Prints the values contained in the attribute to space-separated string.
PDG_AttributeType type() const
Returns the type of the contained attribute.
An array of PDG_File values, e.g. File info structs.
uint16 flags() const
Returns the flags on the contained holder.
bool isNumeric() const
Returns true if the attribute is numeric.
LeafData & operator=(const LeafData &)=delete
PDG_AttributeCast asString(UT_WorkBuffer &buffer, int index, int pad=0) const
PDG_AttributeCast asFilePath(UT_StringHolder &path, int index, const UT_StringHolder &tag, const PDG_Scheduler *scheduler, bool localize)
No cast error occured (success)
UT_Options & setOptionS(const UT_StringHolder &name, const UT_StringHolder &value)
PDG_RWAttributeRef(Self &&other)
OIIO_API bool attribute(string_view name, TypeDesc type, const void *val)
A single, opaque PyObject.
void protectString(bool protect_empty=false)
PDG_AttributeCast asOptions(UT_Options &options, PDG_AttributeOverwrite overwrite) const
const Attribute * operator->() const
Returns a const pointer to the underlying attribute instance.
void emitEvents()
Emits pending events from the ref.
UT_Options & setOptionDict(const UT_StringHolder &name, const UT_OptionsHolder &value)
UT_Options & setOptionFArray(const UT_StringHolder &name, const fpreal32 *values, size_t size)
Cast failed due to an index being out of bounds.
Self & operator=(Self &&other)
Self & operator=(const Self &other)
UT_Options & setOptionF(const UT_StringHolder &name, fpreal64 value)
PDG_AttributeError error() const
Returns the error state of the handle.
PDG_AttributeCast asNumber(fpreal &number, exint &query_index, const PDG_AttributeQuery &query, int index, bool has_component) const
PDG_AttributeCast asStrings(UT_StringArray &array) const
An array of UT_OptionsHolder values.
PDG_AttributeRef(const UT_StringHolder &name, const PDG_AttributeOwner *owner, PDG_AttributeError error=PDG_AttributeError::eNone)
bool isValid() const
Returns true if the handle is valid.
bool hasFlags(uint16 flags) const
Returns true if the contained holder has all of the specified flags set.
PDG_AttributeError myError