Blender  V3.3
FN_multi_function_param_type.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
22 
23 namespace blender::fn {
24 
25 enum class MFParamCategory {
32 };
33 
34 template<MFParamCategory Category, typename T> struct MFParamTag {
35  static constexpr MFParamCategory category = Category;
36  using base_type = T;
37  /* TODO: Doesn't support all categories yet, this can be generalized when necessary. */
38  using array_type =
39  std::conditional_t<Category == MFParamCategory::SingleInput, VArray<T>, MutableSpan<T>>;
40 };
41 
42 class MFParamType {
43  public:
48  };
49 
50  private:
51  InterfaceType interface_type_;
52  MFDataType data_type_;
53 
54  public:
56  : interface_type_(interface_type), data_type_(data_type)
57  {
58  }
59 
61  {
62  return MFParamType(InterfaceType::Input, MFDataType::ForSingle(type));
63  }
64 
65  static MFParamType ForVectorInput(const CPPType &base_type)
66  {
67  return MFParamType(InterfaceType::Input, MFDataType::ForVector(base_type));
68  }
69 
71  {
73  }
74 
75  static MFParamType ForVectorOutput(const CPPType &base_type)
76  {
78  }
79 
81  {
82  return MFParamType(InterfaceType::Mutable, MFDataType::ForSingle(type));
83  }
84 
85  static MFParamType ForMutableVector(const CPPType &base_type)
86  {
87  return MFParamType(InterfaceType::Mutable, MFDataType::ForVector(base_type));
88  }
89 
91  {
92  return data_type_;
93  }
94 
96  {
97  return interface_type_;
98  }
99 
101  {
102  switch (data_type_.category()) {
103  case MFDataType::Single: {
104  switch (interface_type_) {
105  case Input:
107  case Output:
109  case Mutable:
111  }
112  break;
113  }
114  case MFDataType::Vector: {
115  switch (interface_type_) {
116  case Input:
118  case Output:
120  case Mutable:
122  }
123  break;
124  }
125  }
128  }
129 
130  bool is_input_or_mutable() const
131  {
132  return ELEM(interface_type_, Input, Mutable);
133  }
134 
135  bool is_output_or_mutable() const
136  {
137  return ELEM(interface_type_, Output, Mutable);
138  }
139 
140  bool is_output() const
141  {
142  return interface_type_ == Output;
143  }
144 
145  friend bool operator==(const MFParamType &a, const MFParamType &b);
146  friend bool operator!=(const MFParamType &a, const MFParamType &b);
147 };
148 
149 inline bool operator==(const MFParamType &a, const MFParamType &b)
150 {
151  return a.interface_type_ == b.interface_type_ && a.data_type_ == b.data_type_;
152 }
153 
154 inline bool operator!=(const MFParamType &a, const MFParamType &b)
155 {
156  return !(a == b);
157 }
158 
159 } // namespace blender::fn
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
#define ELEM(...)
_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
Group Output
static MFParamType ForVectorInput(const CPPType &base_type)
static MFParamType ForSingleOutput(const CPPType &type)
static MFParamType ForMutableSingle(const CPPType &type)
friend bool operator!=(const MFParamType &a, const MFParamType &b)
static MFParamType ForVectorOutput(const CPPType &base_type)
friend bool operator==(const MFParamType &a, const MFParamType &b)
static MFParamType ForMutableVector(const CPPType &base_type)
MFParamType(InterfaceType interface_type, MFDataType data_type)
static MFParamType ForSingleInput(const CPPType &type)
#define T
static unsigned a[3]
Definition: RandGen.cpp:78
bool operator==(const FieldNode &a, const FieldNode &b)
Definition: FN_field.hh:605
bool operator!=(const FieldNode &a, const FieldNode &b)
Definition: FN_field.hh:610
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
std::conditional_t< Category==MFParamCategory::SingleInput, VArray< T >, MutableSpan< T > > array_type
static constexpr MFParamCategory category