[Bf-blender-cvs] [7ba7667d8e3] functions: reduce error handling complexity
Jacques Lucke
noreply at git.blender.org
Thu Sep 26 11:26:11 CEST 2019
Commit: 7ba7667d8e38a64f354ff6737afe11c3951133da
Author: Jacques Lucke
Date: Thu Sep 26 11:04:27 2019 +0200
Branches: functions
https://developer.blender.org/rB7ba7667d8e38a64f354ff6737afe11c3951133da
reduce error handling complexity
===================================================================
D source/blender/blenlib/BLI_value_or_error.h
M source/blender/functions/frontends/data_flow_nodes/data_flow_nodes-c.cpp
M source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
M source/blender/functions/frontends/data_flow_nodes/function_generation.hpp
M source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
M source/blender/functions/frontends/data_flow_nodes/graph_generation.hpp
M source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp
M source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.hpp
M source/blender/simulations/bparticles/node_frontend.cpp
M source/blender/simulations/bparticles/particle_function_builder.cpp
M source/blender/simulations/bparticles/particle_function_builder.hpp
===================================================================
diff --git a/source/blender/blenlib/BLI_value_or_error.h b/source/blender/blenlib/BLI_value_or_error.h
deleted file mode 100644
index b54461e1006..00000000000
--- a/source/blender/blenlib/BLI_value_or_error.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-/** \file
- * \ingroup bli
- *
- * This class can be used as return value of functions that might have an error. This forces the
- * caller to check if there was an error or not.
- *
- * The benefit over just using BLI::optional is that this can also store more information about the
- * error.
- */
-
-#pragma once
-
-#include <string>
-#include "BLI_optional.h"
-
-namespace BLI {
-
-struct ErrorInfo {
- const char *file;
- uint line;
- const char *function;
- std::string message;
-};
-
-template<typename T> class ValueOrError {
- private:
- Optional<T> m_value;
- ErrorInfo m_error;
-
- public:
- ValueOrError(T value) : m_value(std::move(value))
- {
- }
-
- ValueOrError(ErrorInfo error) : m_error(std::move(error))
- {
- }
-
- static ValueOrError FromError(const char *file,
- uint line,
- const char *function,
- std::string message)
- {
- return ValueOrError(ErrorInfo{file, line, function, message});
- }
-
- bool is_error() const
- {
- return !m_value.has_value();
- }
-
- T extract_value()
- {
- BLI_assert(m_value.has_value());
- return m_value.extract();
- }
-
- ErrorInfo &error()
- {
- return m_error;
- }
-};
-
-} // namespace BLI
-
-#define BLI_ERROR_CREATE(MESSAGE) \
- { \
- BLI::ErrorInfo \
- { \
- __FILE__, (uint)__LINE__, __func__, MESSAGE \
- } \
- }
diff --git a/source/blender/functions/frontends/data_flow_nodes/data_flow_nodes-c.cpp b/source/blender/functions/frontends/data_flow_nodes/data_flow_nodes-c.cpp
index 07dcb6926be..34d8965e554 100644
--- a/source/blender/functions/frontends/data_flow_nodes/data_flow_nodes-c.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/data_flow_nodes-c.cpp
@@ -7,12 +7,12 @@ FnFunction FN_tree_to_function(bNodeTree *btree)
{
SCOPED_TIMER("Tree to function");
BLI_assert(btree);
- ValueOrError<SharedFunction> fn_or_error = DataFlowNodes::generate_function(btree);
- if (fn_or_error.is_error()) {
+ Optional<SharedFunction> optional_fn = DataFlowNodes::generate_function(btree);
+ if (!optional_fn.has_value()) {
return nullptr;
}
- SharedFunction fn = fn_or_error.extract_value();
+ SharedFunction fn = optional_fn.extract();
Function *fn_ptr = fn.ptr();
fn_ptr->incref();
return wrap(fn_ptr);
diff --git a/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp b/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
index 29ea69f6a78..ec931573178 100644
--- a/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
@@ -32,14 +32,14 @@ static void find_interface_sockets(VirtualNodeTree &vtree,
}
}
-static ValueOrError<FunctionGraph> generate_function_graph(VirtualNodeTree &vtree)
+static Optional<FunctionGraph> generate_function_graph(VirtualNodeTree &vtree)
{
- auto data_graph_or_error = generate_graph(vtree);
- if (data_graph_or_error.is_error()) {
- return data_graph_or_error.error();
+ auto optional_data_graph = generate_graph(vtree);
+ if (!optional_data_graph.has_value()) {
+ return {};
}
- std::unique_ptr<VTreeDataGraph> data_graph = data_graph_or_error.extract_value();
+ std::unique_ptr<VTreeDataGraph> data_graph = optional_data_graph.extract();
VectorSet<DataSocket> input_sockets;
VectorSet<DataSocket> output_sockets;
@@ -48,18 +48,18 @@ static ValueOrError<FunctionGraph> generate_function_graph(VirtualNodeTree &vtre
return FunctionGraph(data_graph->graph(), input_sockets, output_sockets);
}
-ValueOrError<SharedFunction> generate_function(bNodeTree *btree)
+Optional<SharedFunction> generate_function(bNodeTree *btree)
{
VirtualNodeTree vtree;
vtree.add_all_of_tree(btree);
vtree.freeze_and_index();
- ValueOrError<FunctionGraph> fgraph_or_error = generate_function_graph(vtree);
- if (fgraph_or_error.is_error()) {
- return fgraph_or_error.error();
+ Optional<FunctionGraph> optional_fgraph = generate_function_graph(vtree);
+ if (!optional_fgraph.has_value()) {
+ return {};
}
- FunctionGraph fgraph = fgraph_or_error.extract_value();
+ FunctionGraph fgraph = optional_fgraph.extract();
// fgraph.graph()->to_dot__clipboard();
auto fn = fgraph.new_function(btree->id.name);
diff --git a/source/blender/functions/frontends/data_flow_nodes/function_generation.hpp b/source/blender/functions/frontends/data_flow_nodes/function_generation.hpp
index 411f222d67c..2771559c8bd 100644
--- a/source/blender/functions/frontends/data_flow_nodes/function_generation.hpp
+++ b/source/blender/functions/frontends/data_flow_nodes/function_generation.hpp
@@ -1,16 +1,16 @@
#pragma once
#include "FN_core.hpp"
-#include "BLI_value_or_error.h"
+#include "BLI_optional.h"
struct bNodeTree;
namespace FN {
namespace DataFlowNodes {
-using BLI::ValueOrError;
+using BLI::Optional;
-ValueOrError<SharedFunction> generate_function(struct bNodeTree *btree);
+Optional<SharedFunction> generate_function(struct bNodeTree *btree);
} // namespace DataFlowNodes
} // namespace FN
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 d67e897dfa1..bb5e0a7a359 100644
--- a/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
@@ -69,30 +69,29 @@ static bool insert_unlinked_inputs(VTreeDataGraphBuilder &builder,
return true;
}
-ValueOrError<std::unique_ptr<VTreeDataGraph>> generate_graph(VirtualNodeTree &vtree)
+Optional<std::unique_ptr<VTreeDataGraph>> generate_graph(VirtualNodeTree &vtree)
{
GroupByNodeUsage inputs_grouper;
ConstantInputsHandler inputs_inserter;
return generate_graph(vtree, inputs_grouper, inputs_inserter);
}
-ValueOrError<std::unique_ptr<VTreeDataGraph>> generate_graph(
- VirtualNodeTree &vtree,
- UnlinkedInputsGrouper &inputs_grouper,
- UnlinkedInputsInserter &inputs_inserter)
+Optional<std::unique_ptr<VTreeDataGraph>> generate_graph(VirtualNodeTree &vtree,
+ UnlinkedInputsGrouper &inputs_grouper,
+ UnlinkedInputsInserter &inputs_inserter)
{
VTreeDataGraphBuilder builder(vtree);
if (!insert_nodes(builder)) {
- return BLI_ERROR_CREATE("error inserting functions for nodes");
+ return {};
}
if (!insert_links(builder)) {
- return BLI_ERROR_CREATE("error inserting links");
+ return {};
}
if (!insert_unlinked_inputs(builder, inputs_grouper, inputs_inserter)) {
- return BLI_ERROR_CREATE("error inserting unlinked inputs");
+ return {};
}
return builder.build();
diff --git a/source/blender/functions/frontends/data_flow_nodes/graph_generation.hpp b/source/blender/functions/frontends/data_flow_nodes/graph_generation.hpp
index fc492854d94..ccd693cbcaa 100644
--- a/source/blender/functions/frontends/data_flow_nodes/graph_generation.hpp
+++ b/source/blender/functions/frontends/data_flow_nodes/graph_generation.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "BLI_multi_vector.h"
+#include "BLI_optional.h"
#include "vtree_data_graph_builder.hpp"
@@ -8,6 +9,7 @@ namespace FN {
namespace DataFlowNodes {
using BLI::MultiVector;
+using BLI::Optional;
class UnlinkedInputsGrouper {
public:
@@ -21,12 +23,11 @@ class UnlinkedInputsInserter {
MutableArrayRef<BuilderOutputSocket *> r_new_origins) = 0;
};
-ValueOrError<std::unique_ptr<VTreeDataGraph>> generate_graph(VirtualNodeTree &vtree);
+Optional<std::unique_ptr<VTreeDataGraph>> generate_graph(VirtualNodeTree &vtree);
-ValueOrError<std::unique_ptr<VTreeDataGraph>> generate_graph(
- VirtualNodeTree &vtree,
- UnlinkedInputsGrouper &inputs_grouper,
- UnlinkedInputsInserter &inputs_inserter);
+Optional<std::unique_ptr<VTreeDataGraph>> generate_graph(VirtualNodeTree &vtree,
+ UnlinkedInputsGrouper &inputs_grouper,
+ UnlinkedInputsInserter &inputs_inserter);
} // namespace DataFlowNodes
} // namespace FN
diff --git a/source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp b/source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp
index 20be4a5811c..aeca56b1ceb 100644
--- a/source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp
@@ -275,9 +275,9 @@ static void INSERT_call(VTreeDataGraphBuilder &builder, VirtualNode *vnode)
return;
}
- ValueOrError<SharedFunction> fn_or_error = generate_function(btree);
- BLI_assert(!fn_or_error.is_error());
- SharedFunction fn = fn_or_error.extract_value();
+ Optional<SharedFunction> optional_fn = generate_function(btree);
+ BLI_assert(optional_fn.has_value());
+ SharedFunction fn = optional_fn.extract();
builder.insert_matching_function(fn, vnode);
}
diff --git a/source/blender/funct
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list