45 void delete_self_with_data()
override
47 if (data_ !=
nullptr) {
54 void delete_data_only()
override
68 const void *value_ptr = value.
get();
79 data.size = domain_size;
96 data.size = domain_size;
128 for (
const std::unique_ptr<Attribute> &attribute : this->
runtime->attributes) {
134 for (
const std::unique_ptr<Attribute> &attribute : this->
runtime->attributes) {
141 for (
const std::unique_ptr<Attribute> &attribute : this->
runtime->attributes) {
142 if (!
fn(*attribute)) {
149 for (
const std::unique_ptr<Attribute> &attribute : this->
runtime->attributes) {
150 if (!
fn(*attribute)) {
158 if (std::get_if<Attribute::ArrayData>(&data_)) {
161 if (std::get_if<Attribute::SingleData>(&data_)) {
170 if (
auto *
data = std::get_if<Attribute::ArrayData>(&data_)) {
171 if (!
data->sharing_info) {
175 if (
data->sharing_info->is_mutable()) {
176 data->sharing_info->tag_ensured_mutable();
182 *
data = std::move(new_data);
184 else if (
auto *
data = std::get_if<Attribute::SingleData>(&data_)) {
185 if (
data->sharing_info->is_mutable()) {
186 data->sharing_info->tag_ensured_mutable();
199 memset(this->
_pad, 0,
sizeof(this->
_pad));
200 this->
runtime = MEM_new<AttributeStorageRuntime>(__func__);
207 this->
runtime = MEM_new<AttributeStorageRuntime>(__func__);
208 this->
runtime->attributes.reserve(other.
runtime->attributes.size());
210 this->
runtime->attributes.add_new(std::make_unique<Attribute>(attribute));
216 if (
this == &other) {
219 std::destroy_at(
this);
228 this->
runtime = MEM_new<AttributeStorageRuntime>(__func__, std::move(*other.runtime));
233 if (
this == &other) {
236 std::destroy_at(
this);
248 return this->
runtime->attributes.size();
253 return *this->
runtime->attributes[index];
257 return *this->
runtime->attributes[index];
262 return this->
runtime->attributes.index_of_try_as(
name);
267 const std::unique_ptr<blender::bke::Attribute> *attribute =
272 return attribute->get();
277 const std::unique_ptr<blender::bke::Attribute> *attribute =
282 return attribute->get();
291 std::unique_ptr<Attribute>
ptr = std::make_unique<Attribute>();
293 attribute.name_ = std::move(
name);
294 attribute.domain_ =
domain;
296 attribute.data_ = std::move(
data);
297 this->
runtime->attributes.add_new(std::move(
ptr));
309 [&](
const StringRef check_name) {
return this->
lookup(check_name) !=
nullptr; },
'.',
name);
316 const int index = this->
runtime->attributes.index_of_try_as(old_name);
318 old_vector[index]->name_ = std::move(new_name);
319 this->
runtime->attributes.reserve(old_vector.
size());
320 for (std::unique_ptr<Attribute> &attribute : old_vector) {
321 this->
runtime->attributes.add_new(std::move(attribute));
334 const auto &
data = std::get<bke::Attribute::ArrayData>(attr.
data());
339 if (old_size < new_size) {
341 new_size - old_size);
354 const int8_t dna_attr_type,
358 switch (dna_attr_type) {
360 static_assert(
sizeof(bool) ==
sizeof(int8_t));
407 const int8_t dna_attr_type,
412 const char *func = __func__;
415 if (*
data ==
nullptr) {
419 return MEM_new<ArrayDataImplicitSharing>(func, *
data,
size, cpp_type);
424 const int8_t dna_storage_type,
425 const int8_t dna_attr_type,
428 switch (dna_storage_type) {
454 for (
const std::unique_ptr<Attribute> &attr : this->
runtime->attributes) {
456 if (
const auto *
data = std::get_if<Attribute::ArrayData>(&attr->data())) {
458 shared_memory.add(data->size * type.size);
461 else if (
const auto *
data = std::get_if<Attribute::SingleData>(&attr->data())) {
463 [&](
MemoryCounter &shared_memory) { shared_memory.add(type.size); });
470 switch (dna_domain) {
486 this->
runtime = MEM_new<AttributeStorageRuntime>(__func__);
507 std::unique_ptr<Attribute> attribute = std::make_unique<Attribute>();
508 attribute->name_ = dna_attr.
name;
509 attribute->domain_ = *
domain;
511 attribute->data_ = std::move(*
data);
513 if (!this->
runtime->attributes.add(std::move(attribute))) {
514 CLOG_ERROR(&
LOG,
"Ignoring attribute with duplicate name: \"%s\"", dna_attr.
name);
530 static_assert(
sizeof(bool) ==
sizeof(int8_t));
590 if (
const auto *
data = std::get_if<Attribute::ArrayData>(&attr.
data())) {
593 array_dna.sharing_info =
data->sharing_info.get();
594 array_dna.size =
data->size;
595 attribute_dna.
data = &array_dna;
597 else if (
const auto *
data = std::get_if<Attribute::SingleData>(&attr.
data())) {
600 single_dna.sharing_info =
data->sharing_info.get();
601 attribute_dna.
data = &single_dna;
606 data.runtime =
nullptr;
617 write_array_data(writer, data_type, data, size);
632 for (const ::Attribute &attr_dna : write_data.
attributes) {
661 for (
const std::unique_ptr<Attribute> &attribute : this->
runtime->attributes) {
663 if (
auto *
data = std::get_if<Attribute::ArrayData>(&attribute->data_)) {
664 fn.implicit_sharing_array(
667 else if (
auto *
data = std::get_if<Attribute::SingleData>(&attribute->data_)) {
668 fn.implicit_sharing_array(
#define BLI_assert_unreachable()
bool BLI_memory_is_zero(const void *arr, size_t size)
#define BLI_SCOPED_DEFER(function_to_defer)
size_t void BLI_uniquename_cb(blender::FunctionRef< bool(blender::StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
#define POINTER_OFFSET(v, ofs)
void BLO_write_float_array(BlendWriter *writer, int64_t num, const float *data_ptr)
void BLO_read_uint8_array(BlendDataReader *reader, int64_t array_size, uint8_t **ptr_p)
void BLO_read_float3_array(BlendDataReader *reader, int64_t array_size, float **ptr_p)
void BLO_write_int32_array(BlendWriter *writer, int64_t num, const int32_t *data_ptr)
void BLO_write_struct_array_by_name(BlendWriter *writer, const char *struct_name, int64_t array_size, const void *data_ptr)
void BLO_read_float_array(BlendDataReader *reader, int64_t array_size, float **ptr_p)
void BLO_read_int32_array(BlendDataReader *reader, int64_t array_size, int32_t **ptr_p)
void BLO_write_uint8_array(BlendWriter *writer, int64_t num, const uint8_t *data_ptr)
#define BLO_write_struct(writer, struct_name, data_ptr)
void BLO_write_float3_array(BlendWriter *writer, int64_t num, const float *data_ptr)
void BLO_read_int16_array(BlendDataReader *reader, const int64_t array_size, int16_t **ptr_p)
void BLO_write_int8_array(BlendWriter *writer, int64_t num, const int8_t *data_ptr)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
#define BLO_write_struct_array(writer, struct_name, array_size, data_ptr)
void BLO_read_int8_array(BlendDataReader *reader, int64_t array_size, int8_t **ptr_p)
#define BLO_read_struct_array(reader, struct_name, array_size, ptr_p)
#define BLO_read_struct(reader, struct_name, ptr_p)
void BLO_write_int16_array(BlendWriter *writer, int64_t num, const int16_t *data_ptr)
void BLO_write_shared(BlendWriter *writer, const void *data, size_t approximate_size_in_bytes, const blender::ImplicitSharingInfo *sharing_info, blender::FunctionRef< void()> write_fn)
const blender::ImplicitSharingInfo * BLO_read_shared(BlendDataReader *reader, T **data_ptr, blender::FunctionRef< const blender::ImplicitSharingInfo *()> read_fn)
#define CLOG_ERROR(clg_ref,...)
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void copy_construct_n(const void *src, void *dst, int64_t n) const
void default_construct_n(void *ptr, int64_t n) const
void destruct_n(void *ptr, int64_t n) const
bool is_trivially_destructible
void fill_construct_n(const void *value, void *dst, int64_t n) const
void copy_construct(const void *src, void *dst) const
const void * default_value() const
const CPPType * type() const
T & construct(Args &&...args)
constexpr const char * c_str() const
ArrayDataImplicitSharing(void *data, const int64_t size, const CPPType &type)
void rename(StringRef old_name, std::string new_name)
Attribute & add(std::string name, bke::AttrDomain domain, bke::AttrType data_type, Attribute::DataVariant data)
void count_memory(MemoryCounter &memory) const
Attribute * lookup(StringRef name)
void foreach(FunctionRef< void(Attribute &)> fn)
void blend_read(BlendDataReader &reader)
Attribute & at_index(int index)
bool remove(StringRef name)
void blend_write(BlendWriter &writer, const BlendWriteData &write_data)
std::string unique_name_calc(StringRef name) const
void foreach_working_space_color(const IDTypeForeachColorFunctionCallback &fn)
void resize(AttrDomain domain, int64_t new_size)
int index_of(StringRef name) const
void foreach_with_stop(FunctionRef< bool(Attribute &)> fn)
AttributeStorage & operator=(const AttributeStorage &other)
AttrStorageType storage_type() const
const DataVariant & data() const
std::variant< ArrayData, SingleData > DataVariant
DataVariant & data_for_write()
AttrDomain domain() const
StringRefNull name() const
void assign_data(DataVariant &&data)
AttrType data_type() const
void add_shared(const ImplicitSharingInfo *sharing_info, const FunctionRef< void(MemoryCounter &shared_memory)> count_fn)
void * MEM_mallocN_aligned(size_t len, size_t alignment, const char *str)
void *(* MEM_calloc_arrayN_aligned)(size_t len, size_t size, size_t alignment, const char *str)
void MEM_freeN(void *vmemh)
void *(* MEM_malloc_arrayN_aligned)(size_t len, size_t size, size_t alignment, const char *str)
static std::optional< Attribute::DataVariant > read_attr_data(BlendDataReader &reader, const int8_t dna_storage_type, const int8_t dna_attr_type, ::Attribute &dna_attr)
static std::optional< AttrDomain > read_attr_domain(const int8_t dna_domain)
void attribute_storage_blend_write_prepare(AttributeStorage &data, AttributeStorage::BlendWriteData &write_data)
static void write_array_data(BlendWriter &writer, const AttrType data_type, const void *data, const int64_t size)
static void read_shared_array(BlendDataReader &reader, const int8_t dna_attr_type, const int64_t size, void **data, const ImplicitSharingInfo **sharing_info)
static void write_shared_array(BlendWriter &writer, const AttrType data_type, const void *data, const int64_t size, const ImplicitSharingInfo *sharing_info)
static void read_array_data(BlendDataReader &reader, const int8_t dna_attr_type, const int64_t size, void **data)
const CPPType & attribute_type_to_cpp_type(AttrType type)
const ImplicitSharingInfo * info_for_mem_free(void *data)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
const ImplicitSharingInfoHandle * sharing_info
const ImplicitSharingInfoHandle * sharing_info
AttributeStorageRuntimeHandle * runtime
struct Attribute * dna_attributes
Vector<::Attribute, 16 > & attributes
BlendWriteData(ResourceScope &scope)
static ArrayData from_uninitialized(const CPPType &type, int64_t domain_size)
static ArrayData from_default_value(const CPPType &type, int64_t domain_size)
static ArrayData from_value(const GPointer &value, int64_t domain_size)
static ArrayData from_constructed(const CPPType &type, int64_t domain_size)
static SingleData from_value(const GPointer &value)
static SingleData from_default_value(const CPPType &type)