[Bf-blender-cvs] [f1c69c71c63] functions: move FunctionBuilder to separate file and add more methods

Jacques Lucke noreply at git.blender.org
Wed Jul 24 19:11:26 CEST 2019


Commit: f1c69c71c63e8ac1319aead8712f74f5166e5d32
Author: Jacques Lucke
Date:   Wed Jul 24 11:32:40 2019 +0200
Branches: functions
https://developer.blender.org/rBf1c69c71c63e8ac1319aead8712f74f5166e5d32

move FunctionBuilder to separate file and add more methods

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

M	source/blender/functions/CMakeLists.txt
M	source/blender/functions/FN_core.hpp
M	source/blender/functions/core/function.cpp
M	source/blender/functions/core/function.hpp
A	source/blender/functions/core/function_builder.cpp
A	source/blender/functions/core/function_builder.hpp
M	source/blender/functions/core/function_graph.cpp

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

diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index e0892729cd4..b97a6677060 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -40,6 +40,8 @@ set(SRC
   core/type.cpp
   core/function.hpp
   core/function.cpp
+  core/function_builder.hpp
+  core/function_builder.cpp
   core/data_flow_graph.hpp
   core/data_flow_graph.cpp
   core/data_flow_graph_builder.hpp
diff --git a/source/blender/functions/FN_core.hpp b/source/blender/functions/FN_core.hpp
index e3cab7046b4..191d3aaecd5 100644
--- a/source/blender/functions/FN_core.hpp
+++ b/source/blender/functions/FN_core.hpp
@@ -3,6 +3,7 @@
 #include "FN_core-c.h"
 #include "core/type.hpp"
 #include "core/function.hpp"
+#include "core/function_builder.hpp"
 #include "core/source_info.hpp"
 #include "core/function_graph.hpp"
 #include "core/data_flow_graph.hpp"
diff --git a/source/blender/functions/core/function.cpp b/source/blender/functions/core/function.cpp
index b439fefa080..14c40b01829 100644
--- a/source/blender/functions/core/function.cpp
+++ b/source/blender/functions/core/function.cpp
@@ -58,33 +58,4 @@ FunctionBody::~FunctionBody()
 {
 }
 
-/* Function builder
- ************************************/
-
-FunctionBuilder::FunctionBuilder()
-{
-}
-
-void FunctionBuilder::add_input(StringRef name, SharedType &type)
-{
-  auto ref = m_strings_builder.add(name);
-  m_input_names.append(ref);
-  m_input_types.append(type);
-}
-
-void FunctionBuilder::add_output(StringRef name, SharedType &type)
-{
-  auto ref = m_strings_builder.add(name);
-  m_output_names.append(ref);
-  m_output_types.append(type);
-}
-
-SharedFunction FunctionBuilder::build(StringRef function_name)
-{
-  auto name_ref = m_strings_builder.add(function_name);
-  char *strings = m_strings_builder.build();
-  return SharedFunction::New(
-      name_ref, m_input_names, m_input_types, m_output_names, m_output_types, strings);
-}
-
 } /* namespace FN */
