Blender  V2.93
FN_multi_function_signature.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 
27 
28 #include "BLI_vector.hh"
29 
30 namespace blender::fn {
31 
32 struct MFSignature {
33  std::string function_name;
37  bool depends_on_context = false;
38 
39  int data_index(int param_index) const
40  {
41  return param_data_indices[param_index];
42  }
43 };
44 
46  private:
47  MFSignature signature_;
48  int span_count_ = 0;
49  int virtual_array_count_ = 0;
50  int virtual_vector_array_count_ = 0;
51  int vector_array_count_ = 0;
52 
53  public:
54  MFSignatureBuilder(std::string function_name)
55  {
56  signature_.function_name = std::move(function_name);
57  }
58 
60  {
61  return std::move(signature_);
62  }
63 
64  /* Input Parameter Types */
65 
66  template<typename T> void single_input(StringRef name)
67  {
68  this->single_input(name, CPPType::get<T>());
69  }
70  void single_input(StringRef name, const CPPType &type)
71  {
72  this->input(name, MFDataType::ForSingle(type));
73  }
74  template<typename T> void vector_input(StringRef name)
75  {
76  this->vector_input(name, CPPType::get<T>());
77  }
78  void vector_input(StringRef name, const CPPType &base_type)
79  {
80  this->input(name, MFDataType::ForVector(base_type));
81  }
82  void input(StringRef name, MFDataType data_type)
83  {
84  signature_.param_names.append(name);
85  signature_.param_types.append(MFParamType(MFParamType::Input, data_type));
86 
87  switch (data_type.category()) {
88  case MFDataType::Single:
89  signature_.param_data_indices.append(virtual_array_count_++);
90  break;
91  case MFDataType::Vector:
92  signature_.param_data_indices.append(virtual_vector_array_count_++);
93  break;
94  }
95  }
96 
97  /* Output Parameter Types */
98 
99  template<typename T> void single_output(StringRef name)
100  {
101  this->single_output(name, CPPType::get<T>());
102  }
103  void single_output(StringRef name, const CPPType &type)
104  {
105  this->output(name, MFDataType::ForSingle(type));
106  }
107  template<typename T> void vector_output(StringRef name)
108  {
109  this->vector_output(name, CPPType::get<T>());
110  }
111  void vector_output(StringRef name, const CPPType &base_type)
112  {
113  this->output(name, MFDataType::ForVector(base_type));
114  }
115  void output(StringRef name, MFDataType data_type)
116  {
117  signature_.param_names.append(name);
118  signature_.param_types.append(MFParamType(MFParamType::Output, data_type));
119 
120  switch (data_type.category()) {
121  case MFDataType::Single:
122  signature_.param_data_indices.append(span_count_++);
123  break;
124  case MFDataType::Vector:
125  signature_.param_data_indices.append(vector_array_count_++);
126  break;
127  }
128  }
129 
130  /* Mutable Parameter Types */
131 
132  template<typename T> void single_mutable(StringRef name)
133  {
134  this->single_mutable(name, CPPType::get<T>());
135  }
137  {
138  this->mutable_(name, MFDataType::ForSingle(type));
139  }
140  template<typename T> void vector_mutable(StringRef name)
141  {
142  this->vector_mutable(name, CPPType::get<T>());
143  }
144  void vector_mutable(StringRef name, const CPPType &base_type)
145  {
146  this->mutable_(name, MFDataType::ForVector(base_type));
147  }
148  void mutable_(StringRef name, MFDataType data_type)
149  {
150  signature_.param_names.append(name);
151  signature_.param_types.append(MFParamType(MFParamType::Mutable, data_type));
152 
153  switch (data_type.category()) {
154  case MFDataType::Single:
155  signature_.param_data_indices.append(span_count_++);
156  break;
157  case MFDataType::Vector:
158  signature_.param_data_indices.append(vector_array_count_++);
159  break;
160  }
161  }
162 
163  /* Context */
164 
168  {
169  signature_.depends_on_context = true;
170  }
171 };
172 
173 } // namespace blender::fn
_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 vector_output(StringRef name, const CPPType &base_type)
void single_mutable(StringRef name, const CPPType &type)
void vector_mutable(StringRef name, const CPPType &base_type)
void single_output(StringRef name, const CPPType &type)
MFSignatureBuilder(std::string function_name)
void single_input(StringRef name, const CPPType &type)
void vector_input(StringRef name, const CPPType &base_type)
void mutable_(StringRef name, MFDataType data_type)
void input(StringRef name, MFDataType data_type)
void output(StringRef name, MFDataType data_type)
int data_index(int param_index) const