[Bf-blender-cvs] [4be6da25863] virtual-array-attributes: generic mutable array

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


Commit: 4be6da258639a088ea2d901b2c54c848be963d50
Author: Jacques Lucke
Date:   Sat Apr 10 16:01:23 2021 +0200
Branches: virtual-array-attributes
https://developer.blender.org/rB4be6da258639a088ea2d901b2c54c848be963d50

generic mutable array

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

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 c6230730a8d..d2262e41dee 100644
--- a/source/blender/functions/FN_generic_virtual_array.hh
+++ b/source/blender/functions/FN_generic_virtual_array.hh
@@ -136,6 +136,58 @@ class GVArray {
   virtual void get_single_impl(void *UNUSED(r_value)) const;
 };
 
+class GVMutableArray : public GVArray {
+ public:
+  GVMutableArray(const CPPType &type, const int64_t size) : GVArray(type, size)
+  {
+  }
+
+  void set_by_copy(const int64_t index, const void *value)
+  {
+    BLI_assert(index >= 0);
+    BLI_assert(index < size_);
+    this->set_by_copy_impl(index, value);
+  }
+
+  void set_by_move(const int64_t index, void *value)
+  {
+    BLI_assert(index >= 0);
+    BLI_assert(index < size_);
+    this->set_by_move_impl(index, value);
+  }
+
+  void set_by_relocate(const int64_t index, void *value)
+  {
+    BLI_assert(index >= 0);
+    BLI_assert(index < size_);
+    this->set_by_relocate_impl(index, value);
+  }
+
+  GMutableSpan get_span()
+  {
+    BLI_assert(this->is_span());
+    GSpan span = static_cast<const GVArray *>(this)->get_span();
+    return GMutableSpan(span.type(), const_cast<void *>(span.data()), span.size());
+  }
+
+ protected:
+  virtual void set_by_copy_impl(const int64_t index, const void *value)
+  {
+    BUFFER_FOR_CPP_TYPE_VALUE(*type_, buffer);
+    type_->copy_to_uninitialized(value, buffer);
+    this->set_by_move_impl(index, buffer);
+    type_->destruct(buffer);
+  }
+
+  virtual void set_by_relocate_impl(const int64_t index, void *value)
+  {
+    this->set_by_move_impl(index, value);
+    type_->destruct(value);
+  }
+
+  virtual void set_by_move_impl(const int64_t index, void *value) = 0;
+};
+
 class GVArrayForGSpan : public GVArray {
  protected:
   const void *data_;
@@ -168,6 +220,31 @@ class GVArrayForEmpty : public GVArray {
   }
 };
 
+class GVMutableArrayForGMutableSpan : public GVMutableArray {
+ protected:
+  void *data_;
+  const int64_t element_size_;
+
+ public:
+  GVMutableArrayForGMutableSpan(const GMutableSpan span)
+      : GVMutableArray(span.type(), span.size()),
+        data_(span.data()),
+        element_size_(span.type().size())
+  {
+  }
+
+ protected:
+  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;
+
+  void set_by_copy_impl(const int64_t index, const void *value) override;
+  void set_by_move_impl(const int64_t index, void *value) override;
+  void set_by_relocate_impl(const int64_t index, void *value) override;
+
+  bool is_span_impl() const override;
+  GSpan get_span_impl() const override;
+};
+
 class GVArrayForSingleValueRef : public GVArray {
  private:
   const void *value_;
diff --git a/source/blender/functions/intern/generic_virtual_array.cc b/source/blender/functions/intern/generic_virtual_array.cc
index 9380eb257b2..f94380be7dc 100644
--- a/source/blender/functions/intern/generic_virtual_array.cc
+++ b/source/blender/functions/intern/generic_virtual_array.cc
@@ -73,6 +73,42 @@ GSpan GVArrayForGSpan::get_span_impl() const
   return GSpan(*type_, data_, size_);
 }
 
+void GVMutableArrayForGMutableSpan::get_impl(const int64_t index, void *r_value) const
+{
+  type_->copy_to_initialized(POINTER_OFFSET(data_, element_size_ * index), r_value);
+}
+
+void GVMutableArrayForGMutableSpan::get_to_uninitialized_impl(const int64_t index,
+                                                              void *r_value) const
+{
+  type_->copy_to_uninitialized(POINTER_OFFSET(data_, element_size_ * index), r_value);
+}
+
+void GVMutableArrayForGMutableSpan::set_by_copy_impl(const int64_t index, const void *value)
+{
+  type_->copy_to_initialized(value, POINTER_OFFSET(data_, element_size_ * index));
+}
+
+void GVMutableArrayForGMutableSpan::set_by_move_impl(const int64_t index, void *value)
+{
+  type_->move_to_initialized(value, POINTER_OFFSET(data_, element_size_ * index));
+}
+
+void GVMutableArrayForGMutableSpan::set_by_relocate_impl(const int64_t index, void *value)
+{
+  type_->relocate_to_initialized(value, POINTER_OFFSET(data_, element_size_ * index));
+}
+
+bool GVMutableArrayForGMutableSpan::is_span_impl() const
+{
+  return true;
+}
+
+GSpan GVMutableArrayForGMutableSpan::get_span_impl() const
+{
+  return GSpan(*type_, data_, size_);
+}
+
 void GVArrayForSingleValueRef::get_impl(const int64_t UNUSED(index), void *r_value) const
 {
   type_->copy_to_initialized(value_, r_value);



More information about the Bf-blender-cvs mailing list