9 #ifndef __PDG_ATTRIBUTE_HOLDER_H__
10 #define __PDG_ATTRIBUTE_HOLDER_H__
29 : myAttribute(nullptr)
41 : myType(other.myType)
42 , myFlags(other.myFlags)
43 , myIsOwner(other.myIsOwner)
44 , myIsStale(other.myIsStale)
45 , myIsConcat(other.myIsConcat)
46 , myIsChanged(other.myIsChanged)
48 myAttribute = other.myAttribute;
50 other.myAttribute =
nullptr;
51 other.myIsOwner =
false;
52 other.myIsStale =
false;
53 other.myIsConcat =
false;
54 other.myIsChanged =
false;
64 : myAttribute(attribute)
78 if (myAttribute && myIsOwner)
87 reset(other.myAttribute, other.myType, other.myFlags,
88 other.myIsOwner, other.myIsStale, other.myIsConcat);
90 other.myAttribute =
nullptr;
91 other.myIsOwner =
false;
92 other.myIsStale =
false;
93 other.myIsConcat =
false;
94 other.myIsChanged =
false;
104 int64 mem = inclusive ?
sizeof(*this) : 0;
106 mem += myAttribute->getMemoryUsage(
true);
141 if (!myAttribute || myIsOwner)
144 myAttribute = myAttribute->
clone();
153 std::swap(myAttribute, holder.myAttribute);
155 bool is_owner = myIsOwner;
156 bool is_concat = myIsConcat;
157 bool is_changed = myIsChanged;
159 myIsOwner = holder.myIsOwner;
160 myIsConcat = holder.myIsConcat;
161 myIsChanged = holder.myIsChanged;
163 holder.myIsOwner = is_owner;
164 holder.myIsConcat = is_concat;
165 holder.myIsChanged = is_changed;
171 if (myAttribute && myIsOwner)
174 myAttribute =
nullptr;
190 if (myAttribute && myIsOwner)
195 myAttribute =
nullptr;
207 myIsStale = (own && stale);
225 if (myAttribute && myIsOwner)
230 myAttribute =
nullptr;
243 myAttribute = holder.myAttribute->
clone();
251 myAttribute = holder.myAttribute;
258 myType = holder.myType;
260 myFlags = holder.myFlags;
266 template <
typename Attribute=PDG_AttributeData>
273 template <
typename Attribute=PDG_AttributeData>
280 template <
typename Attribute=PDG_AttributeData>
283 const Attribute* attrib = attribute<Attribute>();
284 if (!attrib || !attrib->hasData())
322 if (!myAttribute || !other.myAttribute)
326 if ((myFlags != other.myFlags) || (myType != other.myType))
330 if (myAttribute == other.myAttribute)
334 return (myAttribute->compare(other.myAttribute));
341 return !(*
this == other);
346 inline operator bool()
const
348 return (myAttribute !=
nullptr);
353 template <
typename Attribute>
356 return (Attribute::TypeEnum == myType) ||
375 return (myFlags != 0);
381 return (myFlags & (
uint16)flag);
393 return ((myFlags & flags) != 0);
401 bool has_flag = hasFlag(flag);
406 myIsChanged |= !has_flag;
412 myFlags &= ~((
uint16)flag);
413 myIsChanged |= has_flag;
423 bool changed = (myFlags !=
flags);
425 myIsChanged |= changed;
433 myIsConcat = is_concat;
439 myIsChanged = is_changed;
443 template <
typename Attribute>
451 template <
typename Attribute>
454 return attribute<Attribute>()->adjustSize(offset);
458 template <
typename Attribute>
461 return attribute<Attribute>()->clear();
465 template <
typename Attribute>
478 bool myIsChanged : 1;
bool setFlag(PDG_AttributeFlag flag, bool set)
PDG_AttributeData * reset(const PDG_AttributeHolder &holder, bool own, bool sync_flags)
PDG_AttributeType type() const
Returns the attribute type.
PDG_AttributeData * own()
bool hasFlag(PDG_AttributeFlag flag) const
Returns true if this attribute has the specified flag.
bool adjustSize(int offset)
Sets the size of the attribute.
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
bool isOwner() const
Returns whether or not this holder has taken ownership of the attribute.
Undefined or uninitialized attribute type.
PDG_AttributeHolder()
Constructs an invalid attribute holder.
void clear()
Clears the attribute.
void swap(T &lhs, T &rhs)
Attribute * attribute()
Non-const accessor for the own attribute - could be nullptr.
bool hasAnyFlags(uint16 flags) const
Returns true if this attribute has any of the specified flags set.
bool hasFlags(uint16 flags) const
Returns true if this attribute has all of the specified flags set.
const PDG_AttributeData * operator->() const
void reset()
Resets the holder to a nullptr, thus making it an invalid holder.
PDG_AttributeHolder(PDG_AttributeHolder &&other)
Move constructs an attribute holder.
PDG_AttributeData * operator->()
bool operator!=(const PDG_AttributeHolder &other) const
PDG_AttributeData * reset(const PDG_AttributeData *attribute, PDG_AttributeType type, uint16 flags, bool own, bool stale, bool concat)
bool concat(const PDG_AttributeHolder &other)
Concats the specified attribute with the attribute in this holder.
PDG_AttributeHolder(PDG_AttributeData *attribute, PDG_AttributeType type, uint16 flags, bool owner, bool stale)
bool setFlags(uint16 flags)
void setIsChanged(bool is_changed)
Sets the changed bit to the specified value.
PDG_AttributeType
Enumeration of possible attribute types.
bool operator==(const PDG_AttributeHolder &other) const
const PDG_AttributeData & operator*() const
PDG_AttributeFlag
Enumeration of extra attribute flags. Flags can be ORed together.
PDG_AttributeHolder & operator=(PDG_AttributeHolder &&other)
Move assignment is permitted.
int64 getMemoryUsage(bool inclusive) const
void swap(PDG_AttributeHolder &other)
Swaps the specified attribute with the attribute in this holder.
OIIO_API bool attribute(string_view name, TypeDesc type, const void *val)
bool hasAnyFlags() const
Returns true if this attribute has at least one flag set.
uint16 flags() const
Returns the attribute flags.
void setIsConcat(bool is_concat)
Sets the concat bit to the specified value.
void swapAttributes(PDG_AttributeHolder &holder)
const Attribute * attribute() const
Const accessor for the own attribute - could be nullptr.
std::string OIIO_UTIL_API concat(string_view s, string_view t)
virtual PDG_AttributeData * clone() const =0
Deep copies this attribute.
bool hasData() const
Returns true if the underlying attribute has any data.
PDG_AttributeData & operator*()