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:
Diffstat (limited to 'source/blender/functions/FN_multi_function_builder.hh')
-rw-r--r--source/blender/functions/FN_multi_function_builder.hh77
1 files changed, 77 insertions, 0 deletions
diff --git a/source/blender/functions/FN_multi_function_builder.hh b/source/blender/functions/FN_multi_function_builder.hh
index abc1e5d0723..6e7efb21850 100644
--- a/source/blender/functions/FN_multi_function_builder.hh
+++ b/source/blender/functions/FN_multi_function_builder.hh
@@ -203,6 +203,61 @@ template<typename Mut1> class CustomMF_SM : public MultiFunction {
};
/**
+ * Generates a multi-function that converts between two types.
+ */
+template<typename From, typename To> class CustomMF_Convert : public MultiFunction {
+ public:
+ CustomMF_Convert()
+ {
+ std::string name = CPPType::get<From>().name() + " to " + CPPType::get<To>().name();
+ MFSignatureBuilder signature = this->get_builder(std::move(name));
+ signature.single_input<From>("Input");
+ signature.single_output<To>("Output");
+ }
+
+ void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
+ {
+ VSpan<From> inputs = params.readonly_single_input<From>(0);
+ MutableSpan<To> outputs = params.uninitialized_single_output<To>(1);
+
+ for (uint i : mask) {
+ new ((void *)&outputs[i]) To(inputs[i]);
+ }
+ }
+};
+
+/**
+ * A multi-function that outputs the same value every time. The value is not owned by an instance
+ * of this function. The caller is responsible for destructing and freeing the value.
+ */
+class CustomMF_GenericConstant : public MultiFunction {
+ private:
+ const CPPType &type_;
+ const void *value_;
+
+ template<typename T> friend class CustomMF_Constant;
+
+ public:
+ CustomMF_GenericConstant(const CPPType &type, const void *value);
+ void call(IndexMask mask, MFParams params, MFContext context) const override;
+ uint32_t hash() const override;
+ bool equals(const MultiFunction &other) const override;
+};
+
+/**
+ * A multi-function that outputs the same array every time. The array is not owned by in instance
+ * of this function. The caller is responsible for destructing and freeing the values.
+ */
+class CustomMF_GenericConstantArray : public MultiFunction {
+ private:
+ GSpan array_;
+
+ public:
+ CustomMF_GenericConstantArray(GSpan array);
+ void call(IndexMask mask, MFParams params, MFContext context) const override;
+};
+
+/**
* Generates a multi-function that outputs a constant value.
*/
template<typename T> class CustomMF_Constant : public MultiFunction {
@@ -223,6 +278,28 @@ template<typename T> class CustomMF_Constant : public MultiFunction {
MutableSpan<T> output = params.uninitialized_single_output<T>(0);
mask.foreach_index([&](uint i) { new (&output[i]) T(value_); });
}
+
+ uint32_t hash() const override
+ {
+ return DefaultHash<T>{}(value_);
+ }
+
+ bool equals(const MultiFunction &other) const override
+ {
+ const CustomMF_Constant *other1 = dynamic_cast<const CustomMF_Constant *>(&other);
+ if (other1 != nullptr) {
+ return value_ == other1->value_;
+ }
+ const CustomMF_GenericConstant *other2 = dynamic_cast<const CustomMF_GenericConstant *>(
+ &other);
+ if (other2 != nullptr) {
+ const CPPType &type = CPPType::get<T>();
+ if (type == other2->type_) {
+ return type.is_equal((const void *)&value_, other2->value_);
+ }
+ }
+ return false;
+ }
};
} // namespace blender::fn