[Bf-blender-cvs] [f1fc372df13] functions: move constant functions to separate file
Jacques Lucke
noreply at git.blender.org
Thu Jan 9 18:17:28 CET 2020
Commit: f1fc372df137d292598ae118964cd8fb43bf50f2
Author: Jacques Lucke
Date: Thu Jan 9 17:20:33 2020 +0100
Branches: functions
https://developer.blender.org/rBf1fc372df137d292598ae118964cd8fb43bf50f2
move constant functions to separate file
===================================================================
M source/blender/functions/CMakeLists.txt
M source/blender/functions/FN_multi_functions.h
A source/blender/functions/intern/multi_functions/constants.cc
A source/blender/functions/intern/multi_functions/constants.h
M source/blender/functions/intern/multi_functions/customizable.h
===================================================================
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 3e8b5110b39..53b61cfe89c 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -23,6 +23,7 @@ if(WITH_PYTHON)
endif()
set(SRC
+ intern/multi_functions/constants.cc
intern/multi_functions/lists.cc
intern/multi_functions/mixed.cc
intern/multi_functions/network.cc
@@ -68,6 +69,7 @@ set(SRC
FN_node_tree_multi_function_network.h
FN_node_tree.h
+ intern/multi_functions/constants.h
intern/multi_functions/customizable.h
intern/multi_functions/lists.h
intern/multi_functions/mixed.h
diff --git a/source/blender/functions/FN_multi_functions.h b/source/blender/functions/FN_multi_functions.h
index 674205e91f8..2c9b4ac5a9d 100644
--- a/source/blender/functions/FN_multi_functions.h
+++ b/source/blender/functions/FN_multi_functions.h
@@ -1,6 +1,7 @@
#ifndef __FN_MULTI_FUNCTIONS_H__
#define __FN_MULTI_FUNCTIONS_H__
+#include "intern/multi_functions/constants.h"
#include "intern/multi_functions/customizable.h"
#include "intern/multi_functions/lists.h"
#include "intern/multi_functions/mixed.h"
diff --git a/source/blender/functions/intern/multi_functions/constants.cc b/source/blender/functions/intern/multi_functions/constants.cc
new file mode 100644
index 00000000000..85e8978e940
--- /dev/null
+++ b/source/blender/functions/intern/multi_functions/constants.cc
@@ -0,0 +1,29 @@
+#include "constants.h"
+
+namespace FN {
+
+void MF_GenericConstantValue::value_to_string(std::stringstream &ss,
+ const CPPType &type,
+ const void *value)
+{
+ if (type == CPP_TYPE<float>()) {
+ ss << (*(float *)value);
+ }
+ else if (type == CPP_TYPE<int>()) {
+ ss << *(int *)value;
+ }
+ else if (type == CPP_TYPE<BLI::float3>()) {
+ ss << *(BLI::float3 *)value;
+ }
+ else if (type == CPP_TYPE<bool>()) {
+ ss << ((*(bool *)value) ? "true" : "false");
+ }
+ else if (type == CPP_TYPE<std::string>()) {
+ ss << "\"" << *(std::string *)value << "\"";
+ }
+ else {
+ ss << "Value";
+ }
+}
+
+} // namespace FN
diff --git a/source/blender/functions/intern/multi_functions/constants.h b/source/blender/functions/intern/multi_functions/constants.h
new file mode 100644
index 00000000000..db6888427c7
--- /dev/null
+++ b/source/blender/functions/intern/multi_functions/constants.h
@@ -0,0 +1,56 @@
+#pragma once
+
+#include "FN_multi_function.h"
+
+#include <sstream>
+
+namespace FN {
+
+/**
+ * Note: The value buffer passed into the constructor should have a longer lifetime than the
+ * function itself.
+ */
+class MF_GenericConstantValue : public MultiFunction {
+ private:
+ const void *m_value;
+
+ public:
+ MF_GenericConstantValue(const CPPType &type, const void *value) : m_value(value)
+ {
+ MFSignatureBuilder signature = this->get_builder("Constant " + type.name());
+ std::stringstream ss;
+ MF_GenericConstantValue::value_to_string(ss, type, value);
+ signature.single_output(ss.str(), type);
+ }
+
+ void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
+ {
+ GenericMutableArrayRef r_value = params.uninitialized_single_output(0);
+ r_value.type().fill_uninitialized_indices(m_value, r_value.buffer(), mask);
+ }
+
+ static void value_to_string(std::stringstream &ss, const CPPType &type, const void *value);
+};
+
+template<typename T> class MF_ConstantValue : public MultiFunction {
+ private:
+ T m_value;
+
+ public:
+ MF_ConstantValue(T value) : m_value(std::move(value))
+ {
+ MFSignatureBuilder signature = this->get_builder("Constant " + CPP_TYPE<T>().name());
+ std::stringstream ss;
+ MF_GenericConstantValue::value_to_string(ss, CPP_TYPE<T>(), (const void *)&m_value);
+ signature.single_output<T>(ss.str());
+ }
+
+ void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
+ {
+ MutableArrayRef<T> output = params.uninitialized_single_output<T>(0);
+
+ mask.foreach_index([&](uint i) { new (output.begin() + i) T(m_value); });
+ }
+};
+
+} // namespace FN
diff --git a/source/blender/functions/intern/multi_functions/customizable.h b/source/blender/functions/intern/multi_functions/customizable.h
index 3cb24846265..bcbd88e1279 100644
--- a/source/blender/functions/intern/multi_functions/customizable.h
+++ b/source/blender/functions/intern/multi_functions/customizable.h
@@ -8,73 +8,6 @@
namespace FN {
-inline std::string constant_output_name_from_value(const CPPType &type, const void *value)
-{
- if (type == CPP_TYPE<float>()) {
- return std::to_string(*(float *)value);
- }
- else if (type == CPP_TYPE<int>()) {
- return std::to_string(*(int *)value);
- }
- else if (type == CPP_TYPE<BLI::float3>()) {
- std::stringstream ss;
- ss << *(BLI::float3 *)value;
- return ss.str();
- }
- else if (type == CPP_TYPE<bool>()) {
- return (*(bool *)value) ? "true" : "false";
- }
- else if (type == CPP_TYPE<std::string>()) {
- return "\"" + *(std::string *)value + "\"";
- }
- else {
- return "Value";
- }
-}
-
-/**
- * Note: The value buffer passed into the constructor should have a longer lifetime than the
- * function itself.
- */
-class MF_GenericConstantValue : public MultiFunction {
- private:
- const void *m_value;
-
- public:
- MF_GenericConstantValue(const CPPType &type, const void *value) : m_value(value)
- {
- MFSignatureBuilder signature = this->get_builder("Constant " + type.name());
- std::string name = constant_output_name_from_value(type, value);
- signature.single_output(name, type);
- }
-
- void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
- {
- GenericMutableArrayRef r_value = params.uninitialized_single_output(0);
- r_value.type().fill_uninitialized_indices(m_value, r_value.buffer(), mask);
- }
-};
-
-template<typename T> class MF_ConstantValue : public MultiFunction {
- private:
- T m_value;
-
- public:
- MF_ConstantValue(T value) : m_value(std::move(value))
- {
- MFSignatureBuilder signature = this->get_builder("Constant " + CPP_TYPE<T>().name());
- std::string name = constant_output_name_from_value(CPP_TYPE<T>(), (const void *)&m_value);
- signature.single_output<T>(name);
- }
-
- void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
- {
- MutableArrayRef<T> output = params.uninitialized_single_output<T>(0);
-
- mask.foreach_index([&](uint i) { new (output.begin() + i) T(m_value); });
- }
-};
-
template<typename FromT, typename ToT> class MF_Convert : public MultiFunction {
public:
MF_Convert()
More information about the Bf-blender-cvs
mailing list