12 #ifndef OPENVDB_AX_COMPILER_CUSTOM_DATA_HAS_BEEN_INCLUDED 13 #define OPENVDB_AX_COMPILER_CUSTOM_DATA_HAS_BEEN_INCLUDED 15 #include <openvdb/version.h> 19 #include <unordered_map> 37 using Ptr = std::shared_ptr<CustomData>;
38 using ConstPtr = std::shared_ptr<const CustomData>;
61 const auto iter = mData.find(name);
62 return (iter != mData.end());
66 template <
typename TypedDataCacheT>
70 const auto iter = mData.find(name);
71 if (iter == mData.end())
return false;
72 const TypedDataCacheT*
const typed =
73 dynamic_cast<const TypedDataCacheT* const
>(iter->second.get());
74 return typed !=
nullptr;
82 const auto iter = mData.find(name);
91 template <
typename TypedDataCacheT>
92 inline const TypedDataCacheT*
96 if (!data)
return nullptr;
97 const TypedDataCacheT*
const typed =
98 dynamic_cast<const TypedDataCacheT* const
>(data.get());
106 template <
typename TypedDataCacheT>
107 inline TypedDataCacheT*
110 const auto iter = mData.find(name);
111 if (iter == mData.end()) {
114 return static_cast<TypedDataCacheT* const
>(data.get());
117 return dynamic_cast<TypedDataCacheT* const
>(iter->second.get());
126 template <
typename TypedDataCacheT>
129 const typename TypedDataCacheT::Ptr data)
132 TypedDataCacheT*
const dataToSet =
133 getOrInsertData<TypedDataCacheT>(name);
136 "\" already exists with a different type.");
138 dataToSet->value() = data->value();
141 mData[name] = data->copy();
154 const auto iter = mData.find(name);
155 if (iter == mData.end()) {
159 iter->second->copy(*data);
164 std::unordered_map<Name, Metadata::Ptr> mData;
168 namespace codegen {
struct String; }
169 using AXStringMetadata [[deprecated(
"The ax::AXStringMetadata type has " 170 "been replaced with openvdb::TypedMetadata<ax::codegen::String>. The " 171 "new backend string definition can be found in ax/codegen/String.h")]] =
172 TypedMetadata<ax::codegen::String>;
178 #endif // OPENVDB_AX_COMPILER_CUSTOM_DATA_HAS_BEEN_INCLUDED bool hasData(const Name &name)
Checks whether or not data of given name and type has been inserted.
Definition: CustomData.h:68
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
TypedDataCacheT * getOrInsertData(const Name &name)
Retrieves or inserts typed metadata. If the data exists, it is dynamic-casted to the expected type...
Definition: CustomData.h:108
static UniquePtr create()
Definition: CustomData.h:43
The custom data class is a simple container for named openvdb metadata. Its primary use case is passi...
Definition: CustomData.h:33
const Metadata::ConstPtr getData(const Name &name) const
Retrieves a const pointer to data of given name. If it does not exist, returns nullptr.
Definition: CustomData.h:80
std::shared_ptr< const CustomData > ConstPtr
Definition: CustomData.h:38
std::unique_ptr< CustomData > UniquePtr
Definition: CustomData.h:39
void insertData(const Name &name, const Metadata::Ptr data)
Inserts data with given name.
Definition: CustomData.h:151
Definition: Exceptions.h:13
std::shared_ptr< CustomData > Ptr
Definition: CustomData.h:37
void insertData(const Name &name, const typename TypedDataCacheT::Ptr data)
Inserts data of specified type with given name.
Definition: CustomData.h:128
Definition: Exceptions.h:64
void reset()
Reset the custom data. This will clear and delete all previously added data. This will invalidated an...
Definition: CustomData.h:52
bool hasData(const Name &name)
Checks whether or not data of given name has been inserted.
Definition: CustomData.h:59
std::string Name
Definition: Name.h:19
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
const TypedDataCacheT * getData(const Name &name) const
Retrieves a const pointer to data of given name and type. If it does not exist, returns nullptr...
Definition: CustomData.h:93
CustomData()
Definition: CustomData.h:41
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218