Commit: 2b805f0ae8cc12e3a1dc5a85017784db137efd1b
Author: Jacques Lucke
Date: Fri Nov 1 19:30:31 2019 +0100
Branches: functions-experimental-refactor
https://developer.blender.org/rB2b805f0ae8cc12e3a1dc5a85017784db137efd1b
move multi functions to functions2
===================================================================
M source/blender/functions2/CMakeLists.txt
A source/blender/functions2/FN_multi_function.h
A source/blender/functions2/FN_multi_functions.h
A source/blender/functions2/intern/multi_functions/lists.cc
A source/blender/functions2/intern/multi_functions/lists.h
A source/blender/functions2/intern/multi_functions/mixed.cc
A source/blender/functions2/intern/multi_functions/mixed.h
===================================================================
diff --git a/source/blender/functions2/CMakeLists.txt
b/source/blender/functions2/CMakeLists.txt
index dd8c1fbeaa3..b99b3051e22 100644
--- a/source/blender/functions2/CMakeLists.txt
+++ b/source/blender/functions2/CMakeLists.txt
@@ -22,6 +22,8 @@ if(WITH_PYTHON)
endif()
set(SRC
+ intern/multi_functions/lists.cc
+ intern/multi_functions/mixed.cc
intern/cpp_type.cc
intern/cpp_types.cc
intern/initialize.cc
@@ -32,7 +34,11 @@ set(SRC
FN_generic_virtual_list_list_ref.h
FN_generic_virtual_list_ref.h
FN_initialize.h
+ FN_multi_function.h
+ FN_multi_functions.h
+ intern/multi_functions/lists.h
+ intern/multi_functions/mixed.h
intern/cpp_types.h
)
diff --git a/source/blender/functions2/FN_multi_function.h
b/source/blender/functions2/FN_multi_function.h
new file mode 100644
index 00000000000..c8b7d0359c1
--- /dev/null
+++ b/source/blender/functions2/FN_multi_function.h
@@ -0,0 +1,656 @@
+#ifndef __FN_MULTI_FUNCTION_H__
+#define __FN_MULTI_FUNCTION_H__
+
+#include "FN_generic_array_ref.h"
+#include "FN_generic_vector_array.h"
+#include "FN_generic_virtual_list_ref.h"
+#include "FN_generic_virtual_list_list_ref.h"
+
+#include "BLI_vector.h"
+
+namespace FN {
+
+using BLI::Vector;
+
+struct MFDataType {
+ public:
+ enum Category {
+ None,
+ Single,
+ Vector,
+ };
+
+ MFDataType() = default;
+
+ MFDataType(Category category, const CPPType &type) : m_category(category),
m_base_type(&type)
+ {
+ }
+
+ template<typename T> static MFDataType ForSingle()
+ {
+ return MFDataType(Category::Single, GET_TYPE<T>());
+ }
+
+ template<typename T> static MFDataType ForVector()
+ {
+ return MFDataType(Category::Vector, GET_TYPE<T>());
+ }
+
+ bool is_none() const
+ {
+ return m_category == Category::None;
+ }
+
+ bool is_single() const
+ {
+ return m_category == Category::Single;
+ }
+
+ bool is_vector() const
+ {
+ return m_category == Category::Vector;
+ }
+
+ Category category() const
+ {
+ return m_category;
+ }
+
+ const CPPType &type() const
+ {
+ BLI_assert(m_category == Category::Single);
+ return *m_base_type;
+ }
+
+ const CPPType &base_type() const
+ {
+ BLI_assert(m_category == Category::Vector);
+ return *m_base_type;
+ }
+
+ friend bool operator==(MFDataType a, MFDataType b)
+ {
+ return a.m_category == b.m_category && a.m_base_type == b.m_base_type;
+ }
+
+ friend bool operator!=(MFDataType a, MFDataType b)
+ {
+ return !(a == b);
+ }
+
+ private:
+ Category m_category = Category::None;
+ const CPPType *m_base_type = nullptr;
+};
+
+struct MFParamType {
+ public:
+ enum Category {
+ None,
+ ReadonlySingleInput,
+ SingleOutput,
+ ReadonlyVectorInput,
+ VectorOutput,
+ MutableVector,
+ };
+
+ MFParamType(Category category, const CPPType *base_type = nullptr)
+ : m_category(category), m_base_type(base_type)
+ {
+ }
+
+ bool is_none() const
+ {
+ return m_category == MFParamType::None;
+ }
+
+ bool is_readonly_single_input() const
+ {
+ return m_category == ReadonlySingleInput;
+ }
+
+ bool is_readonly_vector_input() const
+ {
+ return m_category == ReadonlyVectorInput;
+ }
+
+ bool is_mutable_vector() const
+ {
+ return m_category == MutableVector;
+ }
+
+ bool is_single_output() const
+ {
+ return m_category == SingleOutput;
+ }
+
+ bool is_input_or_mutable() const
+ {
+ return ELEM(m_category, ReadonlySingleInput, ReadonlyVectorInput,
MutableVector);
+ }
+
+ bool is_output_or_mutable() const
+ {
+ return ELEM(m_category, SingleOutput, VectorOutput, MutableVector);
+ }
+
+ bool is_vector_output() const
+ {
+ return m_category == VectorOutput;
+ }
+
+ MFDataType as_data_type() const
+ {
+ switch (m_category) {
+ case None:
+ return {};
+ case ReadonlySingleInput:
+ case SingleOutput:
+ return {MFDataType::Single, *m_base_type};
+ case ReadonlyVectorInput:
+ case VectorOutput:
+ case MutableVector:
+ return {MFDataType::Vector, *m_base_type};
+ }
+ BLI_assert(false);
+ return {};
+ }
+
+ Category category() const
+ {
+ return m_category;
+ }
+
+ const CPPType &type() const
+ {
+ BLI_assert(ELEM(m_category, Category::ReadonlySingleInput,
Category::SingleOutput));
+ return *m_base_type;
+ }
+
+ const CPPType &base_type() const
+ {
+ BLI_assert(ELEM(m_category,
+ Category::ReadonlyVectorInput,
+ Category::VectorOutput,
+ Category::MutableVector));
+ return *m_base_type;
+ }
+
+ private:
+ Category m_category = Category::None;
+ const CPPType *m_base_type = nullptr;
+};
+
+class MFMask {
+ private:
+ ArrayRef<uint> m_indices;
+
+ public:
+ MFMask(ArrayRef<uint> indices) : m_indices(indices)
+ {
+#ifdef DEBUG
+ for (uint i = 1; i < indices.size(); i++) {
+ BLI_assert(indices[i - 1] < indices[i]);
+ }
+#endif
+ }
+
+ uint indices_amount() const
+ {
+ return m_indices.size();
+ }
+
+ uint min_array_size() const
+ {
+ return (m_indices.size() == 0) ? 0 : m_indices.last() + 1;
+ }
+
+ ArrayRef<uint> indices() const
+ {
+ return m_indices;
+ }
+
+ bool is_range() const
+ {
+ return m_indices.size() > 0 && m_indices.last() - m_indices.first() ==
m_indices.size() - 1;
+ }
+
+ IndexRange as_range() const
+ {
+ BLI_assert(this->is_range());
+ return IndexRange{m_indices.first(), m_indices.size()};
+ }
+
+ template<typename FuncT> void foreach_index(const FuncT &func) const
+ {
+ if (this->is_range()) {
+ IndexRange range = this->as_range();
+ for (uint i : range) {
+ func(i);
+ }
+ }
+ else {
+ for (uint i : m_indices) {
+ func(i);
+ }
+ }
+ }
+};
+
+class MFContext {
+};
+
+class MFSignature {
+ private:
+ std::string m_function_name;
+ Vector<std::string> m_param_names;
+ Vector<MFParamType> m_param_types;
+ Vector<uint> m_params_with_external_dependencies;
+ Vector<uint> m_corrected_indices;
+
+ friend class MultiFunction;
+
+ public:
+ MFSignature() = default;
+
+ MFSignature(std::string function_name,
+ Vector<std::string> param_names,
+ Vector<MFParamType> param_types,
+ Vector<uint> params_with_external_dependencies)
+ : m_function_name(std::move(function_name)),
+ m_param_names(std::move(param_names)),
+ m_param_types(std::move(param_types)),
+
m_params_with_external_dependencies(std::move(params_with_external_dependencies))
+ {
+ uint array_or_single_refs = 0;
+ uint mutable_array_refs = 0;
+ uint virtual_list_list_refs = 0;
+ uint vector_arrays = 0;
+ for (MFParamType param_type : m_param_types) {
+ uint corrected_index = 0;
+ switch (param_type.category()) {
+ case MFParamType::None:
+ BLI_assert(false);
+ break;
+ case MFParamType::ReadonlySingleInput:
+ corrected_index = array_or_single_refs++;
+ break;
+ case MFParamType::SingleOutput:
+ corrected_index = mutable_array_refs++;
+ break;
+ case MFParamType::ReadonlyVectorInput:
+ corrected_index = virtual_list_list_refs++;
+ break;
+ case MFParamType::VectorOutput:
+ case MFParamType::MutableVector:
+ corrected_index = vector_arrays++;
+ break;
+ }
+ m_corrected_indices.append(corrected_index);
+ }
+ }
+
+ ArrayRef<MFParamType> param_types() const
+ {
+ return m_param_types;
+ }
+
+ uint get_corrected_index(uint index) const
+ {
+ return m_corrected_indices[index];
+ }
+
+ template<typename T> bool is_readonly_single_input(uint index, StringRef
name) const
+ {
+ return this->is_valid_param<T>(index, name,
MFParamType::ReadonlySingleInput);
+ }
+ bool is_readonly_single_input(uint index, StringRef name) const
+ {
+ return this->is_valid_param(index, name, MFParamType::ReadonlySingleInput);
+ }
+
+ template<typename T> bool is_single_output(uint index, StringRef name) const
+ {
+ return this->is_valid_param<T>(index, name, MFParamType::SingleOutput);
+ }
+ bool is_single_output(uint index, StringRef name) const
+ {
+ return this->is_valid_param(index, name, MFParamType::SingleOutput);
+ }
+
+ template<typename T> bool is_readonly_vector_input(uint index, StringRef
name) const
+ {
+ return this->is_valid_param<T>(index, name,
MFParamType::ReadonlyVectorInput);
+ }
+ bool is_readonly_vector_input(uint index, StringRef name) const
+ {
+ return this->is_valid_param(index, name, MFParamType::ReadonlyVectorInput);
+ }
+
+ template<typename T> bool is_vector_output(uint index, StringRef name) const
+ {
+ return this->is_valid_param<T>(index, name, MFParamType::VectorOutput);
+ }
+ bool is_vector_output(uint index, StringRef name) const
+ {
+ return this->is_valid_param(index, name, MFParamType::VectorOutput);
+ }
+
+ bool is_mutable_vector(uint index, StringRef name) const
+ {
+ return this->is_valid_param(index, name, MFParamType::MutableVector);
+ }
+
+ private:
+ template<typename T>
+ bool is_valid_param(uint index, StringRef name, MFParamType::Category
category) const
+ {
+ if (!this->is_valid_param(index, name, category)) {
+ return false;
+ }
+ else if (ELEM(category, MFParamType::ReadonlySingleInput,
MFParamType::SingleOutput)) {
+ return
GET_TYPE<T>().is_same_or_generalization(m_param_types[index].type());
+ }
+ else if (ELEM(category,
+ MFParamType::ReadonlyVectorInput,
+ MFParamType::VectorOutput,
+ MFParamType::MutableVector)) {
+ return
GET_TYPE<T>().is_same_or_generalization(m_param_types[index].base_type());
+ }
+ else {
+ return false;
+ }
+ }
+
+ bool is_valid_param(uint index, StringRef name, MFParamType::Category
category) const
+ {
+ return m_param_names[index] == name && m_param_types[index].category() ==
category;
+ }
+};
+
+class MFSignatureBuilder {
+ private:
+ std::string m_function_name;
+ Vector<std::string> m_param_names;
+ Vector<MFParamType> m_param_types;
+ Vector<uint> m_params_with_external_dependencies;
+
+ public:
+ MFSignatureBuilder(S
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs