9 #ifndef __PDG_ATTRIBUTE_MAP_H__
10 #define __PDG_ATTRIBUTE_MAP_H__
241 : myGlobalLock(attribute_map.globalLock())
242 , myAttribLock(attribute_map.attributeLock())
243 , myAttribMap(attribute_map)
246 myGlobalLock->readLock();
249 myAttribLock.readLock();
251 myAttribLock.writeLock();
257 myAttribLock.readUnlock();
260 myAttribMap.onUnlock();
261 myAttribLock.writeUnlock();
265 myGlobalLock->readUnlock();
283 : myGlobalLock(attribute_map.globalLock())
284 , myAttribLock(attribute_map.attributeLock())
285 , myDidLockGlobal(false)
286 , myDidLockAttrib(false)
288 if (!myGlobalLock || myGlobalLock->tryReadLock())
290 myDidLockGlobal =
true;
291 if (myAttribLock.tryReadLock())
292 myDidLockAttrib =
true;
299 myAttribLock.readUnlock();
301 if (myGlobalLock && myDidLockGlobal)
302 myGlobalLock->readUnlock();
308 {
return (myDidLockGlobal && myDidLockAttrib); }
313 bool myDidLockGlobal;
314 bool myDidLockAttrib;
329 template <
typename Func>
340 template <
typename Func>
357 template <
typename Attribute,
typename Func>
361 attributeNames(names, Attribute::TypeEnum);
363 for (
auto&&
name : names)
365 auto&&
ref = refRO<Attribute>(
name);
378 int64 getMemoryUsage(
bool inclusive)
const;
392 AttribTable dst_table=eTableStatic,
399 AttribTable dst_table=eTableStatic,
421 bool eraseDirty(
bool include_unowned);
438 void clearConcat(AttribTable
table=eTableCount);
442 bool timeDependentAttributes(
472 bool include_internal)
const;
478 bool include_internal)
const;
485 bool include_bound)
const;
498 bool loadV2(SaveType save_type,
510 return refRO<PDG_AttributeFile>(theInputFileName,
table);
518 return refRWC<PDG_AttributeFile>(
531 return refRO<PDG_AttributeFile>(theOutputFileName,
table);
539 return refRWC<PDG_AttributeFile>(
552 return refRO<PDG_AttributeFile>(theAddedFileName,
table);
560 return refRWC<PDG_AttributeFile>(
574 return refRO<PDG_AttributeString>(theCommandStringName,
table);
582 return refRWC<PDG_AttributeString>(
583 theCommandStringName,
588 theCommandStringFlags);
596 return refRO<PDG_AttributeString>(theLabelName,
table);
604 return refRWC<PDG_AttributeString>(
618 return refRO<PDG_AttributeString>(theCustomStateName,
table);
627 return refRWC<PDG_AttributeString>(
633 theCustomStateFlags);
641 return refRO<PDG_AttributeFloat>(theCookPercentName,
table);
650 return refRWC<PDG_AttributeFloat>(
656 theCustomStateFlags);
661 template <
typename Attribute=PDG_AttributeData>
669 if (
table == eTableCount)
670 table = isRuntime(local_ctx) ? eTableDynamic : eTableStatic;
686 template <
typename Attribute>
691 if (!canWrite(local_ctx))
715 template <
typename Attribute>
722 return refRWC<Attribute>(
724 (create ? eCreateAlways : eCreateNever),
732 template <
typename Attribute>
738 bool allow_internal_names=
false,
742 if (!canWrite(local_ctx))
751 if (
table == eTableCount)
752 table = isStatic(local_ctx) ? eTableStatic : eTableDynamic;
764 template <
typename Attribute>
767 bool overwrite_existing,
771 if (!canWrite(local_ctx))
778 isStatic(local_ctx) ? eTableStatic : eTableDynamic;
780 overwrite_existing ? eOverwriteMatch : eOverwriteNever;
784 eCreateAlways, overwrite,
false,
table, 0);
789 if (holder->isOwner())
792 ref_holder->template attribute<Attribute>());
796 holder->reset(*ref_holder,
false,
true);
812 if (!canWrite(local_ctx))
816 isStatic(local_ctx) ? eTableStatic : eTableDynamic;
823 for (
int i = table; i >= 0; i--)
825 auto&& attrib = myAttributes[i].find(src_name);
826 if (attrib != myAttributes[i].
end())
828 holder = attrib->second.get();
836 if (src_table < table)
856 auto&& iter = myAttributes[
table].find(valid);
857 if (iter != myAttributes[table].
end())
867 myAttributes[
table].erase(iter);
871 HolderPtr holder_copy =
872 UTmakeUnique<PDG_AttributeHolder>(std::move(*holder));
873 myAttributes[
table].emplace(valid, std::move(holder_copy));
874 myAttributes[
table].erase(src_name);
881 template <
typename Attribute>
898 template <
typename Attribute>
915 template <
typename Attribute>
917 const typename Attribute::Data&
value,
922 auto&&
attribute = refRW<Attribute>(
name, create, overwrite);
931 template <
typename Attribute>
937 auto&&
attribute = refRW<Attribute>(
name, create, overwrite);
946 template <
typename Attribute>
951 auto&&
attribute = refRW<Attribute>(
name, create, overwrite);
960 template <
typename Attribute>
961 bool values(
typename Attribute::Map& value_map,
966 if (isRuntime(local_ctx))
997 void startChangeTracking();
1000 ChangeResult endChangeTracking(
bool check_all);
1006 bool include_internal,
1007 bool include_unowned,
1016 bool include_internal,
1017 bool include_unowned,
1036 void onUnlock()
const;
1039 bool hashAttributes(
1043 bool include_internal,
1044 bool include_unowned,
1064 AttribTable
table)
const
1066 if (myParentMap && myParentMap->hasAttribute(name, table))
1068 return (myAttributes[table].
find(name) != myAttributes[
table].end());
1077 AttribTable src_table,
1078 AttribTable dst_table,
1079 bool flatten_dynamic);
1083 bool mergeAttribute(
1088 AttribTable dst_table);
1092 bool loadAttribute(AttribTable table,
1108 bool values(AttribTable table,
1113 myParentMap->values(table, value_map, flags);
1115 for (
auto&& attrib_pair : myAttributes[table])
1122 if (!attribToValue(value_map[attrib_pair.first], 0, holder))
1131 template <
typename Attribute>
1132 void values(AttribTable table,
1133 typename Attribute::Map& value_map,
1139 for (
auto&& attrib_pair : myAttributes[table])
1144 value_map.erase(attrib_pair.first);
1155 value_map[attrib_pair.first] = attribute->values();
1209 switch (attrib.
type())
1229 switch (attrib.
type())
1253 switch (holder.
type())
1256 return attribToValue<PDG_AttributeFloat>(
value,
index, holder);
1258 return attribToValue<PDG_AttributeInteger>(
value,
index, holder);
1260 return attribToValue<PDG_AttributeString>(
value,
index, holder);
1274 value.setValue(str);
1283 value.setValue(str);
1297 template <
typename Attribute>
1302 typename Attribute::Data temp;
1306 value.
setValue(
typename Attribute::Data());
1314 template <
typename Attribute>
1320 AttribTable table = isRuntime(local_ctx) ? eTableDynamic : eTableStatic;
1326 template <
typename Attribute>
1331 bool check_parent)
const
1334 for (
int i = table; i >= 0; i--)
1336 auto&& attrib = myAttributes[i].find(name);
1337 if (attrib != myAttributes[i].
end())
1339 holder = attrib->second.get();
1346 if (myParentMap && check_parent)
1348 return myParentMap->attribHolderR<
Attribute>(
1369 template <
typename Attribute>
1375 AttribTable src_table = eTableCount;
1379 for (
int i = table; i >= 0; i--)
1381 auto&& attrib = myAttributes[i].find(name);
1382 if (attrib != myAttributes[i].
end())
1384 holder = attrib->second.get();
1385 src_table =
static_cast<AttribTable
>(i);
1404 HolderPtr new_holder = UTmakeUnique<PDG_AttributeHolder>();
1405 new_holder->reset(*parent, parent->isOwner(),
true);
1407 name, std::move(new_holder));
1409 return insert.first->second.get();
1435 if (src_table < table)
1437 HolderPtr holder_copy = UTmakeUnique<PDG_AttributeHolder>();
1438 holder_copy->reset(*holder, holder->isOwner(),
true);
1441 name, std::move(holder_copy));
1443 return insert.first->second.get();
1455 template <
typename Attribute>
1459 OverwriteWhen overwrite,
1465 AttribTable src_table = eTableCount;
1469 for (
int i = table; i >= 0; i--)
1471 auto&& attrib = myAttributes[i].find(name);
1472 if (attrib != myAttributes[i].
end())
1474 holder = attrib->second.get();
1475 src_table =
static_cast<AttribTable
>(i);
1495 if (create == eCreateNever)
1501 HolderPtr new_holder = UTmakeUnique<PDG_AttributeHolder>();
1502 new_holder->reset(*parent, parent->isOwner(),
true);
1505 name, std::move(new_holder));
1507 return insert.first->second.get();
1511 if (create != eCreateAlways)
1517 HolderPtr holder = UTmakeUnique<PDG_AttributeHolder>(
1519 Attribute::TypeEnum,
1525 name, std::move(holder));
1527 return insert.first->second.get();
1531 if (overwrite == eOverwriteNever)
1546 bool type_match = holder->typeMatch<Attribute>();
1547 if (!type_match && (overwrite != eOverwriteAlways))
1556 if (src_table < table)
1558 if (create == eCreateNever)
1564 HolderPtr holder_copy = UTmakeUnique<PDG_AttributeHolder>();
1569 Attribute::TypeEnum,
1576 holder_copy->reset(*holder, holder->isOwner(),
true);
1579 name, std::move(holder_copy));
1581 return insert.first->second.get();
1588 new Attribute(), Attribute::TypeEnum, flags, own,
false,
false);
1595 Map myAttributes[eTableCount];
1596 Map* myStaleAttributes;
1600 bool myHasRuntimeAttribs;
A single, opaque PyObject.
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.
PDG_AttributeRef::Error setValue(const UT_StringHolder &name, const typename Attribute::Array &values, bool create, OverwriteWhen overwrite=eOverwriteMatch)
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.
PDG_AttributeRef::Error clearValues(const UT_StringHolder &name, bool create, OverwriteWhen overwrite=eOverwriteMatch)
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
Attribute values were changed or added.
GLsizei const GLfloat * value
ScopedTryLock(const PDG_AttributeMap &attribute_map)
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
PDG_AttributeRef::Error setValue(const UT_StringHolder &name, const typename Attribute::Data &value, int index, bool create, OverwriteWhen overwrite=eOverwriteMatch)
void clear()
Clears the attribute.
void swap(T &lhs, T &rhs)
std::size_t SYS_HashType
Define the type for hash values.
An array of UT_StringHolder 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.
PDG_AttributeRef::Error 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.
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].
The entire attribute map is read only.
static const UT_StringHolder theBuiltinPrefix
The requested attribute was not found - the ref is invalid.
bool value(typename Attribute::Data &value, const UT_StringHolder &name, int index, uint16 flags=0) const
No error was specified, i.e. the ref is valid.
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.
ScopedLock(const PDG_AttributeMap &attribute_map)
const UT_StringHolder & local_data() const
Never overwrite the attribute.
static const UT_StringHolder theInputFileName
An array of PDG_File values, e.g. File info structs.
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)
The requested attribute is static and was not upgraded to dynamic.
Flatten attributes, saving both dynamic and static as a mix.
PDG_ROAttributeRef< PDG_AttributeFloat > cookPercentRO(AttribTable table=eTableCount) const
Always create the attribute if it does not exist.
PDG_AttributeRef::Error rename(const UT_StringHolder &src_name, const UT_StringHolder &dst_name, bool overwrite)
Renames the specififed attribute.
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.
static const UT_StringHolder theCookPercentName
Name of the built-in cook percent attribute.
Number of attribute tables.
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.
A single PDG_ApplicationShim::Geometry instance.
GLenum GLenum GLsizei void * table
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
An array of fpreal values.
PDG_RWAttributeRef< Attribute > refRW(const UT_StringHolder &name, bool create, OverwriteWhen overwrite=eOverwriteMatch, uint16 flags=0)
PDG_AttributeType
Enumeration of possible attribute types.
GLenum GLsizei GLsizei GLint * values
PDG_RWAttributeRef< PDG_AttributeString > stateRW(CreateWhen create=eCreateNever, AttribTable table=eTableCount)
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
Only overwrite the attribute if the type matches.
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
SaveType
Save operation to perform.
const Attribute * attribute() const
Const accessor for the own attribute - could be nullptr.
PDG_RWAttributeRef< PDG_AttributeFile > inputFileRW(CreateWhen create=eCreateNever, AttribTable table=eTableCount)
Returns a read/write handle to the standard input file attribute.
PDG_ROAttributeRef< PDG_AttributeFile > inputFileRO(AttribTable table=eTableCount) const
Returns a read-only handle to the standard input file attribute.
PDG_RWAttributeRef< Attribute > refRWC(const UT_StringHolder &name, CreateWhen create=eCreateNever, OverwriteWhen overwrite=eOverwriteMatch, AttribTable table=eTableCount, bool allow_internal_names=false, uint16 flags=0)
Same as above, but with greater control on the creation flags.
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
static const UT_StringHolder theCommandStringName
Name of the built-in command attribute.
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter