9 #ifndef __PDG_ATTRIBUTE_REF_H__
10 #define __PDG_ATTRIBUTE_REF_H__
47 inline operator bool()
const
81 bool report_errors=
true,
82 bool as_warning=
false)
const;
87 static bool attributeError(
94 static void attributeModified(
108 template <
typename Attribute,
typename Holder>
134 return myHolder->template attribute<const Attribute>();
141 return myHolder->template attribute<const T>();
153 return myHolder->template hasData<Attribute>();
159 return myHolder->isOwner();
165 return myHolder->type();
171 return myHolder->flags();
177 return myHolder->hasAnyFlags();
183 return myHolder->hasFlag(flag);
189 return myHolder->hasFlags(flags);
195 return myHolder->hasAnyFlags(flags);
222 bool has_component)
const
228 return myHolder->template attribute<PDG_AttributePyObject>()->
query(
229 number, query, index);
235 return myHolder->template attribute<PDG_AttributeDictionary>()->
query(
236 number, query, query_index, index);
239 return asNumber(number, index);
249 if (myHolder->template attribute<PDG_AttributeInteger>()->value(
260 if (myHolder->template attribute<PDG_AttributeFloat>()->value(
280 bool own =
false)
const
286 switch (myHolder->type())
290 if (!myHolder->template attribute<PDG_AttributePyObject>()->str(
301 if (!myHolder->template attribute<PDG_AttributeString>()->value(
313 if (myHolder->template attribute<PDG_AttributeFile>()->value(
316 file_path = temp.
data();
319 file_tag = temp.
tag();
322 file_hash = temp.
hash();
334 file =
PDG_File(file_path, file_tag, file_hash, own);
346 bool has_component)
const
352 return myHolder->template attribute<PDG_AttributePyObject>()->
query(
353 buffer, query, index);
359 return myHolder->template attribute<PDG_AttributeDictionary>()->
query(
360 buffer, query, query_index, index);
363 return asString(buffer, index, pad);
372 switch (myHolder->type())
377 if (myHolder->template attribute<PDG_AttributeInteger>()->value(
389 if (myHolder->template attribute<PDG_AttributeFloat>()->value(
408 if (myHolder->template attribute<PDG_AttributeString>()->value(
411 buffer.
sprintf(
"%s", temp.c_str());
420 if (myHolder->template attribute<PDG_AttributeFile>()->value(
431 if (myHolder->template attribute<PDG_AttributeDictionary>()->desc(
443 if (myHolder->template attribute<PDG_AttributePyObject>()->str(
461 switch (myHolder->type())
465 auto&&
values = myHolder->template
466 attribute<PDG_AttributeInteger>()->
values();
475 auto&&
values = myHolder->template
476 attribute<PDG_AttributeFloat>()->
values();
495 auto&&
values = myHolder->template
496 attribute<PDG_AttributeString>()->
values();
510 auto&&
values = myHolder->template
511 attribute<PDG_AttributeFile>()->
values();
525 if (myHolder->template attribute<PDG_AttributeDictionary>()->desc(
536 if (myHolder->template attribute<PDG_AttributePyObject>()->str(
558 return asOptions(options, myName, overwrite);
575 switch (myHolder->type())
585 myHolder->template attribute<PDG_AttributeInteger>();
586 if (attr->size() == 1)
611 myHolder->template attribute<PDG_AttributeFloat>();
612 if (attr->size() == 1)
617 key, attr->values().
data(), attr->size());
632 myHolder->template attribute<PDG_AttributeString>();
633 if (attr->size() == 1)
650 myHolder->template attribute<PDG_AttributeFile>();
651 if (attr->size() == 1)
656 for (
auto&&
value : attr->values())
673 myHolder->template attribute<PDG_AttributeDictionary>();
674 if (attr->size() == 1)
691 switch (myHolder->type())
747 template <
typename Attribute>
763 template <
typename Attribute>
804 :
Base(std::move(other))
805 , myModified(other.myModified)
807 other.myModified =
false;
839 myModified = other.myModified;
840 other.myModified =
false;
851 if (Base::myOwner && myModified)
852 Base::attributeModified(Base::myOwner,
Base::type(), Base::myName);
868 Base::myHolder->own();
869 Base::myHolder->setIsChanged(
true);
872 return Base::myHolder->template attribute<Attribute>();
888 if (!Base::isValid())
891 if (Base::myOwner && !Base::myOwner->isAttribFlagValid(flag))
894 changed = Base::myHolder->setFlag(flag, set);
903 return setFlag(flag, set, discard);
910 if (!Base::isValid())
913 if (Base::myOwner && !Base::myOwner->areAttribFlagsValid(flags))
916 changed = Base::myHolder->setFlags(flags);
925 return setFlags(flags, discard);
931 switch (Base::myHolder->
type())
935 return Base::myHolder->template
attribute<
941 return Base::myHolder->template
attribute<
947 return Base::myHolder->template
attribute<
953 return Base::myHolder->template
attribute<
959 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.
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.
bool isEmpty() const
Same as !isstring()
bool isArray() const
Returns true if the attribute is an array.
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)
PDG_AttributeRefT(Holder *holder, const UT_StringHolder &name, const PDG_AttributeOwner *owner, PDG_AttributeError error=PDG_AttributeError::eNone)
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
bool hasAnyFlags() const
Returns true if the contained holder has any flags set.
void clearEvents()
Clears any pending events.
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
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)
int sprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
PDG_RWAttributeRef(const Self &other)
A map of string to various well defined value types.
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
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
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