diff --git a/source/blender/functions/core/function.hpp b/source/blender/functions/core/function.hpp
index 483c150f484..bcc371fdcb2 100644
--- a/source/blender/functions/core/function.hpp
+++ b/source/blender/functions/core/function.hpp
@@ -155,33 +155,6 @@ class Function final : public RefCountedBase {
 
 using SharedFunction = AutoRefCount<Function>;
 
-class FunctionBuilder {
- private:
-  ChainedStringsBuilder m_strings_builder;
-  Vector<ChainedStringRef> m_input_names;
-  Vector<SharedType> m_input_types;
-  Vector<ChainedStringRef> m_output_names;
-  Vector<SharedType> m_output_types;
-
- public:
-  FunctionBuilder();
-
-  /**
-   * Add an input to the function with the given name and type.
-   */
-  void add_input(StringRef input_name, SharedType &type);
-
-  /**
-   * Add an output to the function with the given name and type.
-   */
-  void add_output(StringRef output_name, SharedType &type);
-
-  /**
-   * Create a new function with the given name and all the inputs and outputs previously added.
-   */
-  SharedFunction build(StringRef function_name);
-};
-
 /* Function inline functions
  ***********************************************/
 
diff --git a/source/blender/functions/core/function_builder.cpp b/source/blender/functions/core/function_builder.cpp
new file mode 100644
index 00000000000..bc0bd5984fb
--- /dev/null
+++ b/source/blender/functions/core/function_builder.cpp
@@ -0,0 +1,50 @@
+#include "FN_core.hpp"
+
+namespace FN {
+
+FunctionBuilder::FunctionBuilder()
+{
+}
+
+void FunctionBuilder::add_input(StringRef name, SharedType &type)
+{
+  auto ref = m_strings_builder.add(name);
+  m_input_names.append(ref);
+  m_input_types.append(type);
+}
+
+void FunctionBuilder::add_output(StringRef name, SharedType &type)
+{
+  auto ref = m_strings_builder.add(name);
+  m_output_names.append(ref);
+  m_output_types.append(type);
+}
+
+void FunctionBuilder::add_inputs(const SharedDataFlowGraph &graph, ArrayRef<DFGraphSocket> sockets)
+{
+  for (DFGraphSocket socket : sockets) {
+    StringRef name = graph->name_of_socket(socket);
+    SharedType &type = graph->type_of_socket(socket);
+    this->add_input(name, type);
+  }
+}
+
+void FunctionBuilder::add_outputs(const SharedDataFlowGraph &graph,
+                                  ArrayRef<DFGraphSocket> sockets)
+{
+  for (DFGraphSocket socket : sockets) {
+    StringRef name = graph->name_of_socket(socket);
+    SharedType &type = graph->type_of_socket(socket);
+    this->add_output(name, type);
+  }
+}
+
+SharedFunction FunctionBuilder::build(StringRef function_name)
+{
+  auto name_ref = m_strings_builder.add(function_name);
+  char *strings = m_strings_builder.build();
+  return SharedFunction::New(
+      name_ref, m_input_names, m_input_types, m_output_names, m_output_types, strings);
+}
+
+}  // namespace FN
diff --git a/source/blender/functions/core/function_builder.hpp b/source/blender/functions/core/function_builder.hpp
new file mode 100644
index 00000000000..30ec59f4f78
--- /dev/null
+++ b/source/blender/functions/core/function_builder.hpp
@@ -0,0 +1,45 @@
+#pragma once
+
+#include "function.hpp"
+#include "data_flow_graph.hpp"
+
+namespace FN {
+
+class FunctionBuilder {
+ private:
+  ChainedStringsBuilder m_strings_builder;
+  Vector<ChainedStringRef> m_input_names;
+  Vector<SharedType> m_input_types;
+  Vector<ChainedStringRef> m_output_names;
+  Vector<SharedType> m_output_types;
+
+ public:
+  FunctionBuilder();
+
+  /**
+   * Add an input to the function with the given name and type.
+   */
+  void add_input(StringRef input_name, SharedType &type);
+
+  /**
+   * Add an output to the function with the given name and type.
+   */
+  void add_output(StringRef output_name, SharedType &type);
+
+  /**
+   * Add multiple inputs. The names and types are taken from the sockets.
+   */
+  void add_inputs(const SharedDataFlowGraph &graph, ArrayRef<DFGraphSocket> sockets);
+
+  /**
+   * Add multiple outputs. The names and types are taken from the sockets.
+   */
+  void add_outputs(const SharedDataFlowGraph &graph, ArrayRef<DFGraphSocket> sockets);
+
+  /**
+   * Create a new function with the given name and all the inputs and outputs previously added.
+   */
+  SharedFunction build(StringRef function_name);
+};
+
+}  // namespace FN
diff --git a/source/blender/functions/core/function_graph.cpp b/source/blender/functions/core/function_graph.cpp
index 595156f4e3a..1e705e79c1c 100644
--- a/source/blender/functions/core/function_graph.cpp
+++ b/source/blender/functions/core/function_graph.cpp
@@ -5,14 +5,8 @@ namespace FN {
 SharedFunction FunctionGraph::new_function(StringRef name) const
 {
   FunctionBuilder builder;
-
-  for (const DFGraphSocket &socket : m_inputs) {
-    builder.add_input(m_graph->name_of_socket(socket), m_graph->type_of_socket(socket));
-  }
-  for (const DFGraphSocket &socket : m_outputs) {
-    builder.add_output(m_graph->name_of_socket(socket), m_graph->type_of_socket(socket));
-  }
-
+  builder.add_inputs(m_graph, m_inputs);
+  builder.add_outputs(m_graph, m_outputs);
   return builder.build(name);
 }



More information about the Bf-blender-cvs mailing list