[Bf-blender-cvs] [f92bc17cb3e] functions: utility to count the number of times an output socket is used

Jacques Lucke noreply at git.blender.org
Mon Apr 8 18:57:20 CEST 2019


Commit: f92bc17cb3e84d915134e483ef3bbf341335bf7b
Author: Jacques Lucke
Date:   Mon Apr 8 18:57:01 2019 +0200
Branches: functions
https://developer.blender.org/rBf92bc17cb3e84d915134e483ef3bbf341335bf7b

utility to count the number of times an output socket is used

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

M	source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
M	source/blender/functions/core/data_flow_graph.hpp

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

diff --git a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
index d644de67b8e..7d5d5bcd902 100644
--- a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
+++ b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
@@ -341,6 +341,25 @@ namespace FN {
 		}
 	};
 
+	static SmallMap<Socket, uint> UNUSED_FUNCTION(get_max_usage_amounts)(SocketSet used_sockets)
+	{
+		SmallMap<Socket, uint> usage_counts;
+
+		for (Socket socket : used_sockets) {
+			if (socket.is_input()) {
+				continue;
+			}
+			uint amount = 0;
+			for (Socket target : socket.targets()) {
+				if (used_sockets.contains(target)) {
+					amount++;
+				}
+			}
+			usage_counts.add_new(socket, amount);
+		}
+		return usage_counts;
+	}
+
 	class ExecuteGraph : public TupleCallBody {
 	private:
 		SharedDataFlowGraph m_graph;
diff --git a/source/blender/functions/core/data_flow_graph.hpp b/source/blender/functions/core/data_flow_graph.hpp
index 304c0af0a5a..96f28c176ba 100644
--- a/source/blender/functions/core/data_flow_graph.hpp
+++ b/source/blender/functions/core/data_flow_graph.hpp
@@ -40,6 +40,7 @@ namespace FN {
 		std::string name() const;
 
 		friend bool operator==(const Socket &a, const Socket &b);
+		friend std::ostream &operator<<(std::ostream &stream, Socket socket);
 
 		inline Socket origin() const;
 		inline SocketSet targets() const;
@@ -419,6 +420,14 @@ namespace FN {
 			a.m_index == b.m_index);
 	}
 
+	inline std::ostream &operator<<(std::ostream &stream, Socket socket)
+	{
+		stream << "<" << socket.node()->function()->name();
+		stream << ", " << ((socket.is_input()) ? "Input" : "Output");
+		stream << ":" << socket.index() << ">";
+		return stream;
+	}
+
 	Socket Socket::origin() const
 	{
 		return this->graph()->m_links.get_origin(*this);



More information about the Bf-blender-cvs mailing list