Blender  V2.93
FN_multi_function.hh
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
47 #include "BLI_hash.hh"
48 
51 
52 namespace blender::fn {
53 
55  private:
56  const MFSignature *signature_ref_ = nullptr;
57 
58  public:
59  virtual ~MultiFunction()
60  {
61  }
62 
63  virtual void call(IndexMask mask, MFParams params, MFContext context) const = 0;
64 
65  virtual uint64_t hash() const
66  {
67  return get_default_hash(this);
68  }
69 
70  virtual bool equals(const MultiFunction &UNUSED(other)) const
71  {
72  return false;
73  }
74 
75  int param_amount() const
76  {
77  return signature_ref_->param_types.size();
78  }
79 
81  {
82  return signature_ref_->param_types.index_range();
83  }
84 
85  MFParamType param_type(int param_index) const
86  {
87  return signature_ref_->param_types[param_index];
88  }
89 
90  StringRefNull param_name(int param_index) const
91  {
92  return signature_ref_->param_names[param_index];
93  }
94 
96  {
97  return signature_ref_->function_name;
98  }
99 
100  bool depends_on_context() const
101  {
102  return signature_ref_->depends_on_context;
103  }
104 
105  const MFSignature &signature() const
106  {
107  BLI_assert(signature_ref_ != nullptr);
108  return *signature_ref_;
109  }
110 
111  protected:
112  /* Make the function use the given signature. This should be called once in the constructor of
113  * child classes. No copy of the signature is made, so the caller has to make sure that the
114  * signature lives as long as the multi function. It is ok to embed the signature into the child
115  * class. */
117  {
118  /* Take a pointer as argument, so that it is more obvious that no copy is created. */
119  BLI_assert(signature != nullptr);
120  signature_ref_ = signature;
121  }
122 };
123 
124 inline MFParamsBuilder::MFParamsBuilder(const class MultiFunction &fn, int64_t min_array_size)
125  : MFParamsBuilder(fn.signature(), min_array_size)
126 {
127 }
128 
129 extern const MultiFunction &dummy_multi_function;
130 
131 namespace multi_function_types {
132 using fn::CPPType;
133 using fn::GMutableSpan;
134 using fn::GSpan;
135 using fn::MFContext;
137 using fn::MFDataType;
138 using fn::MFParams;
139 using fn::MFParamsBuilder;
140 using fn::MFParamType;
141 using fn::MultiFunction;
142 } // namespace multi_function_types
143 
144 } // namespace blender::fn
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define UNUSED(x)
MFParamsBuilder(const MFSignature &signature, int64_t min_array_size)
virtual uint64_t hash() const
StringRefNull name() const
StringRefNull param_name(int param_index) const
MFParamType param_type(int param_index) const
IndexRange param_indices() const
void set_signature(const MFSignature *signature)
virtual void call(IndexMask mask, MFParams params, MFContext context) const =0
virtual bool equals(const MultiFunction &UNUSED(other)) const
const MFSignature & signature() const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
const MultiFunction & dummy_multi_function
uint64_t get_default_hash(const T &v)
Definition: BLI_hash.hh:209
struct SELECTID_Context context
Definition: select_engine.c:47
__int64 int64_t
Definition: stdint.h:92
unsigned __int64 uint64_t
Definition: stdint.h:93
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)