9 #ifndef __PDG_ATTRIBUTE_MAP_H__
10 #define __PDG_ATTRIBUTE_MAP_H__
211 : myGlobalLock(attribute_map.globalLock())
212 , myAttribLock(attribute_map.attributeLock())
213 , myAttribMap(attribute_map)
216 myGlobalLock->readLock();
219 myAttribLock.readLock();
221 myAttribLock.writeLock();
223 myAttribMap.myWasModified =
false;
229 myAttribLock.readUnlock();
232 myAttribMap.onUnlock();
233 myAttribLock.writeUnlock();
237 myGlobalLock->readUnlock();
255 : myGlobalLock(attribute_map.globalLock())
256 , myAttribLock(attribute_map.attributeLock())
257 , myDidLockGlobal(false)
258 , myDidLockAttrib(false)
260 if (!myGlobalLock || myGlobalLock->tryReadLock())
262 myDidLockGlobal =
true;
263 if (myAttribLock.tryReadLock())
264 myDidLockAttrib =
true;
271 myAttribLock.readUnlock();
273 if (myGlobalLock && myDidLockGlobal)
274 myGlobalLock->readUnlock();
280 {
return (myDidLockGlobal && myDidLockAttrib); }
285 bool myDidLockGlobal;
286 bool myDidLockAttrib;
301 template <
typename Func>
312 template <
typename Func>
329 template <
typename Attribute,
typename Func>
333 attributeNames(names, Attribute::TypeEnum);
335 for (
auto&&
name : names)
337 auto&&
ref = refRO<Attribute>(
name);
349 template <
typename Func>
352 const Func&
func)
const
355 if (!attributeMatch(names, pattern,
false))
358 for (
auto&&
name : names)
360 auto&&
ref = refRO<PDG_AttributeData>(
name);
374 template <
typename Attribute,
typename Func>
377 const Func&
func)
const
380 if (!attributeMatch(names, pattern, Attribute::TypeEnum,
false))
383 for (
auto&&
name : names)
385 auto&&
ref = refRO<Attribute>(
name);
400 int64 getMemoryUsage(
bool inclusive)
const;
414 AttribTable dst_table=eTableStatic,
421 AttribTable dst_table=eTableStatic,
443 bool eraseDirty(
bool include_unowned);
460 void clearConcat(AttribTable
table=eTableCount);
464 bool timeDependentAttributes(
494 bool include_internal)
const;
500 bool include_internal)
const;
508 bool include_internal)
const;
518 bool include_internal)
const;
525 bool include_bound)
const;
532 bool include_bound)
const;
567 return refRO<PDG_AttributeFile>(theInputFileName,
table);
575 return refRWC<PDG_AttributeFile>(
588 return refRO<PDG_AttributeFile>(theOutputFileName,
table);
596 return refRWC<PDG_AttributeFile>(
609 return refRO<PDG_AttributeFile>(theAddedFileName,
table);
617 return refRWC<PDG_AttributeFile>(
631 return refRO<PDG_AttributeString>(theCommandStringName,
table);
639 return refRWC<PDG_AttributeString>(
640 theCommandStringName,
645 theCommandStringFlags);
653 return refRO<PDG_AttributeString>(theLabelName,
table);
661 return refRWC<PDG_AttributeString>(
675 return refRO<PDG_AttributeString>(theCustomStateName,
table);
684 return refRWC<PDG_AttributeString>(
690 theCustomStateFlags);
698 return refRO<PDG_AttributeFloat>(theCookPercentName,
table);
707 return refRWC<PDG_AttributeFloat>(
713 theCustomStateFlags);
718 template <
typename Attribute=PDG_AttributeData>
726 if (
table == eTableCount)
727 table = isRuntime(local_ctx) ? eTableDynamic : eTableStatic;
743 template <
typename Attribute>
748 if (!canWrite(local_ctx))
765 myWasModified =
true;
776 template <
typename Attribute>
784 return refRWC<Attribute>(
786 (create ? eCreateAlways : eCreateNever),
794 template <
typename Attribute>
801 bool allow_internal_names=
false,
805 if (!canWrite(local_ctx))
814 if (
table == eTableCount)
815 table = isStatic(local_ctx) ? eTableStatic : eTableDynamic;
823 myWasModified =
true;
847 refRO<PDG_AttributeInteger>(old_name),
856 refRO<PDG_AttributeFloat>(old_name),
865 refRO<PDG_AttributeString>(old_name),
874 refRO<PDG_AttributeFile>(old_name),
883 refRO<PDG_AttributeDictionary>(old_name),
892 refRO<PDG_AttributePyObject>(old_name),
901 refRO<PDG_AttributeGeometry>(old_name),
913 template <
typename Attribute>
920 if (!canWrite(local_ctx))
927 isStatic(local_ctx) ? eTableStatic : eTableDynamic;
944 eCreateAlways, overwrite,
false,
table, 0);
948 if (!ref.
isArray() && array_op)
952 if (holder->isOwner())
955 ref_holder->template attribute<Attribute>(),
958 else if (holder->attribute() && array_op)
962 ref_holder->template attribute<Attribute>(),
967 holder->reset(*ref_holder,
false,
true);
973 myWasModified =
true;
984 if (!canWrite(local_ctx))
988 isStatic(local_ctx) ? eTableStatic : eTableDynamic;
995 for (
int i = table; i >= 0; i--)
997 auto&& attrib = myAttributes[i].find(src_name);
998 if (attrib != myAttributes[i].
end())
1000 holder = attrib->second.get();
1008 if (src_table < table)
1028 auto&& iter = myAttributes[
table].find(valid);
1029 if (iter != myAttributes[table].
end())
1035 else if (!overwrite)
1039 myAttributes[
table].erase(iter);
1043 HolderPtr holder_copy =
1044 UTmakeUnique<PDG_AttributeHolder>(std::move(*holder));
1045 myAttributes[
table].emplace(valid, std::move(holder_copy));
1046 myAttributes[
table].erase(src_name);
1048 myWasModified =
true;
1054 template <
typename Attribute>
1071 template <
typename Attribute>
1088 template <
typename Attribute>
1090 const typename Attribute::Data&
value,
1096 auto&&
attribute = refRW<Attribute>(
name, create, overwrite);
1105 template <
typename Attribute>
1112 auto&&
attribute = refRW<Attribute>(
name, create, overwrite);
1121 template <
typename Attribute>
1127 auto&&
attribute = refRW<Attribute>(
name, create, overwrite);
1136 template <
typename Attribute>
1137 bool values(
typename Attribute::Map& value_map,
1142 if (isRuntime(local_ctx))
1173 void startChangeTracking();
1176 ChangeResult endChangeTracking(
bool check_all);
1182 bool include_internal,
1183 bool include_unowned,
1192 bool include_internal,
1193 bool include_unowned,
1212 void onUnlock()
const;
1215 bool hashAttributes(
1219 bool include_internal,
1220 bool include_unowned,
1236 bool include_bound)
const;
1255 AttribTable
table)
const
1257 if (myParentMap && myParentMap->hasAttribute(name, table))
1259 return (myAttributes[table].
find(name) != myAttributes[
table].end());
1268 AttribTable src_table,
1269 AttribTable dst_table,
1270 bool flatten_dynamic);
1274 bool mergeAttribute(
1279 AttribTable dst_table);
1283 bool loadAttribute(AttribTable table,
1294 bool loadAttribute(AttribTable table,
1310 bool values(AttribTable table,
1315 myParentMap->values(table, value_map, flags);
1317 for (
auto&& attrib_pair : myAttributes[table])
1324 if (!attribToValue(value_map[attrib_pair.first], 0, holder))
1333 template <
typename Attribute>
1334 void values(AttribTable table,
1335 typename Attribute::Map& value_map,
1341 for (
auto&& attrib_pair : myAttributes[table])
1346 value_map.erase(attrib_pair.first);
1357 value_map[attrib_pair.first] = attribute->values();
1415 switch (attrib.
type())
1437 switch (attrib.
type())
1464 switch (holder.
type())
1467 return attribToValue<PDG_AttributeFloat>(
value,
index, holder);
1469 return attribToValue<PDG_AttributeInteger>(
value,
index, holder);
1471 return attribToValue<PDG_AttributeString>(
value,
index, holder);
1487 value.setValue(buffer.
buffer());
1497 value.setValue(str);
1506 value.setValue(str);
1520 template <
typename Attribute>
1525 typename Attribute::Data temp;
1529 value.
setValue(
typename Attribute::Data());
1537 template <
typename Attribute>
1543 AttribTable table = isRuntime(local_ctx) ? eTableDynamic : eTableStatic;
1549 template <
typename Attribute>
1554 bool check_parent)
const
1557 for (
int i = table; i >= 0; i--)
1559 auto&& attrib = myAttributes[i].find(name);
1560 if (attrib != myAttributes[i].
end())
1562 holder = attrib->second.get();
1569 if (myParentMap && check_parent)
1571 return myParentMap->attribHolderR<
Attribute>(
1592 template <
typename Attribute>
1598 AttribTable src_table = eTableCount;
1602 for (
int i = table; i >= 0; i--)
1604 auto&& attrib = myAttributes[i].find(name);
1605 if (attrib != myAttributes[i].
end())
1607 holder = attrib->second.get();
1608 src_table =
static_cast<AttribTable
>(i);
1627 HolderPtr new_holder = UTmakeUnique<PDG_AttributeHolder>();
1628 new_holder->reset(*parent, parent->isOwner(),
true);
1630 name, std::move(new_holder));
1632 return insert.first->second.get();
1658 if (src_table < table)
1660 HolderPtr holder_copy = UTmakeUnique<PDG_AttributeHolder>();
1661 holder_copy->reset(*holder, holder->isOwner(),
true);
1664 name, std::move(holder_copy));
1666 return insert.first->second.get();
1678 template <
typename Attribute>
1688 AttribTable src_table = eTableCount;
1692 for (
int i = table; i >= 0; i--)
1694 auto&& attrib = myAttributes[i].find(name);
1695 if (attrib != myAttributes[i].
end())
1697 holder = attrib->second.get();
1698 src_table =
static_cast<AttribTable
>(i);
1718 if (create == eCreateNever)
1724 HolderPtr new_holder = UTmakeUnique<PDG_AttributeHolder>();
1725 new_holder->reset(*parent, parent->isOwner(),
true);
1728 name, std::move(new_holder));
1730 return insert.first->second.get();
1734 if (create != eCreateAlways)
1740 HolderPtr holder = UTmakeUnique<PDG_AttributeHolder>(
1742 Attribute::TypeEnum,
1748 name, std::move(holder));
1750 return insert.first->second.get();
1769 bool type_match = holder->typeMatch<Attribute>();
1779 if (src_table < table)
1781 if (create == eCreateNever)
1787 HolderPtr holder_copy = UTmakeUnique<PDG_AttributeHolder>();
1792 Attribute::TypeEnum,
1799 holder_copy->reset(*holder, holder->isOwner(),
true);
1802 name, std::move(holder_copy));
1804 return insert.first->second.get();
1811 new Attribute(), Attribute::TypeEnum, flags, own,
false,
false);
1818 Map myAttributes[eTableCount];
1824 bool myHasRuntimeAttribs;
1825 mutable bool myWasModified;
Only overwrite the attribute if the type matches.
PDG_RWAttributeRef< PDG_AttributeString > commandStringRW(CreateWhen create=eCreateNever, AttribTable table=eTableCount)
Returns a read/write handle to the standard input file attribute.
PDG_AttributeType type() const
Returns the attribute type.
bool desc(UT_StringHolder &str) const
bool hasFlag(PDG_AttributeFlag flag) const
Returns true if this attribute has the specified flag.
PDG_ROAttributeRef< PDG_AttributeString > labelRO(AttribTable table=eTableCount) const
bool adjustSize(int offset)
Sets the size of the attribute.
Never create the attribute, even if its not found.
static const UT_StringHolder theAddedFileName
Append to the existing attribute if it exists and matches.
static const uint16 theAddedFileFlags
Flags for the standard added file attribute.
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
Never overwrite the attribute.
PDG_RWAttributeRef< Attribute > refRWC(const UT_StringHolder &name, CreateWhen create=eCreateNever, PDG_AttributeOverwrite overwrite=PDG_AttributeOverwrite::eMatch, AttribTable table=eTableCount, bool allow_internal_names=false, uint16 flags=0)
Same as above, but with greater control on the creation flags.
Attribute values were changed or added.
Undefined or uninitialized attribute type.
GLsizei const GLfloat * value
ScopedTryLock(const PDG_AttributeMap &attribute_map)
PDG_AttributeError clearValues(const UT_StringHolder &name, bool create, PDG_AttributeOverwrite overwrite=PDG_AttributeOverwrite::eMatch)
PDG_RWAttributeRef< PDG_AttributeFile > addedFileRW(CreateWhen create=eCreateNever, AttribTable table=eTableCount)
Returns a read/write handle to the standard input file attribute.
bool isArray() const
Returns true if the attribute is an array.
PDG_ROAttributeRef< PDG_AttributeString > stateRO(AttribTable table=eTableCount) const
static const UT_StringHolder thePseudoAttribName
SYS_FORCE_INLINE const char * buffer() const
void clear()
Clears the attribute.
void swap(T &lhs, T &rhs)
std::size_t SYS_HashType
Define the type for hash values.
PDG_RWAttributeRef< PDG_AttributeFile > outputFileRW(CreateWhen create=eCreateNever, AttribTable table=eTableCount)
Returns a read-write handle to the standard output file attribute.
static const uint16 theCustomStateFlags
Flags for the standard custom state attribute.
bool hasFlags(uint16 flags) const
Returns true if this attribute has all of the specified flags set.
bool values(typename Attribute::Map &value_map, uint16 flags=0) const
Class which writes ASCII or binary JSON streams.
PDG_ROAttributeRef< PDG_AttributeString > commandStringRO(AttribTable table=eTableCount) const
const PDG_AttributeOwner * owner() const
Returns the attribute owner.
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
OIIO_FORCEINLINE vbool4 insert(const vbool4 &a, bool val)
Helper: substitute val for a[i].
static const UT_StringHolder theBuiltinPrefix
bool value(typename Attribute::Data &value, const UT_StringHolder &name, int index, uint16 flags=0) const
static PDG_EvaluationContext * getContext()
Returns the thread-local PDG_EvaluationContext instance.
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
PDG_ROAttributeRef< PDG_AttributeFile > addedFileRO(AttribTable table=eTableCount) const
Returns a read-only handle to the standard added file attribute.
PDG_AttributeError setValue(const UT_StringHolder &name, const typename Attribute::Data &value, int index, bool create, PDG_AttributeOverwrite overwrite=PDG_AttributeOverwrite::eMatch)
ScopedLock(const PDG_AttributeMap &attribute_map)
const UT_StringHolder & local_data() const
static const UT_StringHolder theInputFileName
A single PDG_ApplicationShim::Geometry instance.
GLint GLint GLsizei GLint GLenum GLenum type
No error was specified, i.e. the ref is valid.
AttribTable
Enumeration of attribute tables.
PDG_RWAttributeRef< PDG_AttributeString > labelRW(CreateWhen create=eCreateNever, AttribTable table=eTableCount)
Returns a read/write handle to the standard work item label attribute.
PDG_RWAttributeRef< PDG_AttributeFloat > cookPercentRW(CreateWhen create=eCreateNever, AttribTable table=eTableCount)
void forEachRO(const Func &func) const
PDG_ROAttributeRef< PDG_AttributeFile > outputFileRO(AttribTable table=eTableCount) const
Returns a read-only handle to the standard output file attribute.
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER class IMF_EXPORT_TEMPLATE_TYPE Array
static const UT_StringHolder theAllAttribName
void setValue(const PDGT_Value &value)
constexpr auto set(type rhs) -> int
PDG_ROAttributeRef< PDG_AttributeFloat > cookPercentRO(AttribTable table=eTableCount) const
Always create the attribute if it does not exist.
PDG_AttributeError copyFrom(const UT_StringHolder &name, const PDG_ROAttributeRef< Attribute > &ref, PDG_AttributeCopyOp copy_op, bool deep_copy)
Copies the specified attribute into an attribute on this map.
bool value(typename Attribute::Array &value, const UT_StringHolder &name, uint16 flags=0) const
bool concat(const PDG_AttributeHolder &other)
Concats the specified attribute with the attribute in this holder.
The attribute is read-only and cannot be modified on this work item.
static const uint16 theCommandStringFlags
Flags for the standard command string attribute.
const PDG_AttributeHolder * holder() const
Returns the underlying attribute holder.
static const UT_StringHolder theLabelName
Name of the built-in human readable label attribute.
PDG_AttributeType
Enumeration of possible attribute types.
static const UT_StringHolder theCookPercentName
Name of the built-in cook percent attribute.
Number of attribute tables.
An array of UT_StringHolder values.
static const UT_StringHolder theOutputFileName
GLuint const GLchar * name
bool str(UT_StringHolder &str) const
PDG_AttributeFlag
Enumeration of extra attribute flags. Flags can be ORed together.
An array of fpreal values.
Prepend to the existing attribute if it exists and matches.
GLenum GLenum GLsizei void * table
PDG_AttributeSaveType
Enumeration of the different ways that attributes can be saved.
static const UT_StringHolder thePartitionSizeName
Name of the built-in partition size attribute.
static const UT_StringHolder theCustomStateName
Name of the built-in custom state attribute.
static const uint16 theLabelFlags
Flags for the standard label attribute.
bool tryLockedAccess(const Func &func) const
The requested attribute is static and was not upgraded to dynamic.
bool forEachRO(const PDG_AttributePattern &pattern, const Func &func) const
GLenum GLsizei GLsizei GLint * values
PDG_RWAttributeRef< PDG_AttributeString > stateRW(CreateWhen create=eCreateNever, AttribTable table=eTableCount)
An array of PDG_File values, e.g. File info structs.
bool desc(UT_WorkBuffer &result, bool pretty_print=false) const
Writes a string representation of the dictionaries to the buffer.
PDG_RWAttributeRef< Attribute > refRW(const UT_StringHolder &name)
static const uint16 theInputFileFlags
Flags for the standard input file attribute.
static const uint16 theOutputFileFlags
Flags for the standard output file attribute.
bool value(DataType &data, int component) const
Class to store JSON objects as C++ objects.
OIIO_API bool attribute(string_view name, TypeDesc type, const void *val)
bool lockedAccess(const Func &func) const
A single, opaque PyObject.
The requested attribute was not found - the ref is invalid.
const Attribute * attribute() const
Const accessor for the own attribute - could be nullptr.
PDG_AttributeError setValue(const UT_StringHolder &name, const typename Attribute::Array &values, bool create, PDG_AttributeOverwrite overwrite=PDG_AttributeOverwrite::eMatch)
PDG_RWAttributeRef< PDG_AttributeFile > inputFileRW(CreateWhen create=eCreateNever, AttribTable table=eTableCount)
Returns a read/write handle to the standard input file attribute.
PDG_AttributeError rename(const UT_StringHolder &src_name, const UT_StringHolder &dst_name, bool overwrite)
Renames the specififed attribute.
PDG_ROAttributeRef< PDG_AttributeFile > inputFileRO(AttribTable table=eTableCount) const
Returns a read-only handle to the standard input file attribute.
ChangeResult
Enumeration of possible attribute change results during regeneration.
PDG_ROAttributeRef< Attribute > refRO(const UT_StringHolder &name, AttribTable table=eTableCount) const
static bool makeValidName(UT_StringHolder &name, const UT_StringHolder &str, bool allow_internal=false)
Reader/Writer mutex class.
class IMF_EXPORT_TYPE Attribute
PDG_RWAttributeRef< Attribute > refRW(const UT_StringHolder &name, bool create, PDG_AttributeOverwrite overwrite=PDG_AttributeOverwrite::eMatch, uint16 flags=0)
bool forEachRO(const PDG_AttributePattern &pattern, const Func &func) const
Only copy if the existing attribute does not exist.
An array of UT_OptionsHolder values.
static const UT_StringHolder theCommandStringName
Name of the built-in command attribute.
PDG_AttributeCopyOp
Enumeration of attribute copy operations.
PDG_AttributeError copyFrom(const UT_StringHolder &new_name, const UT_StringHolder &old_name, PDG_AttributeCopyOp copy_op, bool deep_copy)
The entire attribute map is read only.
An unspecified error occured - the ref is invalid.
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter