Blender V4.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
15#include "BLI_cpp_type.hh"
17
19
20class DataType {
21 public:
26
27 private:
28 Category category_;
29 const CPPType *type_;
30
31 DataType(Category category, const CPPType &type);
32
33 public:
34 DataType() = default;
35
36 static DataType ForSingle(const CPPType &type);
37 static DataType ForVector(const CPPType &type);
38
39 template<typename T> static DataType ForSingle();
40 template<typename T> static DataType ForVector();
41
42 bool is_single() const;
43 bool is_vector() const;
44
45 Category category() const;
46
47 const CPPType &single_type() const;
48 const CPPType &vector_base_type() const;
49
51
52 std::string to_string() const;
53
54 uint64_t hash() const;
55};
56
57/* -------------------------------------------------------------------- */
61inline DataType::DataType(Category category, const CPPType &type)
62 : category_(category), type_(&type)
63{
64}
65
67{
68 return DataType(Single, type);
69}
70
72{
73 return DataType(Vector, type);
74}
75
76template<typename T> inline DataType DataType::ForSingle()
77{
79}
80
81template<typename T> inline DataType DataType::ForVector()
82{
84}
85
86inline bool DataType::is_single() const
87{
88 return category_ == Single;
89}
90
91inline bool DataType::is_vector() const
92{
93 return category_ == Vector;
94}
95
97{
98 return category_;
99}
100
101inline const CPPType &DataType::single_type() const
102{
103 BLI_assert(this->is_single());
104 return *type_;
105}
106
108{
109 BLI_assert(this->is_vector());
110 return *type_;
111}
112
113inline std::string DataType::to_string() const
114{
115 switch (category_) {
116 case Single:
117 return type_->name();
118 case Vector:
119 return type_->name() + " Vector";
120 }
121 BLI_assert(false);
122 return "";
123}
124
126{
127 return get_default_hash(*type_, category_);
128}
129
132} // namespace blender::fn::multi_function
#define BLI_assert(a)
Definition BLI_assert.h:50
#define BLI_STRUCT_EQUALITY_OPERATORS_2(Type, m1, m2)
StringRefNull name() const
static const CPPType & get()
uint64_t get_default_hash(const T &v)
Definition BLI_hash.hh:219
unsigned __int64 uint64_t
Definition stdint.h:90