Blender V5.3
FN_multi_function_data_type.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
14
15#include "BLI_cpp_type.hh"
16
18
19class DataType {
20 public:
25
26 private:
27 Category category_;
28 const CPPType *type_;
29
30 DataType(Category category, const CPPType &type);
31
32 public:
33 DataType() = default;
34
35 static DataType ForSingle(const CPPType &type);
36 static DataType ForVector(const CPPType &type);
37
38 template<typename T> static DataType ForSingle();
39 template<typename T> static DataType ForVector();
40
41 bool is_single() const;
42 bool is_vector() const;
43
44 Category category() const;
45
46 const CPPType &single_type() const;
47 const CPPType &vector_base_type() const;
48
49 friend bool operator==(const DataType &a, const DataType &b) = default;
50
51 std::string to_string() const;
52
53 uint64_t hash() const;
54};
55
56/* -------------------------------------------------------------------- */
59
60inline DataType::DataType(Category category, const CPPType &type)
61 : category_(category), type_(&type)
62{
63}
64
65inline DataType DataType::ForSingle(const CPPType &type)
66{
67 return DataType(Single, type);
68}
69
70inline DataType DataType::ForVector(const CPPType &type)
71{
72 return DataType(Vector, type);
73}
74
75template<typename T> inline DataType DataType::ForSingle()
76{
78}
79
80template<typename T> inline DataType DataType::ForVector()
81{
83}
84
85inline bool DataType::is_single() const
86{
87 return category_ == Single;
88}
89
90inline bool DataType::is_vector() const
91{
92 return category_ == Vector;
93}
94
96{
97 return category_;
98}
99
100inline const CPPType &DataType::single_type() const
101{
102 BLI_assert(this->is_single());
103 return *type_;
104}
105
107{
108 BLI_assert(this->is_vector());
109 return *type_;
110}
111
112inline std::string DataType::to_string() const
113{
114 switch (category_) {
115 case Single:
116 return type_->name();
117 case Vector:
118 return type_->name() + " Vector";
119 }
120 BLI_assert(false);
121 return "";
122}
123
125{
126 return get_default_hash(*type_, category_);
127}
128
130
131} // namespace blender::fn::multi_function
static const CPPType & get()
static DataType ForVector(const CPPType &type)
static DataType ForSingle(const CPPType &type)
friend bool operator==(const DataType &a, const DataType &b)=default
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252