[Bf-blender-cvs] [7bcd0e01afa] spreadsheet-active-node: cleanup
Jacques Lucke
noreply at git.blender.org
Thu Apr 1 13:55:19 CEST 2021
Commit: 7bcd0e01afac6c713e4284d3f37dfa909a7ee9ea
Author: Jacques Lucke
Date: Thu Apr 1 12:18:49 2021 +0200
Branches: spreadsheet-active-node
https://developer.blender.org/rB7bcd0e01afac6c713e4284d3f37dfa909a7ee9ea
cleanup
===================================================================
M source/blender/blenlib/BLI_function_ref.hh
M source/blender/nodes/intern/derived_node_tree.cc
M source/blender/nodes/intern/node_tree_ref.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_function_ref.hh b/source/blender/blenlib/BLI_function_ref.hh
index 07a20a08e13..9c635ef550a 100644
--- a/source/blender/blenlib/BLI_function_ref.hh
+++ b/source/blender/blenlib/BLI_function_ref.hh
@@ -141,7 +141,13 @@ template<typename Ret, typename... Params> class FunctionRef<Ret(Params...)> {
}
using OptionalReturnValue = std::conditional_t<std::is_void_v<Ret>, void, std::optional<Ret>>;
- OptionalReturnValue call_if_available(Params... params) const
+
+ /**
+ * Calls the referenced function if it is available.
+ * The return value is of type `std::optional<Ret>` if `Ret` is not `void`.
+ * Otherwise the function returns void.
+ */
+ OptionalReturnValue call_safe(Params... params) const
{
if constexpr (std::is_void_v<Ret>) {
if (callback_ == nullptr) {
diff --git a/source/blender/nodes/intern/derived_node_tree.cc b/source/blender/nodes/intern/derived_node_tree.cc
index b5e943fdb88..25c58c2371b 100644
--- a/source/blender/nodes/intern/derived_node_tree.cc
+++ b/source/blender/nodes/intern/derived_node_tree.cc
@@ -224,7 +224,7 @@ void DOutputSocket::foreach_target_socket(FunctionRef<void(DInputSocket)> callba
FunctionRef<void(DSocket)> skipped_callback) const
{
for (const SocketRef *skipped_socket : socket_ref_->logically_linked_skipped_sockets()) {
- skipped_callback.call_if_available({context_, skipped_socket});
+ skipped_callback.call_safe({context_, skipped_socket});
}
for (const InputSocketRef *linked_socket : socket_ref_->as_output().logically_linked_sockets()) {
const NodeRef &linked_node = linked_socket->node();
@@ -239,8 +239,8 @@ void DOutputSocket::foreach_target_socket(FunctionRef<void(DInputSocket)> callba
/* Follow the links going out of the group node in the parent node group. */
DOutputSocket socket_in_parent_group =
linked_dsocket.get_corresponding_group_node_output();
- skipped_callback.call_if_available(linked_dsocket);
- skipped_callback.call_if_available(socket_in_parent_group);
+ skipped_callback.call_safe(linked_dsocket);
+ skipped_callback.call_safe(socket_in_parent_group);
socket_in_parent_group.foreach_target_socket(callback, skipped_callback);
}
}
@@ -248,9 +248,9 @@ void DOutputSocket::foreach_target_socket(FunctionRef<void(DInputSocket)> callba
/* Follow the links within the nested node group. */
Vector<DOutputSocket> sockets_in_group =
linked_dsocket.get_corresponding_group_input_sockets();
- skipped_callback.call_if_available(linked_dsocket);
+ skipped_callback.call_safe(linked_dsocket);
for (DOutputSocket socket_in_group : sockets_in_group) {
- skipped_callback.call_if_available(socket_in_group);
+ skipped_callback.call_safe(socket_in_group);
socket_in_group.foreach_target_socket(callback, skipped_callback);
}
}
diff --git a/source/blender/nodes/intern/node_tree_ref.cc b/source/blender/nodes/intern/node_tree_ref.cc
index 19d1f37e01c..12493521057 100644
--- a/source/blender/nodes/intern/node_tree_ref.cc
+++ b/source/blender/nodes/intern/node_tree_ref.cc
@@ -231,16 +231,16 @@ void InputSocketRef::foreach_logical_origin(FunctionRef<void(const OutputSocketR
if (origin_node.is_reroute_node()) {
const InputSocketRef &reroute_input = origin_node.input(0);
const OutputSocketRef &reroute_output = origin_node.output(0);
- skipped_callback.call_if_available(reroute_input);
- skipped_callback.call_if_available(reroute_output);
+ skipped_callback.call_safe(reroute_input);
+ skipped_callback.call_safe(reroute_output);
reroute_input.foreach_logical_origin(callback, skipped_callback, false);
}
else if (origin_node.is_muted()) {
for (const InternalLinkRef *internal_link : origin_node.internal_links()) {
if (&internal_link->to() == &origin) {
const InputSocketRef &mute_input = internal_link->from();
- skipped_callback.call_if_available(origin);
- skipped_callback.call_if_available(mute_input);
+ skipped_callback.call_safe(origin);
+ skipped_callback.call_safe(mute_input);
mute_input.foreach_logical_origin(callback, skipped_callback, true);
break;
}
@@ -264,17 +264,17 @@ void OutputSocketRef::foreach_logical_target(
const NodeRef &target_node = target.node();
if (target_node.is_reroute_node()) {
const OutputSocketRef &reroute_output = target_node.output(0);
- skipped_callback.call_if_available(target);
- skipped_callback.call_if_available(reroute_output);
+ skipped_callback.call_safe(target);
+ skipped_callback.call_safe(reroute_output);
reroute_output.foreach_logical_target(callback, skipped_callback);
}
else if (target_node.is_muted()) {
- skipped_callback.call_if_available(target);
+ skipped_callback.call_safe(target);
for (const InternalLinkRef *internal_link : target_node.internal_links()) {
if (&internal_link->from() == &target) {
const OutputSocketRef &mute_output = internal_link->to();
- skipped_callback.call_if_available(target);
- skipped_callback.call_if_available(mute_output);
+ skipped_callback.call_safe(target);
+ skipped_callback.call_safe(mute_output);
mute_output.foreach_logical_target(callback, skipped_callback);
}
}
More information about the Bf-blender-cvs
mailing list