Blender  V2.93
FN_multi_function_data_type.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 #include "FN_cpp_type.hh"
28 
29 namespace blender::fn {
30 
31 class MFDataType {
32  public:
33  enum Category {
36  };
37 
38  private:
39  Category category_;
40  const CPPType *type_;
41 
42  MFDataType(Category category, const CPPType &type) : category_(category), type_(&type)
43  {
44  }
45 
46  public:
47  MFDataType() = default;
48 
50  {
51  return MFDataType(Single, type);
52  }
53 
55  {
56  return MFDataType(Vector, type);
57  }
58 
59  template<typename T> static MFDataType ForSingle()
60  {
61  return MFDataType::ForSingle(CPPType::get<T>());
62  }
63 
64  template<typename T> static MFDataType ForVector()
65  {
66  return MFDataType::ForVector(CPPType::get<T>());
67  }
68 
69  bool is_single() const
70  {
71  return category_ == Single;
72  }
73 
74  bool is_vector() const
75  {
76  return category_ == Vector;
77  }
78 
80  {
81  return category_;
82  }
83 
84  const CPPType &single_type() const
85  {
86  BLI_assert(this->is_single());
87  return *type_;
88  }
89 
90  const CPPType &vector_base_type() const
91  {
92  BLI_assert(this->is_vector());
93  return *type_;
94  }
95 
96  friend bool operator==(const MFDataType &a, const MFDataType &b);
97  friend bool operator!=(const MFDataType &a, const MFDataType &b);
98 
99  std::string to_string() const
100  {
101  switch (category_) {
102  case Single:
103  return type_->name();
104  case Vector:
105  return type_->name() + " Vector";
106  }
107  BLI_assert(false);
108  return "";
109  }
110 
111  uint64_t hash() const
112  {
113  return get_default_hash_2(*type_, category_);
114  }
115 };
116 
117 inline bool operator==(const MFDataType &a, const MFDataType &b)
118 {
119  return a.category_ == b.category_ && a.type_ == b.type_;
120 }
121 
122 inline bool operator!=(const MFDataType &a, const MFDataType &b)
123 {
124  return !(a == b);
125 }
126 
127 } // namespace blender::fn
#define BLI_assert(a)
Definition: BLI_assert.h:58
_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
StringRefNull name() const
Definition: FN_cpp_type.hh:269
const CPPType & vector_base_type() const
friend bool operator!=(const MFDataType &a, const MFDataType &b)
const CPPType & single_type() const
static MFDataType ForVector(const CPPType &type)
friend bool operator==(const MFDataType &a, const MFDataType &b)
static MFDataType ForSingle(const CPPType &type)
static unsigned a[3]
Definition: RandGen.cpp:92
bool operator!=(const MFDataType &a, const MFDataType &b)
bool operator==(const MFDataType &a, const MFDataType &b)
uint64_t get_default_hash_2(const T1 &v1, const T2 &v2)
Definition: BLI_hash.hh:214
unsigned __int64 uint64_t
Definition: stdint.h:93