[Bf-blender-cvs] [e439cc5e693] virtual-array-attributes: add GVArray_For_SingleValue

Jacques Lucke noreply at git.blender.org
Mon Apr 12 18:27:55 CEST 2021


Commit: e439cc5e693a954ff94a6d68b0d948ef57e6a18e
Author: Jacques Lucke
Date:   Sat Apr 10 18:48:44 2021 +0200
Branches: virtual-array-attributes
https://developer.blender.org/rBe439cc5e693a954ff94a6d68b0d948ef57e6a18e

add GVArray_For_SingleValue

===================================================================

M	source/blender/functions/FN_generic_virtual_array.hh
M	source/blender/functions/intern/generic_virtual_array.cc

===================================================================

diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh
index 60b8ba0002f..55b4d09a707 100644
--- a/source/blender/functions/FN_generic_virtual_array.hh
+++ b/source/blender/functions/FN_generic_virtual_array.hh
@@ -268,8 +268,8 @@ class GVMutableArray_For_GMutableSpan : public GVMutableArray {
 };
 
 class GVArray_For_SingleValueRef : public GVArray {
- private:
-  const void *value_;
+ protected:
+  const void *value_ = nullptr;
 
  public:
   GVArray_For_SingleValueRef(const CPPType &type, const int64_t size, const void *value)
@@ -278,6 +278,10 @@ class GVArray_For_SingleValueRef : public GVArray {
   }
 
  protected:
+  GVArray_For_SingleValueRef(const CPPType &type, const int64_t size) : GVArray(type, size)
+  {
+  }
+
   void get_impl(const int64_t index, void *r_value) const override;
   void get_to_uninitialized_impl(const int64_t index, void *r_value) const override;
 
@@ -288,6 +292,12 @@ class GVArray_For_SingleValueRef : public GVArray {
   void get_single_impl(void *r_value) const override;
 };
 
+class GVArray_For_SingleValue : public GVArray_For_SingleValueRef {
+ public:
+  GVArray_For_SingleValue(const CPPType &type, const int64_t size, const void *value);
+  ~GVArray_For_SingleValue();
+};
+
 template<typename T> class GVArray_For_VArray : public GVArray {
  private:
   const VArray<T> *varray_ = nullptr;
diff --git a/source/blender/functions/intern/generic_virtual_array.cc b/source/blender/functions/intern/generic_virtual_array.cc
index 73e2d702a38..e5200567712 100644
--- a/source/blender/functions/intern/generic_virtual_array.cc
+++ b/source/blender/functions/intern/generic_virtual_array.cc
@@ -156,4 +156,23 @@ void GVArray_For_SingleValueRef::get_single_impl(void *r_value) const
   type_->copy_to_initialized(value_, r_value);
 }
 
+/* --------------------------------------------------------------------
+ * GVArray_For_SingleValue.
+ */
+
+GVArray_For_SingleValue::GVArray_For_SingleValue(const CPPType &type,
+                                                 const int64_t size,
+                                                 const void *value)
+    : GVArray_For_SingleValueRef(type, size)
+{
+  value_ = MEM_mallocN_aligned(type.size(), type.alignment(), __func__);
+  type.copy_to_uninitialized(value, (void *)value_);
+}
+
+GVArray_For_SingleValue::~GVArray_For_SingleValue()
+{
+  type_->destruct((void *)value_);
+  MEM_freeN((void *)value_);
+}
+
 }  // namespace blender::fn



More information about the Bf-blender-cvs mailing list