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);
221 bool has_component)
const
227 return myHolder->template attribute<PDG_AttributePyObject>()->
query(
228 number, query, index);
234 return myHolder->template attribute<PDG_AttributeDictionary>()->
query(
235 number, query, index);
238 return asNumber(number, index);
248 if (myHolder->template attribute<PDG_AttributeInteger>()->value(
259 if (myHolder->template attribute<PDG_AttributeFloat>()->value(
279 bool own =
false)
const
285 switch (myHolder->type())
289 if (!myHolder->template attribute<PDG_AttributePyObject>()->str(
300 if (!myHolder->template attribute<PDG_AttributeString>()->value(
312 if (myHolder->template attribute<PDG_AttributeFile>()->value(
315 file_path = temp.
data();
318 file_tag = temp.
tag();
321 file_hash = temp.
hash();
333 file =
PDG_File(file_path, file_tag, file_hash, own);
344 bool has_component)
const
350 return myHolder->template attribute<PDG_AttributePyObject>()->
query(
351 buffer, query, index);
357 return myHolder->template attribute<PDG_AttributeDictionary>()->
query(
358 buffer, query, index);
361 return asString(buffer, index, pad);
370 switch (myHolder->type())
375 if (myHolder->template attribute<PDG_AttributeInteger>()->value(
387 if (myHolder->template attribute<PDG_AttributeFloat>()->value(
406 if (myHolder->template attribute<PDG_AttributeString>()->value(
409 buffer.
sprintf(
"%s", temp.c_str());
418 if (myHolder->template attribute<PDG_AttributeFile>()->value(
429 if (myHolder->template attribute<PDG_AttributeDictionary>()->desc(
441 if (myHolder->template attribute<PDG_AttributePyObject>()->str(
459 switch (myHolder->type())
463 auto&&
values = myHolder->template
464 attribute<PDG_AttributeInteger>()->
values();
473 auto&&
values = myHolder->template
474 attribute<PDG_AttributeFloat>()->
values();
493 auto&&
values = myHolder->template
494 attribute<PDG_AttributeString>()->
values();
508 auto&&
values = myHolder->template
509 attribute<PDG_AttributeFile>()->
values();
523 if (myHolder->template attribute<PDG_AttributeDictionary>()->desc(
534 if (myHolder->template attribute<PDG_AttributePyObject>()->str(
556 return asOptions(options, myName, overwrite);
573 switch (myHolder->type())
583 myHolder->template attribute<PDG_AttributeInteger>();
584 if (attr->size() == 1)
609 myHolder->template attribute<PDG_AttributeFloat>();
610 if (attr->size() == 1)
615 key, attr->values().
data(), attr->size());
630 myHolder->template attribute<PDG_AttributeString>();
631 if (attr->size() == 1)
648 myHolder->template attribute<PDG_AttributeFile>();
649 if (attr->size() == 1)
654 for (
auto&&
value : attr->values())
671 myHolder->template attribute<PDG_AttributeDictionary>();
672 if (attr->size() == 1)
689 switch (myHolder->type())
745 template <
typename Attribute>
761 template <
typename Attribute>
802 :
Base(std::move(other))
803 , myModified(other.myModified)
805 other.myModified =
false;
837 myModified = other.myModified;
838 other.myModified =
false;
849 if (Base::myOwner && myModified)
850 Base::attributeModified(Base::myOwner,
Base::type(), Base::myName);
866 Base::myHolder->own();
867 Base::myHolder->setIsChanged(
true);
870 return Base::myHolder->template attribute<Attribute>();
886 if (!Base::isValid())
889 if (Base::myOwner && !Base::myOwner->isAttribFlagValid(flag))
892 changed = Base::myHolder->setFlag(flag, set);
901 return setFlag(flag, set, discard);
908 if (!Base::isValid())
911 if (Base::myOwner && !Base::myOwner->areAttribFlagsValid(flags))
914 changed = Base::myHolder->setFlags(flags);
923 return setFlags(flags, discard);
929 switch (Base::myHolder->
type())
933 return Base::myHolder->template
attribute<
939 return Base::myHolder->template
attribute<
945 return Base::myHolder->template
attribute<
951 return Base::myHolder->template
attribute<
957 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)
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)
PDG_AttributeCast asNumber(fpreal &number, const PDG_AttributeQuery &query, int index, bool has_component) const
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)
PDG_AttributeCast asString(UT_WorkBuffer &buffer, const PDG_AttributeQuery &query, int index, int pad, bool has_component) const
UT_Options & setOptionF(const UT_StringHolder &name, fpreal64 value)
PDG_AttributeError error() const
Returns the error state of the handle.
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