Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-01-13 12:48:39 +0300
committerJacques Lucke <jacques@blender.org>2021-01-13 12:48:39 +0300
commit614bd239f85292a8ca6ca454b48f4a1342316252 (patch)
tree775b1b0341cf40c053f7990fb58070bf2484960f /source/blender/blenkernel/BKE_attribute_access.hh
parent7b68d0679e98b3b4ef981d00df0293940675fed8 (diff)
Geometry Nodes: support optional ownership for typed attributes
This will simplify some code in an upcoming commit and will be useful for T83793.
Diffstat (limited to 'source/blender/blenkernel/BKE_attribute_access.hh')
-rw-r--r--source/blender/blenkernel/BKE_attribute_access.hh30
1 files changed, 22 insertions, 8 deletions
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>());
}