[Bf-blender-cvs] [d3b807ff02f] functions: move BuilderContext into Builder

Jacques Lucke noreply at git.blender.org
Sat Apr 6 22:09:16 CEST 2019


Commit: d3b807ff02fc0b155da3ebaef67061153c95e136
Author: Jacques Lucke
Date:   Sat Apr 6 22:08:13 2019 +0200
Branches: functions
https://developer.blender.org/rBd3b807ff02fc0b155da3ebaef67061153c95e136

move BuilderContext into Builder

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

M	source/blender/functions/frontends/data_flow_nodes/builder.cpp
M	source/blender/functions/frontends/data_flow_nodes/builder.hpp
M	source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
M	source/blender/functions/frontends/data_flow_nodes/inserters.cpp
M	source/blender/functions/frontends/data_flow_nodes/inserters.hpp
M	source/blender/functions/frontends/data_flow_nodes/inserters/conversions.cpp
M	source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp

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

diff --git a/source/blender/functions/frontends/data_flow_nodes/builder.cpp b/source/blender/functions/frontends/data_flow_nodes/builder.cpp
index a680dbaec7e..e1021868228 100644
--- a/source/blender/functions/frontends/data_flow_nodes/builder.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/builder.cpp
@@ -88,19 +88,17 @@ namespace FN { namespace DataFlowNodes {
 		return m_graph->insert(fn);
 	}
 
-	Node *Builder::insert_function(SharedFunction &fn, bNodeTree *btree, bNode *bnode)
+	Node *Builder::insert_function(SharedFunction &fn, bNode *bnode)
 	{
-		BLI_assert(btree != nullptr);
 		BLI_assert(bnode != nullptr);
-		NodeSource *source = m_graph->new_source_info<NodeSource>(btree, bnode);
+		NodeSource *source = m_graph->new_source_info<NodeSource>(m_ctx.btree(), bnode);
 		return m_graph->insert(fn, source);
 	}
 
-	Node *Builder::insert_function(SharedFunction &fn, bNodeTree *btree, bNodeLink *blink)
+	Node *Builder::insert_function(SharedFunction &fn, bNodeLink *blink)
 	{
-		BLI_assert(btree != nullptr);
 		BLI_assert(blink != nullptr);
-		LinkSource *source = m_graph->new_source_info<LinkSource>(btree, blink);
+		LinkSource *source = m_graph->new_source_info<LinkSource>(m_ctx.btree(), blink);
 		return m_graph->insert(fn, source);
 	}
 
@@ -109,61 +107,61 @@ namespace FN { namespace DataFlowNodes {
 		m_graph->link(a, b);
 	}
 
-	void Builder::map_socket(const BuilderContext &ctx, Socket socket, bNodeSocket *bsocket)
+	void Builder::map_socket(Socket socket, bNodeSocket *bsocket)
 	{
-		BLI_assert(ctx.is_data_socket(bsocket) ? socket.type() == ctx.type_of_socket(bsocket) : true);
+		BLI_assert(m_ctx.is_data_socket(bsocket) ? socket.type() == m_ctx.type_of_socket(bsocket) : true);
 		m_socket_map.add(bsocket, socket);
 	}
 
-	void Builder::map_sockets(const BuilderContext &ctx, Node *node, struct bNode *bnode)
+	void Builder::map_sockets(Node *node, struct bNode *bnode)
 	{
 		BLI_assert(BLI_listbase_count(&bnode->inputs) == node->input_amount());
 		BLI_assert(BLI_listbase_count(&bnode->outputs) == node->output_amount());
 
 		uint input_index = 0;
 		for (bNodeSocket *bsocket : bSocketList(&bnode->inputs)) {
-			this->map_socket(ctx, node->input(input_index), bsocket);
+			this->map_socket(node->input(input_index), bsocket);
 			input_index++;
 		}
 
 		uint output_index = 0;
 		for (bNodeSocket *bsocket : bSocketList(&bnode->outputs)) {
-			this->map_socket(ctx, node->output(output_index), bsocket);
+			this->map_socket( node->output(output_index), bsocket);
 			output_index++;
 		}
 	}
 
-	void Builder::map_data_sockets(const BuilderContext &ctx, Node *node, struct bNode *bnode)
+	void Builder::map_data_sockets(Node *node, struct bNode *bnode)
 	{
 		uint input_index = 0;
 		for (bNodeSocket *bsocket : bSocketList(&bnode->inputs)) {
-			if (ctx.is_data_socket(bsocket)) {
-				this->map_socket(ctx, node->input(input_index), bsocket);
+			if (m_ctx.is_data_socket(bsocket)) {
+				this->map_socket(node->input(input_index), bsocket);
 				input_index++;
 			}
 		}
 
 		uint output_index = 0;
 		for (bNodeSocket *bsocket : bSocketList(&bnode->outputs)) {
-			if (ctx.is_data_socket(bsocket)) {
-				this->map_socket(ctx, node->output(output_index), bsocket);
+			if (m_ctx.is_data_socket(bsocket)) {
+				this->map_socket( node->output(output_index), bsocket);
 				output_index++;
 			}
 		}
 	}
 
-	void Builder::map_input(const BuilderContext &ctx, Socket socket, struct bNode *bnode, uint index)
+	void Builder::map_input(Socket socket, struct bNode *bnode, uint index)
 	{
 		BLI_assert(socket.is_input());
 		auto bsocket = (bNodeSocket *)BLI_findlink(&bnode->inputs, index);
-		this->map_socket(ctx, socket, bsocket);
+		this->map_socket(socket, bsocket);
 	}
 
-	void Builder::map_output(const BuilderContext &ctx, Socket socket, struct bNode *bnode, uint index)
+	void Builder::map_output(Socket socket, struct bNode *bnode, uint index)
 	{
 		BLI_assert(socket.is_output());
 		auto bsocket = (bNodeSocket *)BLI_findlink(&bnode->outputs, index);
-		this->map_socket(ctx, socket, bsocket);
+		this->map_socket(socket, bsocket);
 	}
 
 	Socket Builder::lookup_socket(struct bNodeSocket *bsocket)
@@ -174,15 +172,14 @@ namespace FN { namespace DataFlowNodes {
 
 	bool Builder::check_if_sockets_are_mapped(
 		struct bNode *bnode,
-		bSocketList bsockets,
-		const BuilderContext &ctx) const
+		bSocketList bsockets) const
 	{
 		int index = 0;
 		for (bNodeSocket *bsocket : bsockets) {
-			if (ctx.is_data_socket(bsocket)) {
+			if (m_ctx.is_data_socket(bsocket)) {
 				if (!m_socket_map.contains(bsocket)) {
 					std::cout << "Data Socket not mapped: " << std::endl;
-					std::cout << "    Tree: " << ctx.btree()->id.name << std::endl;
+					std::cout << "    Tree: " << m_ctx.btree()->id.name << std::endl;
 					std::cout << "    Node: " << bnode->name << std::endl;
 					if (bsocket->in_out == SOCK_IN) {
 						std::cout << "    Input";
@@ -199,11 +196,11 @@ namespace FN { namespace DataFlowNodes {
 		return true;
 	}
 
-	bool Builder::verify_data_sockets_mapped(struct bNode *bnode, const BuilderContext &ctx) const
+	bool Builder::verify_data_sockets_mapped(struct bNode *bnode) const
 	{
 		return (
-			this->check_if_sockets_are_mapped(bnode, bSocketList(&bnode->inputs), ctx) &&
-			this->check_if_sockets_are_mapped(bnode, bSocketList(&bnode->outputs), ctx));
+			this->check_if_sockets_are_mapped(bnode, bSocketList(&bnode->inputs)) &&
+			this->check_if_sockets_are_mapped(bnode, bSocketList(&bnode->outputs)));
 	}
 
 
diff --git a/source/blender/functions/frontends/data_flow_nodes/builder.hpp b/source/blender/functions/frontends/data_flow_nodes/builder.hpp
index c82e7de8d46..57b77479f77 100644
--- a/source/blender/functions/frontends/data_flow_nodes/builder.hpp
+++ b/source/blender/functions/frontends/data_flow_nodes/builder.hpp
@@ -14,41 +14,6 @@ namespace FN { namespace DataFlowNodes {
 
 	using SocketMap = SmallMap<struct bNodeSocket *, Socket>;
 
-	class BuilderContext;
-
-	class Builder {
-	private:
-		SharedDataFlowGraph &m_graph;
-		SocketMap &m_socket_map;
-
-	public:
-		Builder(
-			SharedDataFlowGraph &graph,
-			SocketMap &socket_map)
-			: m_graph(graph), m_socket_map(socket_map) {}
-
-		Node *insert_function(SharedFunction &fn);
-		Node *insert_function(SharedFunction &fn, struct bNodeTree *btree, struct bNode *bnode);
-		Node *insert_function(SharedFunction &fn, struct bNodeTree *btree, struct bNodeLink *blink);
-		void insert_link(Socket a, Socket b);
-
-		void map_socket(const BuilderContext &ctx, Socket socket, struct bNodeSocket *bsocket);
-		void map_sockets(const BuilderContext &ctx, Node *node, struct bNode *bnode);
-		void map_data_sockets(const BuilderContext &ctx, Node *node, struct bNode *bnode);
-		void map_input(const BuilderContext &ctx, Socket socket, struct bNode *bnode, uint index);
-		void map_output(const BuilderContext &ctx, Socket socket, struct bNode *bnode, uint index);
-
-		Socket lookup_socket(struct bNodeSocket *bsocket);
-		bool verify_data_sockets_mapped(struct bNode *bnode, const BuilderContext &ctx) const;
-
-	private:
-		bool check_if_sockets_are_mapped(
-			struct bNode *bnode,
-			bSocketList bsockets,
-			const BuilderContext &ctx) const;
-	};
-
-
 	class BuilderContext {
 	private:
 		struct bNodeTree *m_btree;
@@ -71,4 +36,42 @@ namespace FN { namespace DataFlowNodes {
 		std::string socket_type_string(bNodeSocket *bsocket) const;
 	};
 
+	class Builder {
+	private:
+		const BuilderContext &m_ctx;
+		SharedDataFlowGraph &m_graph;
+		SocketMap &m_socket_map;
+
+	public:
+		Builder(
+			const BuilderContext &ctx,
+			SharedDataFlowGraph &graph,
+			SocketMap &socket_map)
+			: m_ctx(ctx), m_graph(graph), m_socket_map(socket_map) {}
+
+		Node *insert_function(SharedFunction &fn);
+		Node *insert_function(SharedFunction &fn, struct bNode *bnode);
+		Node *insert_function(SharedFunction &fn, struct bNodeLink *blink);
+		void insert_link(Socket a, Socket b);
+
+		void map_socket(Socket socket, struct bNodeSocket *bsocket);
+		void map_sockets(Node *node, struct bNode *bnode);
+		void map_data_sockets(Node *node, struct bNode *bnode);
+		void map_input(Socket socket, struct bNode *bnode, uint index);
+		void map_output(Socket socket, struct bNode *bnode, uint index);
+
+		Socket lookup_socket(struct bNodeSocket *bsocket);
+		bool verify_data_sockets_mapped(struct bNode *bnode) const;
+
+		const BuilderContext &ctx() const
+		{
+			return m_ctx;
+		}
+
+	private:
+		bool check_if_sockets_are_mapped(
+			struct bNode *bnode,
+			bSocketList bsockets) const;
+	};
+
 } }
\ No newline at end of file
diff --git a/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp b/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
index 844f2d86bdf..d69b6fe8f23 100644
--- a/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
@@ -53,7 +53,7 @@ namespace FN { namespace DataFlowNodes {
 
 		auto fn = SharedFunction::New("Function Input", Signature({}, outputs));
 		Node *node = builder.insert_function(fn);
-		builder.map_data_sockets(ctx, node, bnode);
+		builder.map_data_sockets(node, bnode);
 	}
 
 	static void insert_output_node(
@@ -69,7 +69,7 @@ namespace FN { namespace DataFlowNodes {
 
 		auto fn = SharedFunction::New("Function Output", Signature(inputs, {}));
 		Node *node = builder.insert_function(fn);
-		builder.map_data_sockets(ctx, node, bnode);
+		builder.map_data_sockets(node, bnode);
 	}
 
 	struct BSocketLink {
@@ -150,8 +150,8 @@ namespace FN { namespace DataFlowNodes {
 		auto graph = SharedDataFlowGraph::New();
 		SocketMap socket_map;
 
-		Builder builder(graph, socket_map);
 		BuilderContext ctx(btree);
+		Builder builder(ctx, graph, socket_map);
 		GraphInserters &inserters = get_standard_inserters();
 
 		bNode *input_node;
@@ -166,7 +166,7 @@ namespace FN { namespace DataFlowNodes {
 				continue;
 			}
 
-			if (!inserters.insert_node(builder, ctx, bnode)) {
+			if (!inserters.insert_node(builder, bnode)) {
 				return {};
 			}
 		}
@@ -194,7 +194,7 @@ namespace FN { namespace DataFlowNodes {
 		TreeData tree_data(btree);
 		for (auto &link : tree_data.data_origi

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list