Blender V5.3
bundle_type.cc
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#include "NOD_bundle_type.hh"
11
12namespace blender::nodes {
13
14FlatBundleType::FlatBundleType(std::string name, Vector<std::unique_ptr<SocketDeclaration>> decls)
15 : name_(std::move(name))
16{
17 for (std::unique_ptr<SocketDeclaration> &decl : decls) {
18 items_.add_new(Item{std::move(decl)});
19 }
20}
21
23{
24 const Item *item = items_.lookup_key_ptr_as(name);
25 if (!item) {
26 return nullptr;
27 }
28 return item->decl.get();
29}
30
31FlatBundleTypeBuilder::FlatBundleTypeBuilder(std::string name) : name_(std::move(name)) {}
32
34{
35 return std::make_shared<const FlatBundleType>(std::move(name_), std::move(decls_));
36}
37
39{
40 BundleSignature signature;
41 signature.add(Bundle::type_item_name.ustr().string(), SOCK_STRING);
42 for (const Item &item : items_) {
43 signature.add(item.name().ref(), item.decl->socket_type);
44 }
45 return signature;
46}
47
49 : name_(std::move(name))
50{
51 for (FlatBundleTypePtr &bundle_type : bundle_types) {
52 items_.add_new(std::move(bundle_type));
53 }
54}
55
57{
58 static BundleTypeRegistry singleton;
59 return singleton;
60}
61
63{
65 const Set<BundleType> *types_with_name = registry.types_.lookup_ptr(name);
66 if (!types_with_name) {
67 return nullptr;
68 }
69 if (types_with_name->size() != 1) {
70 return nullptr;
71 }
72 const BundleType &bundle_type = *types_with_name->begin();
73 if (const auto *flat_bundle_type = std::get_if<FlatBundleTypePtr>(&bundle_type.type)) {
74 return *flat_bundle_type;
75 }
76 return nullptr;
77}
78
80{
83 for (const auto &[name, types] : registry.types_.items()) {
84 if (std::any_of(types.begin(),
85 types.end(),
86 [](const BundleType &type) {
87 return std::holds_alternative<FlatBundleTypePtr>(type.type);
88 }))
89 {
90 names.append(name);
91 }
92 }
93 return names;
94}
95
97{
99 registry.types_.lookup_or_add_default(bundle_type.name()).add(bundle_type);
100}
101
102} // namespace blender::nodes
Iterator begin() const
Definition BLI_set.hh:499
int64_t size() const
Definition BLI_set.hh:606
void append(const T &value)
static Vector< std::string > get_all_flat_type_names()
static void register_type(BundleType bundle_type)
static FlatBundleTypePtr try_find_single_flat(StringRef name)
StringRefNull name() const
std::variant< FlatBundleTypePtr, NestedBundleTypePtr > type
const SocketDeclaration * find_decl(const UString name) const
FlatBundleType(std::string name, Vector< std::unique_ptr< SocketDeclaration > > decls)
BundleSignature to_bundle_signature() const
NestedBundleType(std::string name, Vector< FlatBundleTypePtr > bundle_types)
std::shared_ptr< const FlatBundleType > FlatBundleTypePtr
static BundleTypeRegistry & get_bundle_type_registry()
void add(std::string key, const eNodeSocketDatatype socket_type)
std::unique_ptr< SocketDeclaration > decl