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-09-08 16:47:45 +0300
committerJacques Lucke <jacques@blender.org>2021-09-08 16:47:45 +0300
commit068f0122213b1574ccad7ec1335969ad65bbf0d2 (patch)
tree67a8f0759f991ff9fd215eddf1a0a40f094c4d75 /source/blender/functions
parentcffd4a7ccf7dcf0d92d1b2392ac5adba9a965cdb (diff)
initial commit
Diffstat (limited to 'source/blender/functions')
-rw-r--r--source/blender/functions/FN_generic_virtual_array.hh46
-rw-r--r--source/blender/functions/FN_multi_function_parallel.hh24
-rw-r--r--source/blender/functions/intern/generic_virtual_array.cc39
3 files changed, 109 insertions, 0 deletions
diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh
index f429243e2de..b883db6fa31 100644
--- a/source/blender/functions/FN_generic_virtual_array.hh
+++ b/source/blender/functions/FN_generic_virtual_array.hh
@@ -911,4 +911,50 @@ template<typename T> class GVMutableArray_Typed {
}
};
+class GVArray_For_SlicedGVArray : public GVArray {
+ protected:
+ const GVArray &varray_;
+ int64_t offset_;
+
+ public:
+ GVArray_For_SlicedGVArray(const GVArray &varray, const IndexRange slice)
+ : GVArray(varray.type(), slice.size()), varray_(varray), offset_(slice.start())
+ {
+ BLI_assert(slice.one_after_last() <= varray.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;
+};
+
+/**
+ * Utility class to create the "best" sliced virtual array.
+ */
+class GVArray_Slice {
+ private:
+ const GVArray *varray_;
+ /* Of these optional virtual arrays, at most one is constructed at any time. */
+ std::optional<GVArray_For_GSpan> varray_span_;
+ std::optional<GVArray_For_SingleValue> varray_single_;
+ std::optional<GVArray_For_SlicedGVArray> varray_any_;
+
+ public:
+ GVArray_Slice(const GVArray &varray, const IndexRange slice);
+
+ const GVArray &operator*()
+ {
+ return *varray_;
+ }
+
+ const GVArray *operator->()
+ {
+ return varray_;
+ }
+
+ operator const GVArray &()
+ {
+ return *varray_;
+ }
+};
+
} // namespace blender::fn
diff --git a/source/blender/functions/FN_multi_function_parallel.hh b/source/blender/functions/FN_multi_function_parallel.hh
new file mode 100644
index 00000000000..b5b3e2f2f94
--- /dev/null
+++ b/source/blender/functions/FN_multi_function_parallel.hh
@@ -0,0 +1,24 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+/** \file
+ * \ingroup fn
+ */
+
+namespace blender::fn {
+}
diff --git a/source/blender/functions/intern/generic_virtual_array.cc b/source/blender/functions/intern/generic_virtual_array.cc
index bd033a429de..a3096417212 100644
--- a/source/blender/functions/intern/generic_virtual_array.cc
+++ b/source/blender/functions/intern/generic_virtual_array.cc
@@ -387,4 +387,43 @@ void GVMutableArray_GSpan::disable_not_applied_warning()
show_not_saved_warning_ = false;
}
+/* --------------------------------------------------------------------
+ * GVArray_For_SlicedGVArray.
+ */
+
+void GVArray_For_SlicedGVArray::get_impl(const int64_t index, void *r_value) const
+{
+ varray_.get(index + offset_, r_value);
+}
+
+void GVArray_For_SlicedGVArray::get_to_uninitialized_impl(const int64_t index, void *r_value) const
+{
+ varray_.get_to_uninitialized(index + offset_, r_value);
+}
+
+/* --------------------------------------------------------------------
+ * GVArray_Slice.
+ */
+
+GVArray_Slice::GVArray_Slice(const GVArray &varray, const IndexRange slice)
+{
+ const CPPType &type = varray.type();
+ if (varray.is_span()) {
+ const GSpan span = varray.get_internal_span();
+ varray_span_.emplace(span.slice(slice.start(), slice.size()));
+ varray_ = &*varray_span_;
+ }
+ else if (varray.is_single()) {
+ BUFFER_FOR_CPP_TYPE_VALUE(type, buffer);
+ varray_->get_internal_single_to_uninitialized(buffer);
+ varray_single_.emplace(type, slice.size(), buffer);
+ type.destruct(buffer);
+ varray_ = &*varray_single_;
+ }
+ else {
+ varray_any_.emplace(varray, slice);
+ varray_ = &*varray_any_;
+ }
+}
+
} // namespace blender::fn