Blender  V3.3
FN_multi_function_signature.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
13 
14 #include "BLI_vector.hh"
15 
16 namespace blender::fn {
17 
18 struct MFSignature {
26  const char *function_name;
30  bool depends_on_context = false;
31 
36  int span_num = 0;
40 
41  int data_index(int param_index) const
42  {
43  return param_data_indices[param_index];
44  }
45 };
46 
48  private:
49  MFSignature signature_;
50 
51  public:
52  MFSignatureBuilder(const char *function_name)
53  {
54  signature_.function_name = function_name;
55  }
56 
58  {
59  return std::move(signature_);
60  }
61 
62  /* Input Parameter Types */
63 
64  template<typename T> void single_input(const char *name)
65  {
66  this->single_input(name, CPPType::get<T>());
67  }
68  void single_input(const char *name, const CPPType &type)
69  {
70  this->input(name, MFDataType::ForSingle(type));
71  }
72  template<typename T> void vector_input(const char *name)
73  {
74  this->vector_input(name, CPPType::get<T>());
75  }
76  void vector_input(const char *name, const CPPType &base_type)
77  {
78  this->input(name, MFDataType::ForVector(base_type));
79  }
80  void input(const char *name, MFDataType data_type)
81  {
82  signature_.param_names.append(name);
83  signature_.param_types.append(MFParamType(MFParamType::Input, data_type));
84 
85  switch (data_type.category()) {
86  case MFDataType::Single:
87  signature_.param_data_indices.append(signature_.virtual_array_num++);
88  break;
89  case MFDataType::Vector:
90  signature_.param_data_indices.append(signature_.virtual_vector_array_num++);
91  break;
92  }
93  }
94 
95  /* Output Parameter Types */
96 
97  template<typename T> void single_output(const char *name)
98  {
99  this->single_output(name, CPPType::get<T>());
100  }
101  void single_output(const char *name, const CPPType &type)
102  {
103  this->output(name, MFDataType::ForSingle(type));
104  }
105  template<typename T> void vector_output(const char *name)
106  {
107  this->vector_output(name, CPPType::get<T>());
108  }
109  void vector_output(const char *name, const CPPType &base_type)
110  {
111  this->output(name, MFDataType::ForVector(base_type));
112  }
113  void output(const char *name, MFDataType data_type)
114  {
115  signature_.param_names.append(name);
116  signature_.param_types.append(MFParamType(MFParamType::Output, data_type));
117 
118  switch (data_type.category()) {
119  case MFDataType::Single:
120  signature_.param_data_indices.append(signature_.span_num++);
121  break;
122  case MFDataType::Vector:
123  signature_.param_data_indices.append(signature_.vector_array_num++);
124  break;
125  }
126  }
127 
128  /* Mutable Parameter Types */
129 
130  template<typename T> void single_mutable(const char *name)
131  {
132  this->single_mutable(name, CPPType::get<T>());
133  }
134  void single_mutable(const char *name, const CPPType &type)
135  {
136  this->mutable_(name, MFDataType::ForSingle(type));
137  }
138  template<typename T> void vector_mutable(const char *name)
139  {
140  this->vector_mutable(name, CPPType::get<T>());
141  }
142  void vector_mutable(const char *name, const CPPType &base_type)
143  {
144  this->mutable_(name, MFDataType::ForVector(base_type));
145  }
146  void mutable_(const char *name, MFDataType data_type)
147  {
148  signature_.param_names.append(name);
149  signature_.param_types.append(MFParamType(MFParamType::Mutable, data_type));
150 
151  switch (data_type.category()) {
152  case MFDataType::Single:
153  signature_.param_data_indices.append(signature_.span_num++);
154  break;
155  case MFDataType::Vector:
156  signature_.param_data_indices.append(signature_.vector_array_num++);
157  break;
158  }
159  }
160 
161  void add(const char *name, const MFParamType &param_type)
162  {
163  switch (param_type.interface_type()) {
164  case MFParamType::Input:
165  this->input(name, param_type.data_type());
166  break;
168  this->mutable_(name, param_type.data_type());
169  break;
170  case MFParamType::Output:
171  this->output(name, param_type.data_type());
172  break;
173  }
174  }
175 
176  template<MFParamCategory Category, typename T>
177  void add(MFParamTag<Category, T> /* tag */, const char *name)
178  {
179  switch (Category) {
181  this->single_input<T>(name);
182  return;
184  this->vector_input<T>(name);
185  return;
187  this->single_output<T>(name);
188  return;
190  this->vector_output<T>(name);
191  return;
193  this->single_mutable<T>(name);
194  return;
196  this->vector_mutable<T>(name);
197  return;
198  }
200  }
201 
202  /* Context */
203 
207  {
208  signature_.depends_on_context = true;
209  }
210 };
211 
212 } // namespace blender::fn
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
void append(const T &value)
Definition: BLI_vector.hh:433
void vector_mutable(const char *name, const CPPType &base_type)
void add(const char *name, const MFParamType &param_type)
void input(const char *name, MFDataType data_type)
void mutable_(const char *name, MFDataType data_type)
MFSignatureBuilder(const char *function_name)
void single_output(const char *name, const CPPType &type)
void output(const char *name, MFDataType data_type)
void vector_output(const char *name, const CPPType &base_type)
void vector_input(const char *name, const CPPType &base_type)
void single_input(const char *name, const CPPType &type)
void add(MFParamTag< Category, T >, const char *name)
void single_mutable(const char *name, const CPPType &type)
int data_index(int param_index) const