Blender V5.0
attribute_storage_access.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_attribute.hh"
7#include <optional>
8
9namespace blender::bke {
10
11using AttrUpdateOnChange = void (*)(void *owner);
12
21
22GAttributeReader attribute_to_reader(const Attribute &attribute,
23 const AttrDomain domain,
24 const int64_t domain_size);
25
26GAttributeWriter attribute_to_writer(void *owner,
28 const int64_t domain_size,
29 Attribute &attribute);
30
32 const int64_t domain_size,
33 const AttributeInit &initializer);
34
36 AttrDomain domain,
37 const CPPType &cpp_type,
39 int64_t domain_size,
40 const void *default_value);
41
42template<typename T>
44 const AttrDomain domain,
45 const StringRef name,
46 const int64_t domain_size,
47 const T &default_value)
48{
50 storage, domain, CPPType::get<T>(), name, domain_size, &default_value);
51 return varray.typed<T>();
52}
53
54std::optional<GSpan> get_span_attribute(const AttributeStorage &storage,
55 AttrDomain domain,
56 const CPPType &cpp_type,
58 const int64_t domain_size);
59
60template<typename T>
61inline std::optional<Span<T>> get_span_attribute(const AttributeStorage &storage,
62 const AttrDomain domain,
63 const StringRef name,
64 const int64_t domain_size)
65{
66 const std::optional<GSpan> span = get_span_attribute(
67 storage, domain, CPPType::get<T>(), name, domain_size);
68 if (!span) {
69 return std::nullopt;
70 }
71 return span->typed<T>();
72}
73
75 const AttrDomain domain,
76 const CPPType &cpp_type,
77 const StringRef name,
78 const int64_t domain_size,
79 const void *default_value);
80
81template<typename T>
83 const AttrDomain domain,
84 const StringRef name,
85 const int64_t domain_size,
86 const T &default_value = T())
87{
89 storage, domain, CPPType::get<T>(), name, domain_size, &default_value);
90 return span.typed<T>();
91}
92
93} // namespace blender::bke
AttrDomain
long long int int64_t
static const CPPType & get()
MutableSpan< T > typed() const
std::variant< ArrayData, SingleData > DataVariant
#define T
GMutableSpan get_mutable_attribute(AttributeStorage &storage, const AttrDomain domain, const CPPType &cpp_type, const StringRef name, const int64_t domain_size, const void *custom_default_value)
GAttributeReader attribute_to_reader(const Attribute &attribute, const AttrDomain domain, const int64_t domain_size)
std::optional< GSpan > get_span_attribute(const AttributeStorage &storage, const AttrDomain domain, const CPPType &cpp_type, const StringRef name, const int64_t domain_size)
Attribute::DataVariant attribute_init_to_data(const bke::AttrType data_type, const int64_t domain_size, const AttributeInit &initializer)
GAttributeWriter attribute_to_writer(void *owner, const Map< StringRef, AttrUpdateOnChange > &changed_tags, const int64_t domain_size, Attribute &attribute)
GVArray get_varray_attribute(const AttributeStorage &storage, AttrDomain domain, const CPPType &cpp_type, StringRef name, int64_t domain_size, const void *default_value)
void(*)(void *owner) AttrUpdateOnChange
static const auto & changed_tags()
const char * name
AttrBuiltinInfo(AttrDomain domain, AttrType type)