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;
515 bool include_bound)
const;
522 bool include_bound)
const;
557 return refRO<PDG_AttributeFile>(theInputFileName,
table);
565 return refRWC<PDG_AttributeFile>(
578 return refRO<PDG_AttributeFile>(theOutputFileName,
table);
586 return refRWC<PDG_AttributeFile>(
599 return refRO<PDG_AttributeFile>(theAddedFileName,
table);
607 return refRWC<PDG_AttributeFile>(
621 return refRO<PDG_AttributeString>(theCommandStringName,
table);
629 return refRWC<PDG_AttributeString>(
630 theCommandStringName,
635 theCommandStringFlags);
643 return refRO<PDG_AttributeString>(theLabelName,
table);
651 return refRWC<PDG_AttributeString>(
665 return refRO<PDG_AttributeString>(theCustomStateName,
table);
674 return refRWC<PDG_AttributeString>(
680 theCustomStateFlags);
688 return refRO<PDG_AttributeFloat>(theCookPercentName,
table);
697 return refRWC<PDG_AttributeFloat>(
703 theCustomStateFlags);
708 template <
typename Attribute=PDG_AttributeData>
716 if (
table == eTableCount)
717 table = isRuntime(local_ctx) ? eTableDynamic : eTableStatic;
733 template <
typename Attribute>
738 if (!canWrite(local_ctx))
755 myWasModified =
true;
766 template <
typename Attribute>
774 return refRWC<Attribute>(
776 (create ? eCreateAlways : eCreateNever),
784 template <
typename Attribute>
791 bool allow_internal_names=
false,
795 if (!canWrite(local_ctx))
804 if (
table == eTableCount)
805 table = isStatic(local_ctx) ? eTableStatic : eTableDynamic;
813 myWasModified =
true;
821 template <
typename Attribute>
824 bool overwrite_existing,
828 if (!canWrite(local_ctx))
835 isStatic(local_ctx) ? eTableStatic : eTableDynamic;
841 eCreateAlways, overwrite,
false,
table, 0);
846 if (holder->isOwner())
849 ref_holder->template attribute<Attribute>());
853 holder->reset(*ref_holder,
false,
true);
859 myWasModified =
true;
870 if (!canWrite(local_ctx))
874 isStatic(local_ctx) ? eTableStatic : eTableDynamic;
881 for (
int i = table; i >= 0; i--)
883 auto&& attrib = myAttributes[i].find(src_name);
884 if (attrib != myAttributes[i].
end())
886 holder = attrib->second.get();
894 if (src_table < table)
914 auto&& iter = myAttributes[
table].find(valid);
915 if (iter != myAttributes[table].
end())
925 myAttributes[
table].erase(iter);
929 HolderPtr holder_copy =
930 UTmakeUnique<PDG_AttributeHolder>(std::move(*holder));
931 myAttributes[
table].emplace(valid, std::move(holder_copy));
932 myAttributes[
table].erase(src_name);
934 myWasModified =
true;
940 template <
typename Attribute>
957 template <
typename Attribute>
974 template <
typename Attribute>
976 const typename Attribute::Data&
value,
982 auto&&
attribute = refRW<Attribute>(
name, create, overwrite);
991 template <
typename Attribute>
998 auto&&
attribute = refRW<Attribute>(
name, create, overwrite);
1007 template <
typename Attribute>
1013 auto&&
attribute = refRW<Attribute>(
name, create, overwrite);
1022 template <
typename Attribute>
1023 bool values(
typename Attribute::Map& value_map,
1028 if (isRuntime(local_ctx))
1059 void startChangeTracking();
1062 ChangeResult endChangeTracking(
bool check_all);
1068 bool include_internal,
1069 bool include_unowned,
1078 bool include_internal,
1079 bool include_unowned,
1098 void onUnlock()
const;
1101 bool hashAttributes(
1105 bool include_internal,
1106 bool include_unowned,
1122 bool include_bound)
const;
1141 AttribTable
table)
const
1143 if (myParentMap && myParentMap->hasAttribute(name, table))
1145 return (myAttributes[table].
find(name) != myAttributes[
table].end());
1154 AttribTable src_table,
1155 AttribTable dst_table,
1156 bool flatten_dynamic);
1160 bool mergeAttribute(
1165 AttribTable dst_table);
1169 bool loadAttribute(AttribTable table,
1180 bool loadAttribute(AttribTable table,
1196 bool values(AttribTable table,
1201 myParentMap->values(table, value_map, flags);
1203 for (
auto&& attrib_pair : myAttributes[table])
1210 if (!attribToValue(value_map[attrib_pair.first], 0, holder))
1219 template <
typename Attribute>
1220 void values(AttribTable table,
1221 typename Attribute::Map& value_map,
1227 for (
auto&& attrib_pair : myAttributes[table])
1232 value_map.erase(attrib_pair.first);
1243 value_map[attrib_pair.first] = attribute->values();
1301 switch (attrib.
type())
1323 switch (attrib.
type())
1350 switch (holder.
type())
1353 return attribToValue<PDG_AttributeFloat>(
value,
index, holder);
1355 return attribToValue<PDG_AttributeInteger>(
value,
index, holder);
1357 return attribToValue<PDG_AttributeString>(
value,
index, holder);
1373 value.setValue(buffer.
buffer());
1383 value.setValue(str);
1392 value.setValue(str);
1406 template <
typename Attribute>
1411 typename Attribute::Data temp;
1415 value.
setValue(
typename Attribute::Data());
1423 template <
typename Attribute>
1429 AttribTable table = isRuntime(local_ctx) ? eTableDynamic : eTableStatic;
1435 template <
typename Attribute>
1440 bool check_parent)
const
1443 for (
int i = table; i >= 0; i--)
1445 auto&& attrib = myAttributes[i].find(name);
1446 if (attrib != myAttributes[i].
end())
1448 holder = attrib->second.get();
1455 if (myParentMap && check_parent)
1457 return myParentMap->attribHolderR<
Attribute>(
1478 template <
typename Attribute>
1484 AttribTable src_table = eTableCount;
1488 for (
int i = table; i >= 0; i--)
1490 auto&& attrib = myAttributes[i].find(name);
1491 if (attrib != myAttributes[i].
end())
1493 holder = attrib->second.get();
1494 src_table =
static_cast<AttribTable
>(i);
1513 HolderPtr new_holder = UTmakeUnique<PDG_AttributeHolder>();
1514 new_holder->reset(*parent, parent->isOwner(),
true);
1516 name, std::move(new_holder));
1518 return insert.first->second.get();
1544 if (src_table < table)
1546 HolderPtr holder_copy = UTmakeUnique<PDG_AttributeHolder>();
1547 holder_copy->reset(*holder, holder->isOwner(),
true);
1550 name, std::move(holder_copy));
1552 return insert.first->second.get();
1564 template <
typename Attribute>
1574 AttribTable src_table = eTableCount;
1578 for (
int i = table; i >= 0; i--)
1580 auto&& attrib = myAttributes[i].find(name);
1581 if (attrib != myAttributes[i].
end())
1583 holder = attrib->second.get();
1584 src_table =
static_cast<AttribTable
>(i);
1604 if (create == eCreateNever)
1610 HolderPtr new_holder = UTmakeUnique<PDG_AttributeHolder>();
1611 new_holder->reset(*parent, parent->isOwner(),
true);
1614 name, std::move(new_holder));
1616 return insert.first->second.get();
1620 if (create != eCreateAlways)
1626 HolderPtr holder = UTmakeUnique<PDG_AttributeHolder>(
1628 Attribute::TypeEnum,
1634 name, std::move(holder));
1636 return insert.first->second.get();
1655 bool type_match = holder->typeMatch<Attribute>();
1665 if (src_table < table)
1667 if (create == eCreateNever)
1673 HolderPtr holder_copy = UTmakeUnique<PDG_AttributeHolder>();
1678 Attribute::TypeEnum,
1685 holder_copy->reset(*holder, holder->isOwner(),
true);
1688 name, std::move(holder_copy));
1690 return insert.first->second.get();
1697 new Attribute(), Attribute::TypeEnum, flags, own,
false,
false);
1704 Map myAttributes[eTableCount];
1710 bool myHasRuntimeAttribs;
1711 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
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.
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.
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.
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.
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)
PDG_ROAttributeRef< PDG_AttributeFloat > cookPercentRO(AttribTable table=eTableCount) const
Always create the attribute if it does not exist.
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.
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
An array of UT_OptionsHolder values.
static const UT_StringHolder theCommandStringName
Name of the built-in command attribute.
The entire attribute map is read only.
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
PDG_AttributeError copyFrom(const UT_StringHolder &name, const PDG_ROAttributeRef< Attribute > &ref, bool overwrite_existing, bool deep_copy)
Copies the specified attribute into an attribute on this map.
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter