Changeset View
Changeset View
Standalone View
Standalone View
source/blender/functions/FN_multi_function_signature.hh
| Show All 24 Lines | |||||
| #include "FN_multi_function_param_type.hh" | #include "FN_multi_function_param_type.hh" | ||||
| #include "BLI_vector.hh" | #include "BLI_vector.hh" | ||||
| namespace blender::fn { | namespace blender::fn { | ||||
| struct MFSignature { | struct MFSignature { | ||||
| std::string function_name; | /** | ||||
| Vector<std::string> param_names; | * The name should be statically allocated so that it lives longer than this signature. This is | ||||
| * used instead of an #std::string because of the overhead when many functions are created. | |||||
| * If the name of the function has to be more dynamic for debugging purposes, override | |||||
| * #MultiFunction::debug_name() instead. Then the dynamic name will only be computed when it is | |||||
| * actually needed. | |||||
| */ | |||||
| const char *function_name; | |||||
| Vector<const char *> param_names; | |||||
| Vector<MFParamType> param_types; | Vector<MFParamType> param_types; | ||||
| Vector<int> param_data_indices; | Vector<int> param_data_indices; | ||||
| bool depends_on_context = false; | bool depends_on_context = false; | ||||
| int data_index(int param_index) const | int data_index(int param_index) const | ||||
| { | { | ||||
| return param_data_indices[param_index]; | return param_data_indices[param_index]; | ||||
| } | } | ||||
| }; | }; | ||||
| class MFSignatureBuilder { | class MFSignatureBuilder { | ||||
| private: | private: | ||||
| MFSignature signature_; | MFSignature signature_; | ||||
| int span_count_ = 0; | int span_count_ = 0; | ||||
| int virtual_array_count_ = 0; | int virtual_array_count_ = 0; | ||||
| int virtual_vector_array_count_ = 0; | int virtual_vector_array_count_ = 0; | ||||
| int vector_array_count_ = 0; | int vector_array_count_ = 0; | ||||
| public: | public: | ||||
| MFSignatureBuilder(std::string function_name) | MFSignatureBuilder(const char *function_name) | ||||
| { | { | ||||
| signature_.function_name = std::move(function_name); | signature_.function_name = function_name; | ||||
| } | } | ||||
| MFSignature build() const | MFSignature build() const | ||||
| { | { | ||||
| return std::move(signature_); | return std::move(signature_); | ||||
| } | } | ||||
| /* Input Parameter Types */ | /* Input Parameter Types */ | ||||
| template<typename T> void single_input(StringRef name) | template<typename T> void single_input(const char *name) | ||||
| { | { | ||||
| this->single_input(name, CPPType::get<T>()); | this->single_input(name, CPPType::get<T>()); | ||||
| } | } | ||||
| void single_input(StringRef name, const CPPType &type) | void single_input(const char *name, const CPPType &type) | ||||
| { | { | ||||
| this->input(name, MFDataType::ForSingle(type)); | this->input(name, MFDataType::ForSingle(type)); | ||||
| } | } | ||||
| template<typename T> void vector_input(StringRef name) | template<typename T> void vector_input(const char *name) | ||||
| { | { | ||||
| this->vector_input(name, CPPType::get<T>()); | this->vector_input(name, CPPType::get<T>()); | ||||
| } | } | ||||
| void vector_input(StringRef name, const CPPType &base_type) | void vector_input(const char *name, const CPPType &base_type) | ||||
| { | { | ||||
| this->input(name, MFDataType::ForVector(base_type)); | this->input(name, MFDataType::ForVector(base_type)); | ||||
| } | } | ||||
| void input(StringRef name, MFDataType data_type) | void input(const char *name, MFDataType data_type) | ||||
| { | { | ||||
| signature_.param_names.append(name); | signature_.param_names.append(name); | ||||
| signature_.param_types.append(MFParamType(MFParamType::Input, data_type)); | signature_.param_types.append(MFParamType(MFParamType::Input, data_type)); | ||||
| switch (data_type.category()) { | switch (data_type.category()) { | ||||
| case MFDataType::Single: | case MFDataType::Single: | ||||
| signature_.param_data_indices.append(virtual_array_count_++); | signature_.param_data_indices.append(virtual_array_count_++); | ||||
| break; | break; | ||||
| case MFDataType::Vector: | case MFDataType::Vector: | ||||
| signature_.param_data_indices.append(virtual_vector_array_count_++); | signature_.param_data_indices.append(virtual_vector_array_count_++); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| /* Output Parameter Types */ | /* Output Parameter Types */ | ||||
| template<typename T> void single_output(StringRef name) | template<typename T> void single_output(const char *name) | ||||
| { | { | ||||
| this->single_output(name, CPPType::get<T>()); | this->single_output(name, CPPType::get<T>()); | ||||
| } | } | ||||
| void single_output(StringRef name, const CPPType &type) | void single_output(const char *name, const CPPType &type) | ||||
| { | { | ||||
| this->output(name, MFDataType::ForSingle(type)); | this->output(name, MFDataType::ForSingle(type)); | ||||
| } | } | ||||
| template<typename T> void vector_output(StringRef name) | template<typename T> void vector_output(const char *name) | ||||
| { | { | ||||
| this->vector_output(name, CPPType::get<T>()); | this->vector_output(name, CPPType::get<T>()); | ||||
| } | } | ||||
| void vector_output(StringRef name, const CPPType &base_type) | void vector_output(const char *name, const CPPType &base_type) | ||||
| { | { | ||||
| this->output(name, MFDataType::ForVector(base_type)); | this->output(name, MFDataType::ForVector(base_type)); | ||||
| } | } | ||||
| void output(StringRef name, MFDataType data_type) | void output(const char *name, MFDataType data_type) | ||||
| { | { | ||||
| signature_.param_names.append(name); | signature_.param_names.append(name); | ||||
| signature_.param_types.append(MFParamType(MFParamType::Output, data_type)); | signature_.param_types.append(MFParamType(MFParamType::Output, data_type)); | ||||
| switch (data_type.category()) { | switch (data_type.category()) { | ||||
| case MFDataType::Single: | case MFDataType::Single: | ||||
| signature_.param_data_indices.append(span_count_++); | signature_.param_data_indices.append(span_count_++); | ||||
| break; | break; | ||||
| case MFDataType::Vector: | case MFDataType::Vector: | ||||
| signature_.param_data_indices.append(vector_array_count_++); | signature_.param_data_indices.append(vector_array_count_++); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| /* Mutable Parameter Types */ | /* Mutable Parameter Types */ | ||||
| template<typename T> void single_mutable(StringRef name) | template<typename T> void single_mutable(const char *name) | ||||
| { | { | ||||
| this->single_mutable(name, CPPType::get<T>()); | this->single_mutable(name, CPPType::get<T>()); | ||||
| } | } | ||||
| void single_mutable(StringRef name, const CPPType &type) | void single_mutable(const char *name, const CPPType &type) | ||||
| { | { | ||||
| this->mutable_(name, MFDataType::ForSingle(type)); | this->mutable_(name, MFDataType::ForSingle(type)); | ||||
| } | } | ||||
| template<typename T> void vector_mutable(StringRef name) | template<typename T> void vector_mutable(const char *name) | ||||
| { | { | ||||
| this->vector_mutable(name, CPPType::get<T>()); | this->vector_mutable(name, CPPType::get<T>()); | ||||
| } | } | ||||
| void vector_mutable(StringRef name, const CPPType &base_type) | void vector_mutable(const char *name, const CPPType &base_type) | ||||
| { | { | ||||
| this->mutable_(name, MFDataType::ForVector(base_type)); | this->mutable_(name, MFDataType::ForVector(base_type)); | ||||
| } | } | ||||
| void mutable_(StringRef name, MFDataType data_type) | void mutable_(const char *name, MFDataType data_type) | ||||
| { | { | ||||
| signature_.param_names.append(name); | signature_.param_names.append(name); | ||||
| signature_.param_types.append(MFParamType(MFParamType::Mutable, data_type)); | signature_.param_types.append(MFParamType(MFParamType::Mutable, data_type)); | ||||
| switch (data_type.category()) { | switch (data_type.category()) { | ||||
| case MFDataType::Single: | case MFDataType::Single: | ||||
| signature_.param_data_indices.append(span_count_++); | signature_.param_data_indices.append(span_count_++); | ||||
| break; | break; | ||||
| case MFDataType::Vector: | case MFDataType::Vector: | ||||
| signature_.param_data_indices.append(vector_array_count_++); | signature_.param_data_indices.append(vector_array_count_++); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| void add(StringRef name, const MFParamType ¶m_type) | void add(const char *name, const MFParamType ¶m_type) | ||||
| { | { | ||||
| switch (param_type.interface_type()) { | switch (param_type.interface_type()) { | ||||
| case MFParamType::Input: | case MFParamType::Input: | ||||
| this->input(name, param_type.data_type()); | this->input(name, param_type.data_type()); | ||||
| break; | break; | ||||
| case MFParamType::Mutable: | case MFParamType::Mutable: | ||||
| this->mutable_(name, param_type.data_type()); | this->mutable_(name, param_type.data_type()); | ||||
| break; | break; | ||||
| Show All 17 Lines | |||||