Geometry Nodes: support optional ownership for typed attributes

This will simplify some code in an upcoming commit and will be
useful for T83793.
This commit is contained in:
Jacques Lucke 2021-01-13 10:48:39 +01:00
parent 7b68d0679e
commit 614bd239f8
1 changed files with 22 additions and 8 deletions

View File

@ -187,15 +187,22 @@ class WriteAttribute {
using ReadAttributePtr = std::unique_ptr<ReadAttribute>;
using WriteAttributePtr = std::unique_ptr<WriteAttribute>;
/* This provides type safe access to an attribute. */
/* This provides type safe access to an attribute.
* The underlying ReadAttribute is owned optionally. */
template<typename T> class TypedReadAttribute {
private:
ReadAttributePtr attribute_;
std::unique_ptr<ReadAttribute> owned_attribute_;
ReadAttribute *attribute_;
public:
TypedReadAttribute(ReadAttributePtr attribute) : attribute_(std::move(attribute))
TypedReadAttribute(ReadAttributePtr attribute) : TypedReadAttribute(*attribute)
{
owned_attribute_ = std::move(attribute);
BLI_assert(owned_attribute_);
}
TypedReadAttribute(ReadAttribute &attribute) : attribute_(&attribute)
{
BLI_assert(attribute_);
BLI_assert(attribute_->cpp_type().is<T>());
}
@ -220,15 +227,22 @@ template<typename T> class TypedReadAttribute {
}
};
/* This provides type safe access to an attribute. */
/* This provides type safe access to an attribute.
* The underlying WriteAttribute is owned optionally. */
template<typename T> class TypedWriteAttribute {
private:
WriteAttributePtr attribute_;
std::unique_ptr<WriteAttribute> owned_attribute_;
WriteAttribute *attribute_;
public:
TypedWriteAttribute(WriteAttributePtr attribute) : attribute_(std::move(attribute))
TypedWriteAttribute(WriteAttributePtr attribute) : TypedWriteAttribute(*attribute)
{
owned_attribute_ = std::move(attribute);
BLI_assert(owned_attribute_);
}
TypedWriteAttribute(WriteAttribute &attribute) : attribute_(&attribute)
{
BLI_assert(attribute_);
BLI_assert(attribute_->cpp_type().is<T>());
}