Blender  V3.3
FN_multi_function.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
33 #include "BLI_hash.hh"
34 
37 
38 namespace blender::fn {
39 
41  private:
42  const MFSignature *signature_ref_ = nullptr;
43 
44  public:
45  virtual ~MultiFunction()
46  {
47  }
48 
56  virtual void call(IndexMask mask, MFParams params, MFContext 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 &UNUSED(other)) const
64  {
65  return false;
66  }
67 
68  int param_amount() const
69  {
70  return signature_ref_->param_types.size();
71  }
72 
74  {
75  return signature_ref_->param_types.index_range();
76  }
77 
78  MFParamType param_type(int param_index) const
79  {
80  return signature_ref_->param_types[param_index];
81  }
82 
83  StringRefNull param_name(int param_index) const
84  {
85  return signature_ref_->param_names[param_index];
86  }
87 
89  {
90  return signature_ref_->function_name;
91  }
92 
93  virtual std::string debug_name() const;
94 
95  bool depends_on_context() const
96  {
97  return signature_ref_->depends_on_context;
98  }
99 
100  const MFSignature &signature() const
101  {
102  BLI_assert(signature_ref_ != nullptr);
103  return *signature_ref_;
104  }
105 
109  struct ExecutionHints {
121  bool allocates_array = false;
127  };
128 
130 
131  protected:
132  /* Make the function use the given signature. This should be called once in the constructor of
133  * child classes. No copy of the signature is made, so the caller has to make sure that the
134  * signature lives as long as the multi function. It is ok to embed the signature into the child
135  * class. */
137  {
138  /* Take a pointer as argument, so that it is more obvious that no copy is created. */
139  BLI_assert(signature != nullptr);
140  signature_ref_ = signature;
141  }
142 
143  virtual ExecutionHints get_execution_hints() const;
144 };
145 
146 inline MFParamsBuilder::MFParamsBuilder(const MultiFunction &fn, int64_t mask_size)
147  : MFParamsBuilder(fn.signature(), IndexMask(mask_size))
148 {
149 }
150 
151 inline MFParamsBuilder::MFParamsBuilder(const MultiFunction &fn, const IndexMask *mask)
152  : MFParamsBuilder(fn.signature(), *mask)
153 {
154 }
155 
156 namespace multi_function_types {
157 using fn::MFContext;
159 using fn::MFDataType;
160 using fn::MFParams;
161 using fn::MFParamsBuilder;
162 using fn::MFParamType;
163 using fn::MultiFunction;
164 } // namespace multi_function_types
165 
166 } // namespace blender::fn
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define UNUSED(x)
virtual ExecutionHints get_execution_hints() const
virtual uint64_t hash() const
StringRefNull name() const
StringRefNull param_name(int param_index) const
MFParamType param_type(int param_index) const
virtual std::string debug_name() const
IndexRange param_indices() const
void call_auto(IndexMask mask, MFParams params, MFContext context) const
void set_signature(const MFSignature *signature)
virtual void call(IndexMask mask, MFParams params, MFContext context) const =0
ExecutionHints execution_hints() const
virtual bool equals(const MultiFunction &UNUSED(other)) const
const MFSignature & signature() const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
uint64_t get_default_hash(const T &v)
Definition: BLI_hash.hh:218
__int64 int64_t
Definition: stdint.h:89
unsigned __int64 uint64_t
Definition: stdint.h:90