Blender V5.3
FN_multi_function.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
34
35#include "BLI_unique_hash.hh"
38
39namespace blender {
40
41namespace fn::multi_function {
42
44 private:
45 const Signature *signature_ref_ = nullptr;
46
47 public:
48 virtual ~MultiFunction() = default;
49
56 void call_auto(const IndexMask &mask, Params params, Context context) const;
57 virtual void call(const IndexMask &mask, Params params, Context context) const = 0;
58
59 virtual void hash_unique(UniqueHashBytes &hash) const;
60 virtual bool equals(const MultiFunction &other) const;
61
62 int param_amount() const
63 {
64 return signature_ref_->params.size();
65 }
66
68 {
69 return signature_ref_->params.index_range();
70 }
71
72 ParamType param_type(int param_index) const
73 {
74 return signature_ref_->params[param_index].type;
75 }
76
77 StringRefNull param_name(int param_index) const
78 {
79 return signature_ref_->params[param_index].name;
80 }
81
83 {
84 return signature_ref_->function_name;
85 }
86
87 virtual std::string debug_name() const;
88
89 const Signature &signature() const
90 {
91 BLI_assert(signature_ref_ != nullptr);
92 return *signature_ref_;
93 }
94
110 bool allocates_array = false;
116 };
117
119
126 virtual void prepare_for_execution() const {}
127
128 protected:
129 /* Make the function use the given signature. This should be called once in the constructor of
130 * child classes. No copy of the signature is made, so the caller has to make sure that the
131 * signature lives as long as the multi function. It is ok to embed the signature into the child
132 * class. */
134 {
135 /* Take a pointer as argument, so that it is more obvious that no copy is created. */
136 BLI_assert(signature != nullptr);
137 signature_ref_ = signature;
138 }
139
140 virtual ExecutionHints get_execution_hints() const;
141};
142
143inline ParamsBuilder::ParamsBuilder(const MultiFunction &fn, const IndexMask *mask)
144 : ParamsBuilder(fn.signature(), *mask)
145{
146}
147
148} // namespace fn::multi_function
149
150namespace mf = fn::multi_function;
151
152} // namespace blender
constexpr IndexRange index_range() const
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
void set_signature(const Signature *signature)
ParamType param_type(int param_index) const
virtual bool equals(const MultiFunction &other) const
StringRefNull param_name(int param_index) const
virtual void call(const IndexMask &mask, Params params, Context context) const =0
virtual void hash_unique(UniqueHashBytes &hash) const
virtual ExecutionHints get_execution_hints() const
void call_auto(const IndexMask &mask, Params params, Context context) const
MultiFunction::ExecutionHints ExecutionHints
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
#define hash
Definition noise_c.cc:156