Blender V4.5
blenkernel/intern/geometry_nodes_bundle.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
7
8namespace blender::bke {
9
11{
12 identifiers_.append(std::move(identifier));
13}
14
16 : identifiers_(std::move(identifiers))
17{
18 BLI_assert(!identifiers_.is_empty());
19}
20
22{
23 return identifiers_;
24}
25
27{
28 for (const std::string &identifier : other.identifiers_) {
29 if (identifiers_.contains(identifier)) {
30 return true;
31 }
32 }
33 return false;
34}
35
36Bundle::Bundle() = default;
37
39{
40 for (StoredItem &item : items_) {
41 item.type->geometry_nodes_cpp_type->destruct(item.value);
42 }
43 for (void *buffer : buffers_) {
44 MEM_freeN(buffer);
45 }
46}
47
49{
50 for (const StoredItem &item : other.items_) {
51 this->add_new(item.key, *item.type, item.value);
52 }
53}
54
55Bundle::Bundle(Bundle &&other) noexcept
56 : items_(std::move(other.items_)), buffers_(std::move(other.buffers_))
57{
58}
59
61{
62 if (this == &other) {
63 return *this;
64 }
65 this->~Bundle();
66 new (this) Bundle(other);
67 return *this;
68}
69
71{
72 if (this == &other) {
73 return *this;
74 }
75 this->~Bundle();
76 new (this) Bundle(std::move(other));
77 return *this;
78}
79
80void Bundle::add_new(SocketInterfaceKey key, const bNodeSocketType &type, const void *value)
81{
82 BLI_assert(!this->contains(key));
83 BLI_assert(type.geometry_nodes_cpp_type);
84 const CPPType &cpp_type = *type.geometry_nodes_cpp_type;
85 void *buffer = MEM_mallocN_aligned(cpp_type.size, cpp_type.alignment, __func__);
86 cpp_type.copy_construct(value, buffer);
87 items_.append(StoredItem{std::move(key), &type, buffer});
88 buffers_.append(buffer);
89}
90
91bool Bundle::add(const SocketInterfaceKey &key, const bNodeSocketType &type, const void *value)
92{
93 if (this->contains(key)) {
94 return false;
95 }
96 this->add_new(key, type, value);
97 return true;
98}
99
100bool Bundle::add(SocketInterfaceKey &&key, const bNodeSocketType &type, const void *value)
101{
102 if (this->contains(key)) {
103 return false;
104 }
105 this->add_new(std::move(key), type, value);
106 return true;
107}
108
109std::optional<Bundle::Item> Bundle::lookup(const SocketInterfaceKey &key) const
110{
111 for (const StoredItem &item : items_) {
112 if (item.key.matches(key)) {
113 return Item{item.type, item.value};
114 }
115 }
116 return std::nullopt;
117}
118
120{
121 const int removed_num = items_.remove_if([&key](StoredItem &item) {
122 if (item.key.matches(key)) {
124 return true;
125 }
126 return false;
127 });
128 return removed_num >= 1;
129}
130
132{
133 for (const StoredItem &item : items_) {
134 if (item.key.matches(key)) {
135 return true;
136 }
137 }
138 return false;
139}
140
142{
143 MEM_delete(this);
144}
145
146} // namespace blender::bke
#define BLI_assert(a)
Definition BLI_assert.h:46
void copy_construct(const void *src, void *dst) const
void destruct(void *ptr) const
bool add(const SocketInterfaceKey &key, const bke::bNodeSocketType &type, const void *value)
void add_new(SocketInterfaceKey key, const bke::bNodeSocketType &type, const void *value)
std::optional< Item > lookup(const SocketInterfaceKey &key) const
bool contains(const SocketInterfaceKey &key) const
bool remove(const SocketInterfaceKey &key)
bool matches(const SocketInterfaceKey &other) const
void * MEM_mallocN_aligned(size_t len, size_t alignment, const char *str)
Definition mallocn.cc:138
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
const blender::CPPType * geometry_nodes_cpp_type
Definition BKE_node.hh:203