diff options
author | Jacques Lucke <jacques@blender.org> | 2021-09-06 11:58:56 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-09-06 11:58:56 +0300 |
commit | 605f145aba144dff77d5ee0fc430231ab123dce3 (patch) | |
tree | a02c865d985124c462b90c85208161489e60ca00 | |
parent | deb7cd57837283c9ff0d102c08412f76fb764c31 (diff) |
cleanup FieldNode
-rw-r--r-- | source/blender/functions/FN_field.hh | 49 | ||||
-rw-r--r-- | source/blender/functions/intern/field.cc | 8 |
2 files changed, 22 insertions, 35 deletions
diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh index 612ffddc6cd..309d871a56e 100644 --- a/source/blender/functions/FN_field.hh +++ b/source/blender/functions/FN_field.hh @@ -42,19 +42,26 @@ namespace blender::fn { class FieldNode { + private: + bool is_input_; + public: + FieldNode(bool is_input) : is_input_(is_input) + { + } + ~FieldNode() = default; - virtual const CPPType &cpp_type_of_output_index(int output_index) const = 0; + virtual const CPPType &output_cpp_type(int output_index) const = 0; - virtual bool is_input_node() const + bool is_input() const { - return false; + return is_input_; } - virtual bool is_operation_node() const + bool is_operation() const { - return false; + return !is_input_; } virtual uint64_t hash() const @@ -104,17 +111,7 @@ template<typename NodePtr> class GFieldBase { const fn::CPPType &cpp_type() const { - return node_->cpp_type_of_output_index(node_output_index_); - } - - bool has_input_node() const - { - return node_->is_input_node(); - } - - bool has_operation_node() const - { - return node_->is_operation_node(); + return node_->output_cpp_type(node_output_index_); } const FieldNode &node() const @@ -184,13 +181,13 @@ class FieldOperation : public FieldNode { public: FieldOperation(std::unique_ptr<const MultiFunction> function, Vector<GField> inputs = {}) - : owned_function_(std::move(function)), inputs_(std::move(inputs)) + : FieldNode(false), owned_function_(std::move(function)), inputs_(std::move(inputs)) { function_ = owned_function_.get(); } FieldOperation(const MultiFunction &function, Vector<GField> inputs = {}) - : function_(&function), inputs_(std::move(inputs)) + : FieldNode(false), function_(&function), inputs_(std::move(inputs)) { } @@ -204,12 +201,7 @@ class FieldOperation : public FieldNode { return *function_; } - bool is_operation_node() const override - { - return true; - } - - const CPPType &cpp_type_of_output_index(int output_index) const override + const CPPType &output_cpp_type(int output_index) const override { int output_counter = 0; for (const int param_index : function_->param_indices()) { @@ -244,7 +236,7 @@ class FieldInput : public FieldNode { public: FieldInput(const CPPType &type, std::string debug_name = "") - : type_(&type), debug_name_(std::move(debug_name)) + : FieldNode(true), type_(&type), debug_name_(std::move(debug_name)) { } @@ -262,17 +254,12 @@ class FieldInput : public FieldNode { return *type_; } - const CPPType &cpp_type_of_output_index(int output_index) const override + const CPPType &output_cpp_type(int output_index) const override { BLI_assert(output_index == 0); UNUSED_VARS_NDEBUG(output_index); return *type_; } - - bool is_input_node() const override - { - return true; - } }; Vector<const GVArray *> evaluate_fields(ResourceScope &scope, diff --git a/source/blender/functions/intern/field.cc b/source/blender/functions/intern/field.cc index 97c3b0b368e..2d44dcdb1cb 100644 --- a/source/blender/functions/intern/field.cc +++ b/source/blender/functions/intern/field.cc @@ -56,12 +56,12 @@ static FieldTreeInfo preprocess_field_tree(Span<GFieldRef> entry_fields) while (!fields_to_check.is_empty()) { GFieldRef field = fields_to_check.pop(); - if (field.has_input_node()) { + if (field.node().is_input()) { const FieldInput &field_input = static_cast<const FieldInput &>(field.node()); field_tree_info.deduplicated_field_inputs.add(field_input); continue; } - BLI_assert(field.has_operation_node()); + BLI_assert(field.node().is_operation()); const FieldOperation &operation = static_cast<const FieldOperation &>(field.node()); for (const GFieldRef operation_input : operation.inputs()) { field_tree_info.field_users.add(operation_input, field); @@ -173,7 +173,7 @@ static void build_multi_function_procedure_for_fields(MFProcedure &procedure, continue; } /* Field inputs should already be handled above. */ - BLI_assert(field.has_operation_node()); + BLI_assert(field.node().is_operation()); const FieldOperation &operation = static_cast<const FieldOperation &>(field.node()); const Span<GField> operation_inputs = operation.inputs(); @@ -288,7 +288,7 @@ Vector<const GVArray *> evaluate_fields(ResourceScope &scope, * processing. */ for (const int out_index : fields_to_evaluate.index_range()) { const GFieldRef &field = fields_to_evaluate[out_index]; - if (!field.has_input_node()) { + if (!field.node().is_input()) { continue; } const FieldInput &field_input = static_cast<const FieldInput &>(field.node()); |