[Bf-blender-cvs] [614bd239f85] master: Geometry Nodes: support optional ownership for typed attributes
Jacques Lucke
noreply at git.blender.org
Wed Jan 13 10:48:52 CET 2021
Commit: 614bd239f85292a8ca6ca454b48f4a1342316252
Author: Jacques Lucke
Date: Wed Jan 13 10:48:39 2021 +0100
Branches: master
https://developer.blender.org/rB614bd239f85292a8ca6ca454b48f4a1342316252
Geometry Nodes: support optional ownership for typed attributes
This will simplify some code in an upcoming commit and will be
useful for T83793.
===================================================================
M source/blender/blenkernel/BKE_attribute_access.hh
===================================================================
diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh
index 131656136f1..0c980178ffa 100644
--- a/source/blender/blenkernel/BKE_attribute_access.hh
+++ b/source/blender/blenkernel/BKE_attribute_access.hh
@@ -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>());
}
More information about the Bf-blender-cvs
mailing list