Blender V4.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
35#include "BLI_hash.hh"
36
39
41
43 private:
44 const Signature *signature_ref_ = nullptr;
45
46 public:
47 virtual ~MultiFunction() {}
48
55 void call_auto(const IndexMask &mask, Params params, Context context) const;
56 virtual void call(const IndexMask &mask, Params params, Context context) const = 0;
57
58 virtual uint64_t hash() const
59 {
60 return get_default_hash(this);
61 }
62
63 virtual bool equals(const MultiFunction & /*other*/) const
64 {
65 return false;
66 }
67
68 int param_amount() const
69 {
70 return signature_ref_->params.size();
71 }
72
74 {
75 return signature_ref_->params.index_range();
76 }
77
78 ParamType param_type(int param_index) const
79 {
80 return signature_ref_->params[param_index].type;
81 }
82
83 StringRefNull param_name(int param_index) const
84 {
85 return signature_ref_->params[param_index].name;
86 }
87
89 {
90 return signature_ref_->function_name;
91 }
92
93 virtual std::string debug_name() const;
94
95 const Signature &signature() const
96 {
97 BLI_assert(signature_ref_ != nullptr);
98 return *signature_ref_;
99 }
100
123
125
126 protected:
127 /* Make the function use the given signature. This should be called once in the constructor of
128 * child classes. No copy of the signature is made, so the caller has to make sure that the
129 * signature lives as long as the multi function. It is ok to embed the signature into the child
130 * class. */
132 {
133 /* Take a pointer as argument, so that it is more obvious that no copy is created. */
134 BLI_assert(signature != nullptr);
135 signature_ref_ = signature;
136 }
137
138 virtual ExecutionHints get_execution_hints() const;
139};
140
141inline ParamsBuilder::ParamsBuilder(const MultiFunction &fn, const IndexMask *mask)
142 : ParamsBuilder(fn.signature(), *mask)
143{
144}
145
146} // namespace blender::fn::multi_function
147
148namespace blender {
149namespace mf = fn::multi_function;
150}
#define BLI_assert(a)
Definition BLI_assert.h:50
void set_signature(const Signature *signature)
ParamType param_type(int param_index) const
StringRefNull param_name(int param_index) const
virtual void call(const IndexMask &mask, Params params, Context context) const =0
virtual bool equals(const MultiFunction &) const
virtual ExecutionHints get_execution_hints() const
void call_auto(const IndexMask &mask, Params params, Context context) const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
uint64_t get_default_hash(const T &v)
Definition BLI_hash.hh:219
__int64 int64_t
Definition stdint.h:89
unsigned __int64 uint64_t
Definition stdint.h:90