Blender  V3.3
FN_multi_function_data_type.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
13 #include "BLI_cpp_type.hh"
14 
15 namespace blender::fn {
16 
17 class MFDataType {
18  public:
19  enum Category {
22  };
23 
24  private:
25  Category category_;
26  const CPPType *type_;
27 
28  MFDataType(Category category, const CPPType &type) : category_(category), type_(&type)
29  {
30  }
31 
32  public:
33  MFDataType() = default;
34 
36  {
37  return MFDataType(Single, type);
38  }
39 
41  {
42  return MFDataType(Vector, type);
43  }
44 
45  template<typename T> static MFDataType ForSingle()
46  {
47  return MFDataType::ForSingle(CPPType::get<T>());
48  }
49 
50  template<typename T> static MFDataType ForVector()
51  {
52  return MFDataType::ForVector(CPPType::get<T>());
53  }
54 
55  bool is_single() const
56  {
57  return category_ == Single;
58  }
59 
60  bool is_vector() const
61  {
62  return category_ == Vector;
63  }
64 
66  {
67  return category_;
68  }
69 
70  const CPPType &single_type() const
71  {
72  BLI_assert(this->is_single());
73  return *type_;
74  }
75 
76  const CPPType &vector_base_type() const
77  {
78  BLI_assert(this->is_vector());
79  return *type_;
80  }
81 
82  friend bool operator==(const MFDataType &a, const MFDataType &b);
83  friend bool operator!=(const MFDataType &a, const MFDataType &b);
84 
85  std::string to_string() const
86  {
87  switch (category_) {
88  case Single:
89  return type_->name();
90  case Vector:
91  return type_->name() + " Vector";
92  }
93  BLI_assert(false);
94  return "";
95  }
96 
97  uint64_t hash() const
98  {
99  return get_default_hash_2(*type_, category_);
100  }
101 };
102 
103 inline bool operator==(const MFDataType &a, const MFDataType &b)
104 {
105  return a.category_ == b.category_ && a.type_ == b.type_;
106 }
107 
108 inline bool operator!=(const MFDataType &a, const MFDataType &b)
109 {
110  return !(a == b);
111 }
112 
113 } // namespace blender::fn
#define BLI_assert(a)
Definition: BLI_assert.h:46
_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
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: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
uint64_t get_default_hash_2(const T1 &v1, const T2 &v2)
Definition: BLI_hash.hh:223
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
unsigned __int64 uint64_t
Definition: stdint.h:90