Blender V5.3
NOD_bundle_type.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <variant>
12
13#include "BLI_set.hh"
14#include "BLI_vector_set.hh"
15
19
20namespace blender::nodes {
21
23 public:
24 struct Item {
25 std::unique_ptr<SocketDeclaration> decl;
26
27 UString name() const;
28 };
29
30 private:
31 struct ItemNameGetter {
32 UString operator()(const Item &item)
33 {
34 return item.decl->name;
35 }
36 };
37
38 std::string name_;
40
41 public:
42 FlatBundleType(std::string name, Vector<std::unique_ptr<SocketDeclaration>> decls);
43
44 StringRefNull name() const;
45
46 Span<Item> items() const;
47 const SocketDeclaration *find_decl(const UString name) const;
48
50};
51
53 private:
54 struct ItemNameGetter {
55 std::string operator()(const FlatBundleTypePtr &item)
56 {
57 return item->name();
58 }
59 };
60
61 std::string name_;
63
64 public:
65 NestedBundleType(std::string name, Vector<FlatBundleTypePtr> bundle_types);
66
67 StringRefNull name() const;
69};
70
72 public:
73 std::variant<FlatBundleTypePtr, NestedBundleTypePtr> type;
74
77
78 StringRefNull name() const;
79
80 uint64_t hash() const;
81
82 friend bool operator==(const BundleType &a, const BundleType &b) = default;
83};
84
86 private:
87 std::string name_;
90
91 public:
92 FlatBundleTypeBuilder(std::string name);
93
94 template<typename DeclType> typename DeclType::Builder &add(UString name);
95
97};
98
101
102 public:
103 static void register_type(BundleType bundle_type);
106};
107
108template<typename DeclType>
109inline typename DeclType::Builder &FlatBundleTypeBuilder::add(UString name)
110{
111 static_assert(std::is_base_of_v<SocketDeclaration, DeclType>);
112 using SocketBuilder = typename DeclType::Builder;
113
114 auto decl_ptr = std::make_unique<DeclType>();
115 DeclType &decl = *decl_ptr;
116
117 auto decl_builder_ptr = std::make_unique<SocketBuilder>();
118 SocketBuilder &decl_builder = *decl_builder_ptr;
119
120 decl_builder.decl_ = &decl;
121 decl_builder.decl_base_ = &decl;
122
123 decl.name = name;
124 decl.identifier = name;
125 decl.in_out = SOCK_IN;
126 decl.socket_type = DeclType::static_socket_type;
127
128 decls_.append(std::move(decl_ptr));
129 builders_.append(std::move(decl_builder_ptr));
130 return decl_builder;
131}
132
134{
135 return this->decl->name;
136}
137
139{
140 return name_;
141}
142
144{
145 return items_;
146}
147
149{
150 return name_;
151}
152
154{
155 return items_;
156}
157
159{
160 return std::visit([](auto &&type) { return type->name(); }, this->type);
161}
162
164{
165 return std::visit([](auto &&type) { return get_default_hash(type); }, this->type);
166}
167
168} // namespace blender::nodes
SIMD_FORCE_INLINE btVector3 operator()(const btVector3 &x) const
Return the transform of the vector.
Definition btTransform.h:90
static Vector< std::string > get_all_flat_type_names()
static void register_type(BundleType bundle_type)
static FlatBundleTypePtr try_find_single_flat(StringRef name)
friend bool operator==(const BundleType &a, const BundleType &b)=default
BundleType(FlatBundleTypePtr type)
BundleType(NestedBundleTypePtr type)
StringRefNull name() const
std::variant< FlatBundleTypePtr, NestedBundleTypePtr > type
DeclType::Builder & add(UString name)
const SocketDeclaration * find_decl(const UString name) const
FlatBundleType(std::string name, Vector< std::unique_ptr< SocketDeclaration > > decls)
BundleSignature to_bundle_signature() const
Span< FlatBundleTypePtr > items() const
NestedBundleType(std::string name, Vector< FlatBundleTypePtr > bundle_types)
std::shared_ptr< const NestedBundleType > NestedBundleTypePtr
std::shared_ptr< const FlatBundleType > FlatBundleTypePtr
unsigned __int64 uint64_t
Definition BKE_text.h:91
VectorSet< T, InlineBufferCapacity, DefaultProbingStrategy, CustomIDHash< T, GetIDFn >, CustomIDEqual< T, GetIDFn > > CustomIDVectorSet
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
#define hash
Definition noise_c.cc:156
std::unique_ptr< SocketDeclaration > decl