Blender V5.3
idprop.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cfloat>
10#include <climits>
11#include <cstddef>
12#include <cstdio>
13#include <cstdlib>
14#include <cstring>
15
16#include <xxhash.h>
17
18#include <fmt/format.h>
19
20#include "BLI_listbase.hh"
21#include "BLI_math_base_c.hh"
22#include "BLI_set.hh"
23#include "BLI_string.hh"
24#include "BLI_string_utf8.hh"
25#include "BLI_utildefines.hh"
26
27#include "BKE_idprop.hh"
28#include "BKE_idprop_hash.hh"
29#include "BKE_lib_id.hh"
30
31#include "CLG_log.h"
32
33#include "MEM_guardedalloc.h"
34
35#include "BLO_read_write.hh"
36
37#include "BLI_strict_flags.hh" /* IWYU pragma: keep. Keep last. */
38
39namespace blender {
40
41/* IDPropertyTemplate is a union in DNA_ID.h */
42
47#define IDP_ARRAY_REALLOC_LIMIT 200
48
49static CLG_LogRef LOG = {"lib.idprop"};
50
52static size_t idp_size_table[] = {
53 1, /* #IDP_STRING */
54 sizeof(int), /* #IDP_INT */
55 sizeof(float), /* #IDP_FLOAT */
56 sizeof(float[3]), /* DEPRECATED (was vector). */
57 sizeof(float[16]), /* DEPRECATED (was matrix). */
58 0, /* #IDP_ARRAY (no fixed size). */
59 sizeof(ListBase), /* #IDP_GROUP */
60 sizeof(void *), /* #IDP_ID */
61 sizeof(double), /* #IDP_DOUBLE */
62 0, /* #IDP_IDPARRAY (no fixed size). */
63 sizeof(int8_t), /* #IDP_BOOLEAN */
64 sizeof(int), /* #IDP_ENUM */
65};
66
73constexpr int MAX_IDPROP_DEPTH_LEVEL = 1026;
90
92 const bool do_id_user,
93 const int recursion_depth);
95 const bool do_id_user,
96 const int recursion_depth);
97
98/* -------------------------------------------------------------------- */
101
102#define GETPROP(prop, i) &(IDP_property_array_get(prop)[i])
103
105{
106 IDProperty *prop = MEM_new<IDProperty>("IDProperty prop array");
107 prop->type = IDP_IDPARRAY;
108 prop->len = 0;
109 name.copy_utf8_truncated(prop->name);
110
111 return prop;
112}
113
115{
116 /* don't use MEM_dupalloc because this may be part of an array */
117 BLI_assert(array->type == IDP_IDPARRAY);
118
119 IDProperty *narray = MEM_new<IDProperty>(__func__, *array);
120
121 narray->data.pointer = MEM_dupalloc_void(array->data.pointer);
122 for (int i = 0; i < narray->len; i++) {
123 /* OK, the copy functions always allocate a new structure,
124 * which doesn't work here. instead, simply copy the
125 * contents of the new structure into the array cell,
126 * then free it. this makes for more maintainable
127 * code than simply re-implementing the copy functions
128 * in this loop. */
129 IDProperty *tmp = IDP_CopyProperty_ex(GETPROP(narray, i), flag);
130 memcpy(GETPROP(narray, i), tmp, sizeof(IDProperty));
131 MEM_delete(tmp);
132 }
133
134 return narray;
135}
136
137static void IDP_FreeIDPArray(IDProperty *prop, const bool do_id_user, const int recursion_depth)
138{
139 BLI_assert(prop->type == IDP_IDPARRAY);
140
141 for (int i = 0; i < prop->len; i++) {
142 idp_free_property_content_recurse(GETPROP(prop, i), do_id_user, recursion_depth + 1);
143 }
144
145 if (prop->data.pointer) {
146 MEM_delete(static_cast<IDProperty *>(prop->data.pointer));
147 }
148}
150{
151 BLI_assert(prop->type == IDP_IDPARRAY);
152
153 if (index >= prop->len || index < 0) {
154 return;
155 }
156
157 IDProperty *old = GETPROP(prop, index);
158 if (item != old) {
160
161 memcpy(old, item, sizeof(IDProperty));
162 }
163}
164
166{
167 BLI_assert(prop->type == IDP_IDPARRAY);
168
169 return GETPROP(prop, index);
170}
171
173{
174 BLI_assert(prop->type == IDP_IDPARRAY);
175
176 IDP_ResizeIDPArray(prop, prop->len + 1);
177 IDP_SetIndexArray(prop, prop->len - 1, item);
178}
179
181{
182 BLI_assert(prop.type == IDP_GROUP);
183 if (!prop.data.children_map) {
184 prop.data.children_map = MEM_new<bke::idprop::IDPropertyGroupChildrenSet>(__func__);
185 }
186}
187
188static int idp_resize_grow_size_calc(const int newsize)
189{
190 /* NOTE: This code comes from python, here's the corresponding comment. */
191 /* This over-allocates proportional to the list size, making room
192 * for additional growth. The over-allocation is mild, but is
193 * enough to give linear-time amortized behavior over a long
194 * sequence of appends() in the presence of a poorly-performing
195 * system realloc().
196 * The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
197 */
198 int64_t newsize_test = newsize;
199 newsize_test = (newsize_test >> 3) + (newsize_test < 9 ? 3 : 6) + newsize_test;
200 return int(std::min<int64_t>(newsize_test, std::numeric_limits<int>::max()));
201}
202
203void IDP_ResizeIDPArray(IDProperty *prop, int newlen)
204{
205 BLI_assert(prop->type == IDP_IDPARRAY);
206
207 /* first check if the array buffer size has room */
208 if (newlen <= prop->totallen) {
209 if (newlen < prop->len && prop->totallen - newlen < IDP_ARRAY_REALLOC_LIMIT) {
210 for (int i = newlen; i < prop->len; i++) {
211 IDP_ClearProperty(GETPROP(prop, i));
212 }
213
214 prop->len = newlen;
215 return;
216 }
217 if (newlen >= prop->len) {
218 prop->len = newlen;
219 return;
220 }
221 }
222
223 /* free trailing items */
224 if (newlen < prop->len) {
225 /* newlen is smaller */
226 for (int i = newlen; i < prop->len; i++) {
227 IDP_ClearProperty(GETPROP(prop, i));
228 }
229 }
230
231 const int newsize = idp_resize_grow_size_calc(newlen);
233 sizeof(IDProperty) * size_t(newsize));
234 prop->len = newlen;
235 prop->totallen = newsize;
236}
237
238/* ----------- Numerical Array Type ----------- */
240 IDProperty *prop, int newlen, void *newarr, const bool do_id_users, const int recursion_depth)
241{
242 if (prop->subtype != IDP_GROUP) {
243 return;
244 }
245
246 if (newlen >= prop->len) {
247 /* bigger */
248 IDProperty **array = static_cast<IDProperty **>(newarr);
249 for (int a = prop->len; a < newlen; a++) {
250 array[a] = bke::idprop::create_group("IDP_ResizeArray group").release();
251 }
252 }
253 else {
254 /* smaller */
255 IDProperty **array = static_cast<IDProperty **>(prop->data.pointer);
256
257 for (int a = newlen; a < prop->len; a++) {
258 idp_free_property_recurse(array[a], do_id_users, recursion_depth + 1);
259 }
260 }
261}
262
263void IDP_ResizeArray(IDProperty *prop, int newlen)
264{
265 const bool is_grow = newlen >= prop->len;
266
267 /* first check if the array buffer size has room */
268 if (newlen <= prop->totallen && prop->totallen - newlen < IDP_ARRAY_REALLOC_LIMIT) {
269 idp_resize_group_array(prop, newlen, prop->data.pointer, true, 0);
270 prop->len = newlen;
271 return;
272 }
273
274 const int newsize = idp_resize_grow_size_calc(newlen);
275 if (is_grow == false) {
276 idp_resize_group_array(prop, newlen, prop->data.pointer, true, 0);
277 }
278
280 idp_size_table[int(prop->subtype)] * size_t(newsize));
281
282 if (is_grow == true) {
283 idp_resize_group_array(prop, newlen, prop->data.pointer, true, 0);
284 }
285
286 prop->len = newlen;
287 prop->totallen = newsize;
288}
289
290static void IDP_FreeArray(IDProperty *prop, const bool do_id_user, const int recursion_depth)
291{
292 if (prop->data.pointer) {
293 idp_resize_group_array(prop, 0, nullptr, do_id_user, recursion_depth);
295 }
296}
297
299{
300 IDPropertyUIData *dst_ui_data = MEM_dupalloc(prop->ui_data);
301
302 /* Copy extra type specific data. */
303 switch (IDP_ui_data_type(prop)) {
305 const IDPropertyUIDataString *src = reinterpret_cast<const IDPropertyUIDataString *>(
306 prop->ui_data);
307 IDPropertyUIDataString *dst = reinterpret_cast<IDPropertyUIDataString *>(dst_ui_data);
308 dst->default_value = MEM_dupalloc(src->default_value);
309 break;
310 }
311 case IDP_UI_DATA_TYPE_ID: {
312 break;
313 }
315 const IDPropertyUIDataInt *src = reinterpret_cast<const IDPropertyUIDataInt *>(
316 prop->ui_data);
317 IDPropertyUIDataInt *dst = reinterpret_cast<IDPropertyUIDataInt *>(dst_ui_data);
318 dst->default_array = MEM_dupalloc(src->default_array);
319 dst->enum_items = MEM_dupalloc(src->enum_items);
320 for (const int64_t i : IndexRange(src->enum_items_num)) {
321 const IDPropertyUIDataEnumItem &src_item = src->enum_items[i];
322 IDPropertyUIDataEnumItem &dst_item = dst->enum_items[i];
323 dst_item.identifier = BLI_strdup(src_item.identifier);
324 dst_item.name = BLI_strdup_null(src_item.name);
325 dst_item.description = BLI_strdup_null(src_item.description);
326 }
327 break;
328 }
330 const IDPropertyUIDataBool *src = reinterpret_cast<const IDPropertyUIDataBool *>(
331 prop->ui_data);
332 IDPropertyUIDataBool *dst = reinterpret_cast<IDPropertyUIDataBool *>(dst_ui_data);
333 dst->default_array = MEM_dupalloc(src->default_array);
334 break;
335 }
337 const IDPropertyUIDataFloat *src = reinterpret_cast<const IDPropertyUIDataFloat *>(
338 prop->ui_data);
339 IDPropertyUIDataFloat *dst = reinterpret_cast<IDPropertyUIDataFloat *>(dst_ui_data);
340 dst->default_array = MEM_dupalloc(src->default_array);
341 break;
342 }
344 break;
345 }
346 }
347
348 dst_ui_data->description = MEM_dupalloc(prop->ui_data->description);
349
350 return dst_ui_data;
351}
352
353static IDProperty *idp_generic_copy(const IDProperty *prop, const int /*flag*/)
354{
355 IDProperty *newp = MEM_new<IDProperty>(__func__);
356
357 STRNCPY(newp->name, prop->name);
358 newp->type = prop->type;
359 newp->flag = prop->flag;
360 newp->data.val = prop->data.val;
361 newp->data.val2 = prop->data.val2;
362
363 if (prop->ui_data != nullptr) {
364 newp->ui_data = IDP_ui_data_copy(prop);
365 }
366
367 return newp;
368}
369
370static IDProperty *IDP_CopyArray(const IDProperty *prop, const int flag)
371{
372 BLI_assert(prop->type == IDP_ARRAY);
373 IDProperty *newp = idp_generic_copy(prop, flag);
374
375 if (prop->data.pointer) {
377
378 if (prop->subtype == IDP_GROUP) {
379 IDProperty **array = static_cast<IDProperty **>(newp->data.pointer);
380 int a;
381
382 for (a = 0; a < prop->len; a++) {
383 array[a] = IDP_CopyProperty_ex(array[a], flag);
384 }
385 }
386 }
387 newp->len = prop->len;
388 newp->subtype = prop->subtype;
389 newp->totallen = prop->totallen;
390
391 return newp;
392}
393
395
396/* -------------------------------------------------------------------- */
399
401 const size_t st_maxncpy,
402 const StringRef name,
403 const eIDPropertyFlag flags)
404{
405 IDProperty *prop = MEM_new<IDProperty>("IDProperty string");
406
407 if (st == nullptr) {
409 "id property string 1");
410 *IDP_string_get(prop) = '\0';
412 prop->len = 1; /* nullptr string, has len of 1 to account for null byte. */
413 }
414 else {
415 /* Include null terminator '\0'. */
416 size_t stlen_bytes;
417 if (st_maxncpy > 0) {
418 BLI_strnlen_utf8_ex(st, st_maxncpy - 1, &stlen_bytes);
419 }
420 else {
421 stlen_bytes = strlen(st);
422 }
423 const int stlen = int(stlen_bytes) + 1;
424
425 prop->data.pointer = MEM_new_array_uninitialized<char>(size_t(stlen), "id property string 2");
426 prop->len = prop->totallen = stlen;
427
428 /* Ensured above, must always be true otherwise null terminator assignment will be invalid. */
429 BLI_assert(stlen > 0);
430 if (stlen > 1) {
431 memcpy(prop->data.pointer, st, size_t(stlen));
432 }
433 IDP_string_get(prop)[stlen - 1] = '\0';
434 }
435
436 prop->type = IDP_STRING;
437 name.copy_utf8_truncated(prop->name);
438 prop->flag = flags;
439
440 return prop;
441}
442
443IDProperty *IDP_NewString(const char *st, const StringRef name, const eIDPropertyFlag flags)
444{
445 return IDP_NewStringMaxSize(st, 0, name, flags);
446}
447
448IDProperty *IDP_NewString(const StringRef value, const StringRef name, const eIDPropertyFlag flags)
449{
450 BLI_assert(value.size() >= 0);
451 /* Adding one is needed for the null byte. */
452 return IDP_NewStringMaxSize(value.data(), size_t(value.size()) + 1, name, flags);
453}
454
455static IDProperty *IDP_CopyString(const IDProperty *prop, const int flag)
456{
457 BLI_assert(prop->type == IDP_STRING);
458 IDProperty *newp = idp_generic_copy(prop, flag);
459
460 if (prop->data.pointer) {
462 }
463 newp->len = prop->len;
464 newp->subtype = prop->subtype;
465 newp->totallen = prop->totallen;
466
467 return newp;
468}
469
470void IDP_AssignStringMaxSize(IDProperty *prop, const char *st, const size_t st_maxncpy)
471{
472 /* FIXME: This function is broken for bytes (in case there are null chars in it),
473 * needs a dedicated function which takes directly the size of the byte buffer. */
474
475 BLI_assert(prop->type == IDP_STRING);
476
477 if (prop->subtype != IDP_STRING_SUB_BYTE) {
478 /* Ensure strings remain valid UTF8. */
479 size_t src_len;
480 if (st_maxncpy > 0) {
481 BLI_strnlen_utf8_ex(st, st_maxncpy - 1, &src_len);
482 }
483 else {
484 src_len = strlen(st);
485 }
486 const int stlen = int(src_len) + 1;
487 IDP_ResizeArray(prop, stlen);
488 memcpy(prop->data.pointer, st, size_t(stlen));
489 IDP_string_get(prop)[stlen - 1] = '\0';
490 return;
491 }
492
493 const bool is_byte = prop->subtype == IDP_STRING_SUB_BYTE;
494 const int stlen = int((st_maxncpy > 0) ? BLI_strnlen(st, st_maxncpy - 1) : strlen(st)) +
495 (is_byte ? 0 : 1);
496 IDP_ResizeArray(prop, stlen);
497 if (stlen > 0) {
498 memcpy(prop->data.pointer, st, size_t(stlen));
499 if (is_byte == false) {
500 IDP_string_get(prop)[stlen - 1] = '\0';
501 }
502 }
503}
504
505void IDP_AssignString(IDProperty *prop, const char *st)
506{
507 /* FIXME: Should never be called for `byte` subtype, needs an assert. */
508
509 IDP_AssignStringMaxSize(prop, st, 0);
510}
511
513{
514 BLI_assert(prop->type == IDP_STRING);
515
516 if (prop->data.pointer) {
517 MEM_delete(static_cast<char *>(prop->data.pointer));
518 }
519}
520
521
522/* -------------------------------------------------------------------- */
525
526void IDP_EnumItemsFree(IDPropertyUIDataEnumItem *items, const int items_num)
527{
528 for (const int64_t i : IndexRange(items_num)) {
529 IDPropertyUIDataEnumItem &item = items[i];
530 MEM_SAFE_DELETE(item.identifier);
531 MEM_SAFE_DELETE(item.name);
532 MEM_SAFE_DELETE(item.description);
533 }
534 MEM_SAFE_DELETE(items);
535}
536
538{
539 IDP_EnumItemsFree(ui_data->enum_items, ui_data->enum_items_num);
540 ui_data->enum_items = nullptr;
541}
542
544{
545 BLI_assert(prop->type == IDP_INT);
546 const IDPropertyUIDataInt *ui_data = reinterpret_cast<const IDPropertyUIDataInt *>(
547 prop->ui_data);
548
549 const int value = IDP_int_get(prop);
550 for (const IDPropertyUIDataEnumItem &item : Span(ui_data->enum_items, ui_data->enum_items_num)) {
551 if (item.value == value) {
552 return &item;
553 }
554 }
555 return nullptr;
556}
557
559 const int items_num,
560 void (*error_fn)(const char *))
561{
562 Set<int> used_values;
563 Set<const char *> used_identifiers;
564 used_values.reserve(items_num);
565 used_identifiers.reserve(items_num);
566
567 bool is_valid = true;
568 for (const int64_t i : IndexRange(items_num)) {
569 const IDPropertyUIDataEnumItem &item = items[i];
570 if (item.identifier == nullptr || item.identifier[0] == '\0') {
571 if (error_fn) {
572 const std::string msg = "Item identifier is empty";
573 error_fn(msg.c_str());
574 }
575 is_valid = false;
576 }
577 if (!used_identifiers.add(item.identifier)) {
578 if (error_fn) {
579 const std::string msg = fmt::format("Item identifier '{}' is already used",
580 item.identifier);
581 error_fn(msg.c_str());
582 }
583 is_valid = false;
584 }
585 if (!used_values.add(item.value)) {
586 if (error_fn) {
587 const std::string msg = fmt::format(
588 "Item value {} for item '{}' is already used", item.value, item.identifier);
589 error_fn(msg.c_str());
590 }
591 is_valid = false;
592 }
593 }
594 return is_valid;
595}
596
598
599/* -------------------------------------------------------------------- */
602
603static IDProperty *IDP_CopyID(const IDProperty *prop, const int flag)
604{
605 BLI_assert(prop->type == IDP_ID);
606 IDProperty *newp = idp_generic_copy(prop, flag);
607
608 newp->data.pointer = prop->data.pointer;
609 if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
610 id_us_plus(IDP_ID_get(newp));
611 }
612
613 return newp;
614}
615
616void IDP_AssignID(IDProperty *prop, ID *id, const int flag)
617{
618 BLI_assert(prop->type == IDP_ID);
619 /* Do not assign embedded IDs to IDProperties. */
620 BLI_assert(!id || (id->flag & ID_FLAG_EMBEDDED_DATA) == 0);
621
622 if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0 && IDP_ID_get(prop) != nullptr) {
623 id_us_min(IDP_ID_get(prop));
624 }
625
626 prop->data.pointer = id;
627
628 if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
629 id_us_plus(IDP_ID_get(prop));
630 }
631}
632
634
635/* -------------------------------------------------------------------- */
638
642static IDProperty *IDP_CopyGroup(const IDProperty *prop, const int flag)
643{
644 BLI_assert(prop->type == IDP_GROUP);
645 IDProperty *newp = idp_generic_copy(prop, flag);
646 newp->subtype = prop->subtype;
647
648 for (IDProperty &link : prop->data.group) {
649 IDP_AddToGroup(newp, IDP_CopyProperty_ex(&link, flag));
650 }
651
652 return newp;
653}
654
656{
657 BLI_assert(dest->type == IDP_GROUP);
658 BLI_assert(src->type == IDP_GROUP);
659
660 for (IDProperty &prop : src->data.group) {
661 IDProperty *other = IDP_GetPropertyFromGroup(dest, prop.name);
662 if (other && prop.type == other->type) {
663 switch (prop.type) {
664 case IDP_INT:
665 case IDP_FLOAT:
666 case IDP_DOUBLE:
667 case IDP_BOOLEAN:
668 other->data = prop.data;
669 break;
670 case IDP_GROUP:
671 IDP_SyncGroupValues(other, &prop);
672 break;
673 default: {
674 IDP_ReplaceInGroup_ex(dest, IDP_CopyProperty(&prop), other, 0);
675 break;
676 }
677 }
678 }
679 }
680}
681
682void IDP_SyncGroupTypes(IDProperty *dest, const IDProperty *src, const bool do_arraylen)
683{
684 for (IDProperty &prop_dst : dest->data.group.items_mutable()) {
685 const IDProperty *prop_src = IDP_GetPropertyFromGroup(const_cast<IDProperty *>(src),
686 prop_dst.name);
687 if (prop_src != nullptr) {
688 /* check of we should replace? */
689 if ((prop_dst.type != prop_src->type || prop_dst.subtype != prop_src->subtype) ||
690 (do_arraylen && ELEM(prop_dst.type, IDP_ARRAY, IDP_IDPARRAY) &&
691 (prop_src->len != prop_dst.len)))
692 {
693 IDP_ReplaceInGroup_ex(dest, IDP_CopyProperty(prop_src), &prop_dst, 0);
694 }
695 else if (prop_dst.type == IDP_GROUP) {
696 IDP_SyncGroupTypes(&prop_dst, prop_src, do_arraylen);
697 }
698 }
699 else {
700 IDP_FreeFromGroup(dest, &prop_dst);
701 }
702 }
703}
704
706{
707 BLI_assert(dest->type == IDP_GROUP);
708 BLI_assert(src->type == IDP_GROUP);
709
710 for (IDProperty &prop : src->data.group) {
711 IDProperty *old_dest_prop = IDP_GetPropertyFromGroup(dest, prop.name);
712 IDP_ReplaceInGroup_ex(dest, IDP_CopyProperty(&prop), old_dest_prop, 0);
713 }
714}
715
717 IDProperty *prop,
718 IDProperty *prop_exist,
719 const int flag)
720{
721 BLI_assert(group->type == IDP_GROUP);
722 BLI_assert(prop_exist == IDP_GetPropertyFromGroup(group, prop->name));
723
724 if (prop_exist != nullptr) {
725 /* Insert the new property at the same position as the old one in the linked list. */
726 BLI_insertlinkreplace(&group->data.group, prop_exist, prop);
728 group->data.children_map->children.remove_contained(prop_exist);
729 group->data.children_map->children.add_new(prop);
730 IDP_FreeProperty_ex(prop_exist, (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0);
731 }
732 else {
733 IDP_AddToGroup(group, prop);
734 }
735}
736
738{
739 IDProperty *prop_exist = IDP_GetPropertyFromGroup(group, prop->name);
740
741 IDP_ReplaceInGroup_ex(group, prop, prop_exist, 0);
742}
743
745 const IDProperty *src,
746 const bool do_overwrite,
747 const int flag)
748{
749 BLI_assert(dest->type == IDP_GROUP);
750 BLI_assert(src->type == IDP_GROUP);
751
752 if (do_overwrite) {
753 for (IDProperty &prop : src->data.group) {
754 if (prop.type == IDP_GROUP) {
755 IDProperty *prop_exist = IDP_GetPropertyFromGroup(dest, prop.name);
756
757 if (prop_exist != nullptr) {
758 IDP_MergeGroup_ex(prop_exist, &prop, do_overwrite, flag);
759 continue;
760 }
761 }
762
763 IDProperty *copy = IDP_CopyProperty_ex(&prop, flag);
764 IDP_ReplaceInGroup_ex(dest, copy, IDP_GetPropertyFromGroup(dest, copy->name), flag);
765 }
766 }
767 else {
768 for (IDProperty &prop : src->data.group) {
769 IDProperty *prop_exist = IDP_GetPropertyFromGroup(dest, prop.name);
770 if (prop_exist != nullptr) {
771 if (prop.type == IDP_GROUP) {
772 IDP_MergeGroup_ex(prop_exist, &prop, do_overwrite, flag);
773 continue;
774 }
775 }
776 else {
777 IDP_AddToGroup(dest, IDP_CopyProperty_ex(&prop, flag));
778 }
779 }
780 }
781}
782
783void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, const bool do_overwrite)
784{
785 IDP_MergeGroup_ex(dest, src, do_overwrite, 0);
786}
787
789{
790 BLI_assert(group->type == IDP_GROUP);
791
793 if (group->data.children_map->children.add(prop)) {
794 group->len++;
795 BLI_addtail(&group->data.group, prop);
796 return true;
797 }
798 return false;
799}
800
802{
803 BLI_assert(group->type == IDP_GROUP);
804 BLI_assert(BLI_findindex(&group->data.group, prop) != -1);
805
806 group->len--;
807 BLI_remlink(&group->data.group, prop);
809 group->data.children_map->children.remove_contained(prop);
810}
811
813{
814 IDP_RemoveFromGroup(group, prop);
815 IDP_FreeProperty(prop);
816}
817
819{
820 BLI_assert(prop->type == IDP_GROUP);
821 if (prop->len == 0) {
822 BLI_assert(prop->data.children_map == nullptr || prop->data.children_map->children.is_empty());
823 return nullptr;
824 }
825 /* If there is at least one item, the map is expected to exist. */
827 BLI_assert(prop->data.children_map->children.size() == prop->len);
828 return prop->data.children_map->children.lookup_key_default_as(name, nullptr);
829}
830
832{
833 if (!prop) {
834 return nullptr;
835 }
836 return IDP_GetPropertyFromGroup(prop, name);
837}
838
840 const StringRef name,
841 const char type)
842{
844 return (idprop && idprop->type == type) ? idprop : nullptr;
845}
846
847/* Ok, the way things work, Groups free the ID Property structs of their children.
848 * This is because all ID Property freeing functions free only direct data (not the ID Property
849 * struct itself), but for Groups the child properties *are* considered
850 * direct data. */
851static void IDP_FreeGroup(IDProperty *prop, const bool do_id_user, const int recursion_depth)
852{
853 BLI_assert(prop->type == IDP_GROUP);
854
855 MEM_SAFE_DELETE(prop->data.children_map);
856 for (IDProperty &loop : prop->data.group) {
857 idp_free_property_content_recurse(&loop, do_id_user, recursion_depth + 1);
858 }
859 prop->data.group.free_no_destruct();
860}
861
862std::optional<StringRefNull> IDP_group_lookup_string(const IDProperty &group, StringRef name)
863{
864 const IDProperty *prop = IDP_GetPropertyFromGroup(&group, name);
865 if (!prop || prop->type != IDP_STRING) {
866 return std::nullopt;
867 }
868 return IDP_string_get(prop);
869}
870
871std::optional<float> IDP_group_lookup_float(const IDProperty &group, StringRef name)
872{
873 const IDProperty *prop = IDP_GetPropertyFromGroup(&group, name);
874 if (!prop || prop->type != IDP_FLOAT) {
875 return std::nullopt;
876 }
877 return IDP_float_get(prop);
878}
879
880std::optional<int> IDP_group_lookup_int(const IDProperty &group, StringRef name)
881{
882 const IDProperty *prop = IDP_GetPropertyFromGroup(&group, name);
883 if (!prop || prop->type != IDP_INT) {
884 return std::nullopt;
885 }
886 return IDP_int_get(prop);
887}
888
889std::optional<bool> IDP_group_lookup_bool(const IDProperty &group, StringRef name)
890{
891 const IDProperty *prop = IDP_GetPropertyFromGroup(&group, name);
892 if (!prop || prop->type != IDP_BOOLEAN) {
893 return std::nullopt;
894 }
895 return IDP_bool_get(prop);
896}
897
898std::optional<Span<float>> IDP_group_lookup_float_array(const IDProperty &group,
899 StringRef name,
900 int required_size)
901{
902 const IDProperty *prop = IDP_GetPropertyFromGroup(&group, name);
903 /* The subtype has to be checked too: an array of any other element type, such as the doubles
904 * that assigning a float array through Python produces, must not reach #IDP_array_float_get. */
905 if (!prop || prop->type != IDP_ARRAY || prop->subtype != IDP_FLOAT) {
906 return std::nullopt;
907 }
908 if (prop->len != required_size) {
909 return std::nullopt;
910 }
911 return Span(IDP_array_float_get(prop), prop->len);
912}
913
915
916/* -------------------------------------------------------------------- */
919
921{
922 switch (prop->type) {
923 case IDP_INT:
924 return IDP_int_get(prop);
925 case IDP_DOUBLE:
926 return int(IDP_double_get(prop));
927 case IDP_FLOAT:
928 return int(IDP_float_get(prop));
929 case IDP_BOOLEAN:
930 return int(IDP_bool_get(prop));
931 default:
932 return 0;
933 }
934}
935
937{
938 switch (prop->type) {
939 case IDP_DOUBLE:
940 return IDP_double_get(prop);
941 case IDP_FLOAT:
942 return double(IDP_float_get(prop));
943 case IDP_INT:
944 return double(IDP_int_get(prop));
945 case IDP_BOOLEAN:
946 return double(IDP_bool_get(prop));
947 default:
948 return 0.0;
949 }
950}
951
953{
954 switch (prop->type) {
955 case IDP_FLOAT:
956 return IDP_float_get(prop);
957 case IDP_DOUBLE:
958 return float(IDP_double_get(prop));
959 case IDP_INT:
960 return float(IDP_int_get(prop));
961 case IDP_BOOLEAN:
962 return float(IDP_bool_get(prop));
963 default:
964 return 0.0f;
965 }
966}
967
968IDProperty *IDP_CopyProperty_ex(const IDProperty *prop, const int flag)
969{
970 switch (prop->type) {
971 case IDP_GROUP:
972 return IDP_CopyGroup(prop, flag);
973 case IDP_STRING:
974 return IDP_CopyString(prop, flag);
975 case IDP_ID:
976 return IDP_CopyID(prop, flag);
977 case IDP_ARRAY:
978 return IDP_CopyArray(prop, flag);
979 case IDP_IDPARRAY:
980 return IDP_CopyIDPArray(prop, flag);
981 default:
982 return idp_generic_copy(prop, flag);
983 }
984}
985
987{
988 return IDP_CopyProperty_ex(prop, 0);
989}
990
992{
993 IDProperty *idprop_tmp = IDP_CopyProperty(src);
994 idprop_tmp->prev = dst->prev;
995 idprop_tmp->next = dst->next;
996 std::swap(*dst, *idprop_tmp);
997 IDP_FreeProperty(idprop_tmp);
998}
999
1001{
1002 return id->properties;
1003}
1004
1006{
1007 if (id->properties == nullptr) {
1008 id->properties = MEM_new<IDProperty>("IDProperty");
1009 id->properties->type = IDP_GROUP;
1010 /* NOTE(@ideasman42): Don't overwrite the data's name and type
1011 * some functions might need this if they
1012 * don't have a real ID, should be named elsewhere. */
1013 // STRNCPY(id->name, "top_level_group");
1014 }
1015 return id->properties;
1016}
1017
1019{
1020 return id->system_properties;
1021}
1022
1024{
1025 if (id->system_properties == nullptr) {
1026 id->system_properties = MEM_new<IDProperty>(__func__);
1027 id->system_properties->type = IDP_GROUP;
1028 /* NOTE(@ideasman42): Don't overwrite the data's name and type
1029 * some functions might need this if they
1030 * don't have a real ID, should be named elsewhere. */
1031 // STRNCPY(id->name, "top_level_group");
1032 }
1033 return id->system_properties;
1034}
1035
1037 const IDProperty *prop2,
1038 const bool is_strict)
1039{
1040 if (prop1 == nullptr && prop2 == nullptr) {
1041 return true;
1042 }
1043 if (prop1 == nullptr || prop2 == nullptr) {
1044 return is_strict ? false : true;
1045 }
1046 if (prop1->type != prop2->type) {
1047 return false;
1048 }
1049
1050 switch (prop1->type) {
1051 case IDP_INT:
1052 return (IDP_int_get(prop1) == IDP_int_get(prop2));
1053 case IDP_FLOAT:
1054#if !defined(NDEBUG) && defined(WITH_PYTHON)
1055 {
1056 float p1 = IDP_float_get(prop1);
1057 float p2 = IDP_float_get(prop2);
1058 if ((p1 != p2) && ((fabsf(p1 - p2) / max_ff(fabsf(p1), fabsf(p2))) < 0.001f)) {
1059 printf(
1060 "WARNING: Comparing two float properties that have nearly the same value (%f vs. "
1061 "%f)\n",
1062 p1,
1063 p2);
1064 printf(" p1: ");
1065 IDP_print(prop1);
1066 printf(" p2: ");
1067 IDP_print(prop2);
1068 }
1069 }
1070#endif
1071 return (IDP_float_get(prop1) == IDP_float_get(prop2));
1072 case IDP_DOUBLE:
1073 return (IDP_double_get(prop1) == IDP_double_get(prop2));
1074 case IDP_BOOLEAN:
1075 return (IDP_bool_get(prop1) == IDP_bool_get(prop2));
1076 case IDP_STRING: {
1077 return ((prop1->len == prop2->len) &&
1078 STREQLEN(IDP_string_get(prop1), IDP_string_get(prop2), size_t(prop1->len)));
1079 }
1080 case IDP_ARRAY:
1081 if (prop1->len == prop2->len && prop1->subtype == prop2->subtype) {
1082 return (memcmp(IDP_array_voidp_get(prop1),
1083 IDP_array_voidp_get(prop2),
1084 idp_size_table[int(prop1->subtype)] * size_t(prop1->len)) == 0);
1085 }
1086 return false;
1087 case IDP_GROUP: {
1088 if (is_strict && prop1->len != prop2->len) {
1089 return false;
1090 }
1091
1092 for (const IDProperty &link1 : prop1->data.group) {
1093 const IDProperty *link2 = IDP_GetPropertyFromGroup(prop2, link1.name);
1094
1095 if (!IDP_EqualsProperties_ex(&link1, link2, is_strict)) {
1096 return false;
1097 }
1098 }
1099
1100 return true;
1101 }
1102 case IDP_IDPARRAY: {
1103 const IDProperty *array1 = IDP_property_array_get(prop1);
1104 const IDProperty *array2 = IDP_property_array_get(prop2);
1105
1106 if (prop1->len != prop2->len) {
1107 return false;
1108 }
1109
1110 for (int i = 0; i < prop1->len; i++) {
1111 if (!IDP_EqualsProperties_ex(&array1[i], &array2[i], is_strict)) {
1112 return false;
1113 }
1114 }
1115 return true;
1116 }
1117 case IDP_ID:
1118 return (IDP_ID_get(prop1) == IDP_ID_get(prop2));
1119 default:
1121 break;
1122 }
1123
1124 return true;
1125}
1126
1127bool IDP_EqualsProperties(const IDProperty *prop1, const IDProperty *prop2)
1128{
1129 return IDP_EqualsProperties_ex(prop1, prop2, true);
1130}
1131
1132IDProperty *IDP_New(const char type,
1133 const IDPropertyTemplate *val,
1134 const StringRef name,
1135 const eIDPropertyFlag flags)
1136{
1137 IDProperty *prop = nullptr;
1138
1139 switch (type) {
1140 case IDP_INT:
1141 prop = MEM_new<IDProperty>("IDProperty int");
1142 prop->data.val = val->i;
1143 break;
1144 case IDP_FLOAT:
1145 prop = MEM_new<IDProperty>("IDProperty float");
1146 *reinterpret_cast<float *>(&prop->data.val) = val->f;
1147 break;
1148 case IDP_DOUBLE:
1149 prop = MEM_new<IDProperty>("IDProperty double");
1150 *reinterpret_cast<double *>(&prop->data.val) = val->d;
1151 break;
1152 case IDP_BOOLEAN:
1153 prop = MEM_new<IDProperty>("IDProperty boolean");
1154 prop->data.val = bool(val->i);
1155 break;
1156 case IDP_ARRAY: {
1157 /* FIXME: This seems to be the only place in code allowing `IDP_GROUP` as subtype of an
1158 * `IDP_ARRAY`. This is most likely a mistake. `IDP_GROUP` array should be of type
1159 * `IDP_IDPARRAY`, as done e.g. in #idp_from_PySequence_Buffer in bpy API. */
1161 prop = MEM_new<IDProperty>("IDProperty array");
1162 prop->subtype = val->array.type;
1163 if (val->array.len) {
1165 size_t(val->array.len), idp_size_table[val->array.type], "id property array");
1166 }
1167 prop->len = prop->totallen = val->array.len;
1168 break;
1169 }
1170 CLOG_ERROR(&LOG, "bad array type.");
1171 return nullptr;
1172 }
1173 case IDP_STRING: {
1174 const char *st = val->string.str;
1175
1176 prop = MEM_new<IDProperty>("IDProperty string");
1177 if (val->string.subtype == IDP_STRING_SUB_BYTE) {
1178 /* NOTE: Intentionally not null terminated. */
1179 if (st == nullptr) {
1181 "id property string 1");
1182 *IDP_string_get(prop) = '\0';
1184 prop->len = 0;
1185 }
1186 else {
1187 prop->data.pointer = MEM_new_array_uninitialized<char>(size_t(val->string.len),
1188 "id property string 2");
1189 prop->len = prop->totallen = val->string.len;
1190 memcpy(prop->data.pointer, st, size_t(val->string.len));
1191 }
1193 }
1194 else {
1195 if (st == nullptr || val->string.len <= 1) {
1197 "id property string 1");
1198 *IDP_string_get(prop) = '\0';
1200 /* nullptr string, has len of 1 to account for null byte. */
1201 prop->len = 1;
1202 }
1203 else {
1204 BLI_assert(int(val->string.len) <= int(strlen(st)) + 1);
1205 prop->data.pointer = MEM_new_array_uninitialized<char>(size_t(val->string.len),
1206 "id property string 3");
1207 memcpy(prop->data.pointer, st, size_t(val->string.len) - 1);
1208 IDP_string_get(prop)[val->string.len - 1] = '\0';
1209 prop->len = prop->totallen = val->string.len;
1210 }
1212 }
1213 break;
1214 }
1215 case IDP_GROUP: {
1216 /* Values are set properly by calloc. */
1217 prop = MEM_new<IDProperty>("IDProperty group");
1218 break;
1219 }
1220 case IDP_ID: {
1221 prop = MEM_new<IDProperty>("IDProperty datablock");
1222 prop->data.pointer = static_cast<void *>(val->id);
1223 prop->type = IDP_ID;
1224 id_us_plus(IDP_ID_get(prop));
1225 break;
1226 }
1227 default: {
1228 prop = MEM_new<IDProperty>("IDProperty array");
1229 break;
1230 }
1231 }
1232
1233 prop->type = eIDPropertyType(type);
1234 name.copy_utf8_truncated(prop->name);
1235 prop->flag = flags;
1236
1237 return prop;
1238}
1239
1240IDProperty *IDP_NewInt(const int value, const blender::StringRef name, const eIDPropertyFlag flags)
1241{
1242 IDPropertyTemplate prop_template{0};
1243 prop_template.i = value;
1244 return IDP_New(IDP_INT, &prop_template, name, flags);
1245}
1246
1248 const eIDPropertyUIDataType type,
1249 const IDPropertyUIData *other)
1250{
1251 if (ui_data->description != other->description) {
1252 MEM_SAFE_DELETE(ui_data->description);
1253 }
1254
1255 switch (type) {
1257 const IDPropertyUIDataString *other_string =
1258 reinterpret_cast<const IDPropertyUIDataString *>(other);
1259 IDPropertyUIDataString *ui_data_string = reinterpret_cast<IDPropertyUIDataString *>(ui_data);
1260 if (ui_data_string->default_value != other_string->default_value) {
1261 MEM_SAFE_DELETE(ui_data_string->default_value);
1262 }
1263 break;
1264 }
1265 case IDP_UI_DATA_TYPE_ID: {
1266 break;
1267 }
1268 case IDP_UI_DATA_TYPE_INT: {
1269 const IDPropertyUIDataInt *other_int = reinterpret_cast<const IDPropertyUIDataInt *>(other);
1270 IDPropertyUIDataInt *ui_data_int = reinterpret_cast<IDPropertyUIDataInt *>(ui_data);
1271 if (ui_data_int->default_array != other_int->default_array) {
1272 MEM_SAFE_DELETE(ui_data_int->default_array);
1273 }
1274 if (ui_data_int->enum_items != other_int->enum_items) {
1276 }
1277 break;
1278 }
1280 const IDPropertyUIDataBool *other_bool = reinterpret_cast<const IDPropertyUIDataBool *>(
1281 other);
1282 IDPropertyUIDataBool *ui_data_bool = reinterpret_cast<IDPropertyUIDataBool *>(ui_data);
1283 if (ui_data_bool->default_array != other_bool->default_array) {
1284 MEM_SAFE_DELETE(ui_data_bool->default_array);
1285 }
1286 break;
1287 }
1289 const IDPropertyUIDataFloat *other_float = reinterpret_cast<const IDPropertyUIDataFloat *>(
1290 other);
1291 IDPropertyUIDataFloat *ui_data_float = reinterpret_cast<IDPropertyUIDataFloat *>(ui_data);
1292 if (ui_data_float->default_array != other_float->default_array) {
1293 MEM_SAFE_DELETE(ui_data_float->default_array);
1294 }
1295 break;
1296 }
1298 break;
1299 }
1300 }
1301}
1302
1303static void ui_data_free(IDPropertyUIData *ui_data, const eIDPropertyUIDataType type)
1304{
1305 switch (type) {
1307 IDPropertyUIDataString *ui_data_string = reinterpret_cast<IDPropertyUIDataString *>(ui_data);
1308 MEM_SAFE_DELETE(ui_data_string->default_value);
1309 break;
1310 }
1311 case IDP_UI_DATA_TYPE_ID: {
1312 break;
1313 }
1314 case IDP_UI_DATA_TYPE_INT: {
1315 IDPropertyUIDataInt *ui_data_int = reinterpret_cast<IDPropertyUIDataInt *>(ui_data);
1316 MEM_SAFE_DELETE(ui_data_int->default_array);
1318 break;
1319 }
1321 IDPropertyUIDataBool *ui_data_bool = reinterpret_cast<IDPropertyUIDataBool *>(ui_data);
1322 MEM_SAFE_DELETE(ui_data_bool->default_array);
1323 break;
1324 }
1326 IDPropertyUIDataFloat *ui_data_float = reinterpret_cast<IDPropertyUIDataFloat *>(ui_data);
1327 MEM_SAFE_DELETE(ui_data_float->default_array);
1328 break;
1329 }
1331 break;
1332 }
1333 }
1334
1335 MEM_SAFE_DELETE(ui_data->description);
1336
1337 MEM_delete(ui_data);
1338}
1339
1341{
1343 prop->ui_data = nullptr;
1344}
1345
1347 const bool do_id_user,
1348 const int recursion_depth)
1349{
1350 if (recursion_depth > MAX_IDPROP_DEPTH_LEVEL) {
1351 CLOG_ERROR(&LOG,
1352 "Too deep level of IDProperties embedding detected (over %d levels), this is "
1353 "likely caused by a buggy script or add-on. The data in property '%s' will not "
1354 "be freed",
1356 prop->name);
1357 return;
1358 }
1359
1360 switch (prop->type) {
1361 case IDP_INT:
1362 case IDP_FLOAT:
1363 case IDP_DOUBLE:
1364 case IDP_BOOLEAN:
1365 break;
1366 case IDP_ARRAY:
1367 IDP_FreeArray(prop, do_id_user, recursion_depth);
1368 break;
1369 case IDP_STRING:
1370 IDP_FreeString(prop);
1371 break;
1372 case IDP_GROUP:
1373 IDP_FreeGroup(prop, do_id_user, recursion_depth);
1374 break;
1375 case IDP_IDPARRAY:
1376 IDP_FreeIDPArray(prop, do_id_user, recursion_depth);
1377 break;
1378 case IDP_ID:
1379 if (do_id_user) {
1380 id_us_min(IDP_ID_get(prop));
1381 }
1382 break;
1383 }
1384
1385 if (prop->ui_data != nullptr) {
1386 IDP_ui_data_free(prop);
1387 }
1388}
1389
1391 const bool do_id_user,
1392 const int recursion_depth)
1393{
1394 idp_free_property_content_recurse(prop, do_id_user, recursion_depth);
1395 MEM_delete(prop);
1396}
1397
1398void IDP_FreeProperty_ex(IDProperty *prop, const bool do_id_user)
1399{
1400 idp_free_property_recurse(prop, do_id_user, 0);
1401}
1402
1404{
1405 idp_free_property_recurse(prop, true, 0);
1406}
1407
1409{
1410 idp_free_property_content_recurse(prop, true, 0);
1411 prop->data.pointer = nullptr;
1412 prop->len = prop->totallen = 0;
1413}
1414
1415void IDP_Reset(IDProperty *prop, const IDProperty *reference)
1416{
1417 if (prop == nullptr) {
1418 return;
1419 }
1420 IDP_ClearProperty(prop);
1421 if (reference != nullptr) {
1422 IDP_MergeGroup(prop, reference, true);
1423 }
1424}
1425
1426static void idp_foreach_property_recurse(IDProperty *id_property_root,
1427 const int type_filter,
1428 const int recursion_depth,
1429 const FunctionRef<void(IDProperty *id_property)> callback)
1430{
1431 if (!id_property_root) {
1432 return;
1433 }
1434
1435 if (recursion_depth > MAX_IDPROP_DEPTH_LEVEL) {
1436 CLOG_ERROR(&LOG,
1437 "Too deep level of IDProperties embedding detected (over %d levels), this is "
1438 "likely caused by a buggy script or add-on. The data in property '%s' will not "
1439 "be processed further",
1441 id_property_root->name);
1442 return;
1443 }
1444
1445 if (type_filter == 0 || (1 << id_property_root->type) & type_filter) {
1446 callback(id_property_root);
1447 }
1448
1449 /* Recursive call into container types of ID properties. */
1450 switch (id_property_root->type) {
1451 case IDP_GROUP: {
1452 for (IDProperty &loop : id_property_root->data.group) {
1453 idp_foreach_property_recurse(&loop, type_filter, recursion_depth + 1, callback);
1454 }
1455 break;
1456 }
1457 case IDP_IDPARRAY: {
1458 IDProperty *loop = IDP_property_array_get(id_property_root);
1459 for (int i = 0; i < id_property_root->len; i++) {
1460 idp_foreach_property_recurse(&loop[i], type_filter, recursion_depth + 1, callback);
1461 }
1462 break;
1463 }
1464 default:
1465 break; /* Nothing to do here with other types of IDProperties... */
1466 }
1467}
1468
1469void IDP_foreach_property(IDProperty *id_property_root,
1470 const int type_filter,
1471 const FunctionRef<void(IDProperty *id_property)> callback)
1472{
1473 idp_foreach_property_recurse(id_property_root, type_filter, 0, callback);
1474}
1475
1476static void idp_blend_write_recurse(BlendWriter *writer,
1477 const IDProperty *prop,
1478 const int recursion_depth);
1479static void IDP_WriteProperty_OnlyData(const IDProperty *prop,
1480 BlendWriter *writer,
1481 const int recursion_depth);
1482
1483static void write_ui_data(const IDProperty *prop, BlendWriter *writer)
1484{
1485 IDPropertyUIData *ui_data = prop->ui_data;
1486
1487 writer->write_string(ui_data->description);
1488
1489 switch (IDP_ui_data_type(prop)) {
1491 IDPropertyUIDataString *ui_data_string = reinterpret_cast<IDPropertyUIDataString *>(ui_data);
1492 writer->write_string(ui_data_string->default_value);
1493 writer->write_struct_cast<IDPropertyUIDataString>(ui_data);
1494 break;
1495 }
1496 case IDP_UI_DATA_TYPE_ID: {
1497 writer->write_struct_cast<IDPropertyUIDataID>(ui_data);
1498 break;
1499 }
1500 case IDP_UI_DATA_TYPE_INT: {
1501 IDPropertyUIDataInt *ui_data_int = reinterpret_cast<IDPropertyUIDataInt *>(ui_data);
1502 if (prop->type == IDP_ARRAY) {
1503 writer->write_int32_array(uint(ui_data_int->default_array_len),
1504 static_cast<int32_t *>(ui_data_int->default_array));
1505 }
1506 writer->write_struct_array(ui_data_int->enum_items_num, ui_data_int->enum_items);
1507 for (const int64_t i : IndexRange(ui_data_int->enum_items_num)) {
1508 IDPropertyUIDataEnumItem &item = ui_data_int->enum_items[i];
1509 writer->write_string(item.identifier);
1510 writer->write_string(item.name);
1511 writer->write_string(item.description);
1512 }
1513 writer->write_struct_cast<IDPropertyUIDataInt>(ui_data);
1514 break;
1515 }
1517 IDPropertyUIDataBool *ui_data_bool = reinterpret_cast<IDPropertyUIDataBool *>(ui_data);
1518 if (prop->type == IDP_ARRAY) {
1519 writer->write_int8_array(uint(ui_data_bool->default_array_len),
1520 const_cast<const int8_t *>(ui_data_bool->default_array));
1521 }
1522 writer->write_struct_cast<IDPropertyUIDataBool>(ui_data);
1523 break;
1524 }
1526 IDPropertyUIDataFloat *ui_data_float = reinterpret_cast<IDPropertyUIDataFloat *>(ui_data);
1527 if (prop->type == IDP_ARRAY) {
1528 writer->write_double_array(uint(ui_data_float->default_array_len),
1529 ui_data_float->default_array);
1530 }
1531 writer->write_struct_cast<IDPropertyUIDataFloat>(ui_data);
1532 break;
1533 }
1536 break;
1537 }
1538 }
1539}
1540
1541static void IDP_WriteArray(const IDProperty *prop, BlendWriter *writer, const int recursion_depth)
1542{
1543 /* Remember to set #IDProperty.totallen to len in the linking code! */
1544 if (prop->data.pointer) {
1545 /* Only write the actual data (`prop->len`), not the whole allocated buffer (`prop->totallen`).
1546 */
1547 switch (eIDPropertyType(prop->subtype)) {
1548 case IDP_GROUP: {
1549 writer->write_pointer_array(uint32_t(prop->len), prop->data.pointer);
1550
1551 IDProperty **array = static_cast<IDProperty **>(prop->data.pointer);
1552 for (int i = 0; i < prop->len; i++) {
1553 idp_blend_write_recurse(writer, array[i], recursion_depth + 1);
1554 }
1555 break;
1556 }
1557 case IDP_DOUBLE:
1558 writer->write_double_array(uint32_t(prop->len), static_cast<double *>(prop->data.pointer));
1559 break;
1560 case IDP_INT:
1561 writer->write_int32_array(uint32_t(prop->len), static_cast<int *>(prop->data.pointer));
1562 break;
1563 case IDP_FLOAT:
1564 writer->write_float_array(uint32_t(prop->len), static_cast<float *>(prop->data.pointer));
1565 break;
1566 case IDP_BOOLEAN:
1567 writer->write_int8_array(uint32_t(prop->len), static_cast<int8_t *>(prop->data.pointer));
1568 break;
1569 case IDP_STRING:
1570 case IDP_ARRAY:
1571 case IDP_ID:
1572 case IDP_IDPARRAY:
1574 break;
1575 }
1576 }
1577}
1578
1579static void IDP_WriteIDPArray(const IDProperty *prop,
1580 BlendWriter *writer,
1581 const int recursion_depth)
1582{
1583 /* Remember to set #IDProperty.totallen to len in the linking code! */
1584 if (prop->data.pointer) {
1585 const IDProperty *array = static_cast<const IDProperty *>(prop->data.pointer);
1586
1587 /* Recursion depth limit also needs to be handled here, as IDP arrays are written in a single
1588 * call, without going through a call to `idp_blend_write_recurse`. */
1589 if (recursion_depth > MAX_IDPROP_DEPTH_LEVEL_FOR_WRITE) {
1590 CLOG_ERROR(&LOG,
1591 "Too deep level of IDProperties embedding detected (over %d levels), this is "
1592 "likely caused by a buggy script or add-on. The data in property '%s' will not "
1593 "be written in the blend-file or memfile undo step",
1595 prop->name);
1596 IDProperty *empty_prop_idparray = IDP_NewIDPArray(prop->name);
1597 IDP_ResizeIDPArray(empty_prop_idparray, prop->len);
1598
1599 IDProperty *empty_array = static_cast<IDProperty *>(empty_prop_idparray->data.pointer);
1600 for (int a = 0; a < empty_prop_idparray->len; a++) {
1601 empty_array[a].type = IDP_INT;
1602 empty_array[a].subtype = 0;
1603 IDP_int_set(&empty_array[a], 0);
1604 STRNCPY(empty_array[a].name, array[a].name);
1605 }
1606
1608 empty_prop_idparray->len, prop->data.pointer, empty_array);
1609 for (int a = 0; a < empty_prop_idparray->len; a++) {
1610 IDP_WriteProperty_OnlyData(&empty_array[a], writer, recursion_depth + 1);
1611 }
1612
1613 IDP_FreeProperty_ex(empty_prop_idparray, false);
1614 return;
1615 }
1616
1617 writer->write_struct_array(prop->len, array);
1618 for (int a = 0; a < prop->len; a++) {
1619 IDP_WriteProperty_OnlyData(&array[a], writer, recursion_depth + 1);
1620 }
1621 }
1622}
1623
1624static void IDP_WriteString(const IDProperty *prop, BlendWriter *writer)
1625{
1626 /* Remember to set #IDProperty.totallen to len in the linking code! */
1627 /* Do not use #BlendWriter::write_string here, since 'bytes' sub-type of IDProperties may not be
1628 * null-terminated. */
1629 writer->write_char_array(uint(prop->len), static_cast<char *>(prop->data.pointer));
1630}
1631
1632static void IDP_WriteGroup(const IDProperty *prop, BlendWriter *writer, const int recursion_depth)
1633{
1634 for (IDProperty &loop : prop->data.group) {
1635 idp_blend_write_recurse(writer, &loop, recursion_depth + 1);
1636 }
1637}
1638
1639/* Functions to read/write ID Properties */
1641 BlendWriter *writer,
1642 const int recursion_depth)
1643{
1644 switch (prop->type) {
1645 case IDP_INT:
1646 case IDP_FLOAT:
1647 case IDP_DOUBLE:
1648 case IDP_BOOLEAN:
1649 case IDP_ID:
1650 break;
1651 case IDP_GROUP:
1652 IDP_WriteGroup(prop, writer, recursion_depth);
1653 break;
1654 case IDP_STRING:
1655 IDP_WriteString(prop, writer);
1656 break;
1657 case IDP_ARRAY:
1658 IDP_WriteArray(prop, writer, recursion_depth);
1659 break;
1660 case IDP_IDPARRAY:
1661 IDP_WriteIDPArray(prop, writer, recursion_depth);
1662 break;
1663 }
1664 if (prop->ui_data != nullptr) {
1665 write_ui_data(prop, writer);
1666 }
1667}
1668
1670 const IDProperty *prop,
1671 const int recursion_depth)
1672{
1673 if (recursion_depth > MAX_IDPROP_DEPTH_LEVEL_FOR_WRITE) {
1674 CLOG_ERROR(&LOG,
1675 "Too deep level of IDProperties embedding detected (over %d levels), this is "
1676 "likely caused by a buggy script or add-on. The data in property '%s' will not "
1677 "be written in the blend-file or memfile undo step",
1679 prop->name);
1680 IDProperty empty_prop = {};
1681 empty_prop.type = IDP_INT;
1682 empty_prop.subtype = 0;
1683 IDP_int_set(&empty_prop, 0);
1684 STRNCPY(empty_prop.name, prop->name);
1685 writer->write_struct_at_address(prop, &empty_prop);
1686 IDP_WriteProperty_OnlyData(&empty_prop, writer, recursion_depth);
1687 return;
1688 }
1689
1690 writer->write_struct(prop, [](BlendStructWriter<IDProperty> &struct_writer) {
1691 struct_writer.shallow_data.data.children_map = nullptr;
1692 });
1693 IDP_WriteProperty_OnlyData(prop, writer, recursion_depth);
1694}
1695
1696void IDP_BlendWrite(BlendWriter *writer, const IDProperty *prop)
1697{
1698 idp_blend_write_recurse(writer, prop, 0);
1699}
1700
1701static void IDP_DirectLinkProperty(IDProperty *prop,
1702 BlendDataReader *reader,
1703 const int recursion_depth);
1704
1705static void read_ui_data(IDProperty *prop, BlendDataReader *reader)
1706{
1707 /* NOTE: null UI data can happen when opening more recent files with unknown types of
1708 * IDProperties. */
1709
1710 switch (IDP_ui_data_type(prop)) {
1713 if (prop->ui_data) {
1714 IDPropertyUIDataString *ui_data_string = reinterpret_cast<IDPropertyUIDataString *>(
1715 prop->ui_data);
1716 BLO_read_string(reader, &ui_data_string->default_value);
1717 }
1718 break;
1719 }
1720 case IDP_UI_DATA_TYPE_ID: {
1722 break;
1723 }
1724 case IDP_UI_DATA_TYPE_INT: {
1726 IDPropertyUIDataInt *ui_data_int = reinterpret_cast<IDPropertyUIDataInt *>(prop->ui_data);
1727 if (prop->type == IDP_ARRAY) {
1729 reader, &ui_data_int->default_array, &ui_data_int->default_array_len);
1730 }
1731 else {
1732 ui_data_int->default_array = nullptr;
1733 ui_data_int->default_array_len = 0;
1734 }
1736 reader, &ui_data_int->enum_items, &ui_data_int->enum_items_num);
1737 for (const int64_t i : IndexRange(ui_data_int->enum_items_num)) {
1738 IDPropertyUIDataEnumItem &item = ui_data_int->enum_items[i];
1739 BLO_read_string(reader, &item.identifier);
1740 BLO_read_string(reader, &item.name);
1741 BLO_read_string(reader, &item.description);
1742 }
1743 break;
1744 }
1747 IDPropertyUIDataBool *ui_data_bool = reinterpret_cast<IDPropertyUIDataBool *>(prop->ui_data);
1748 if (prop->type == IDP_ARRAY) {
1750 reader, &ui_data_bool->default_array, &ui_data_bool->default_array_len);
1751 }
1752 else {
1753 ui_data_bool->default_array = nullptr;
1754 ui_data_bool->default_array_len = 0;
1755 }
1756 break;
1757 }
1760 IDPropertyUIDataFloat *ui_data_float = reinterpret_cast<IDPropertyUIDataFloat *>(
1761 prop->ui_data);
1762 if (prop->type == IDP_ARRAY) {
1764 reader, &ui_data_float->default_array, &ui_data_float->default_array_len);
1765 }
1766 else {
1767 ui_data_float->default_array = nullptr;
1768 ui_data_float->default_array_len = 0;
1769 }
1770 break;
1771 }
1774 /* Do not attempt to read unknown data. */
1775 prop->ui_data = nullptr;
1776 break;
1777 }
1778 }
1779
1780 if (prop->ui_data) {
1781 BLO_read_string(reader, &prop->ui_data->description);
1782 }
1783}
1784
1786 BlendDataReader *reader,
1787 const int recursion_depth)
1788{
1789 /* since we didn't save the extra buffer, set totallen to len */
1790 prop->totallen = prop->len;
1792 reader, reinterpret_cast<IDProperty **>(&prop->data.pointer), &prop->len);
1793
1794 IDProperty *array = static_cast<IDProperty *>(prop->data.pointer);
1795
1796 /* NOTE:, idp-arrays didn't exist in 2.4x, so the pointer will be cleared
1797 * there's not really anything we can do to correct this, at least don't crash */
1798 if (array == nullptr) {
1799 prop->len = 0;
1800 prop->totallen = 0;
1801 }
1802
1803 for (int i = 0; i < prop->len; i++) {
1804 IDP_DirectLinkProperty(&array[i], reader, recursion_depth + 1);
1805 }
1806}
1807
1809 BlendDataReader *reader,
1810 const int recursion_depth)
1811{
1812 /* since we didn't save the extra buffer, set totallen to len */
1813 prop->totallen = prop->len;
1814
1815 switch (eIDPropertyType(prop->subtype)) {
1816 case IDP_GROUP: {
1818 IDProperty **array = static_cast<IDProperty **>(prop->data.pointer);
1819 for (int i = 0; i < prop->len; i++) {
1820 IDP_DirectLinkProperty(array[i], reader, recursion_depth + 1);
1821 }
1822 break;
1823 }
1824 case IDP_DOUBLE:
1826 reader, reinterpret_cast<double **>(&prop->data.pointer), &prop->len);
1827 break;
1828 case IDP_INT:
1830 reader, reinterpret_cast<int **>(&prop->data.pointer), &prop->len);
1831 break;
1832 case IDP_FLOAT:
1834 reader, reinterpret_cast<float **>(&prop->data.pointer), &prop->len);
1835 break;
1836 case IDP_BOOLEAN:
1838 reader, reinterpret_cast<int8_t **>(&prop->data.pointer), &prop->len);
1839 break;
1840 case IDP_STRING:
1841 case IDP_ARRAY:
1842 case IDP_ID:
1843 case IDP_IDPARRAY:
1845 break;
1846 }
1847
1848 if (prop->data.pointer == nullptr) {
1849 prop->len = 0;
1850 prop->totallen = 0;
1851 }
1852}
1853
1855{
1857 reader, reinterpret_cast<char **>(&prop->data.pointer), &prop->len);
1858 /* Since we didn't save the extra string buffer, set totallen to len. */
1859 prop->totallen = prop->len;
1860}
1861
1863 BlendDataReader *reader,
1864 const int recursion_depth)
1865{
1866 ListBaseT<IDProperty> *lb = &prop->data.group;
1867 prop->data.children_map = nullptr;
1868
1869 BLO_read_struct_list(reader, IDProperty, lb);
1870
1871 if (!prop->data.group.is_empty()) {
1873 }
1874
1875 /* Link child id properties now. */
1876 for (IDProperty &loop : prop->data.group) {
1877 IDP_DirectLinkProperty(&loop, reader, recursion_depth + 1);
1878 if (!prop->data.children_map->children.add(&loop)) {
1879 CLOG_WARN(&LOG, "duplicate ID property '%s' in group", loop.name);
1880 }
1881 }
1882}
1883
1885 BlendDataReader *reader,
1886 const int recursion_depth)
1887{
1888 auto reset_property = [](IDProperty *idprop) -> void {
1889 idprop->type = IDP_INT;
1890 idprop->subtype = 0;
1891 IDP_int_set(idprop, 0);
1892 idprop->ui_data = nullptr;
1893 };
1894
1895 if (recursion_depth > MAX_IDPROP_DEPTH_LEVEL_FOR_READ) {
1896 CLOG_ERROR(&LOG,
1897 "Too deep level of IDProperties embedding detected (over %d levels), this is "
1898 "likely caused by a buggy script or add-on. The data in property '%s' will not "
1899 "be read from the blend-file",
1901 prop->name);
1902 /* NOTE: No attempt to free the property, as it may lead to further recursion. */
1903 reset_property(prop);
1904 return;
1905 }
1906
1907 switch (prop->type) {
1908 case IDP_GROUP:
1909 IDP_DirectLinkGroup(prop, reader, recursion_depth);
1910 break;
1911 case IDP_STRING:
1912 IDP_DirectLinkString(prop, reader);
1913 break;
1914 case IDP_ARRAY:
1915 IDP_DirectLinkArray(prop, reader, recursion_depth);
1916 break;
1917 case IDP_IDPARRAY:
1918 IDP_DirectLinkIDPArray(prop, reader, recursion_depth);
1919 break;
1920 case IDP_DOUBLE:
1921 /* NOTE: this is endianness-sensitive. */
1922 /* Doubles are stored in the same field as `int val, val2` in the #IDPropertyData struct.
1923 *
1924 * In case of endianness switching, `val` and `val2` would have already been switched by the
1925 * generic reading code, so they would need to be first un-switched individually, and then
1926 * re-switched as a single 64-bit entity. */
1927 break;
1928 case IDP_INT:
1929 case IDP_FLOAT:
1930 case IDP_BOOLEAN:
1931 case IDP_ID:
1932 break; /* Nothing special to do here. */
1933 default:
1934 /* Unknown IDP type, nuke it (we cannot handle unknown types everywhere in code,
1935 * IDP are way too polymorphic to do it safely). */
1936 CLOG_WARN(&LOG,
1937 "Found unknown IDProperty type %d, reset to Integer one with null value",
1938 prop->type);
1939 /* NOTE: we do not attempt to free unknown prop, we have no way to know how to do that! */
1940 reset_property(prop);
1941 }
1942
1943 if (prop->ui_data != nullptr) {
1944 read_ui_data(prop, reader);
1945 }
1946}
1947
1948void IDP_BlendReadData_impl(BlendDataReader *reader, IDProperty **prop, const char *caller_func_id)
1949{
1950 if (*prop) {
1951 if ((*prop)->type == IDP_GROUP) {
1952 IDP_DirectLinkGroup(*prop, reader, 0);
1953 }
1954 else {
1955 /* corrupt file! */
1956 CLOG_WARN(&LOG, "%s: found non group data, freeing type %d!", caller_func_id, (*prop)->type);
1957 /* Don't risk it, data is likely corrupt. */
1958 // idp_free_property_content_recurse(*prop, true, 0);
1959 *prop = nullptr;
1960 }
1961 }
1962}
1963
1965{
1966 if (prop->type == IDP_STRING) {
1968 }
1969 if (prop->type == IDP_ID) {
1970 return IDP_UI_DATA_TYPE_ID;
1971 }
1972 if (prop->type == IDP_INT || (prop->type == IDP_ARRAY && prop->subtype == IDP_INT)) {
1973 return IDP_UI_DATA_TYPE_INT;
1974 }
1975 if (ELEM(prop->type, IDP_FLOAT, IDP_DOUBLE) ||
1976 (prop->type == IDP_ARRAY && ELEM(prop->subtype, IDP_FLOAT, IDP_DOUBLE)))
1977 {
1979 }
1980 if (prop->type == IDP_BOOLEAN || (prop->type == IDP_ARRAY && prop->subtype == IDP_BOOLEAN)) {
1982 }
1984}
1985
1987{
1989}
1990
1992{
1993 switch (type) {
1995 IDPropertyUIDataString *ui_data = MEM_new<IDPropertyUIDataString>(__func__);
1996 return &ui_data->base;
1997 }
1998 case IDP_UI_DATA_TYPE_ID: {
1999 IDPropertyUIDataID *ui_data = MEM_new<IDPropertyUIDataID>(__func__);
2000 return &ui_data->base;
2001 }
2002 case IDP_UI_DATA_TYPE_INT: {
2003 IDPropertyUIDataInt *ui_data = MEM_new<IDPropertyUIDataInt>(__func__);
2004 ui_data->min = INT_MIN;
2005 ui_data->max = INT_MAX;
2006 ui_data->soft_min = INT_MIN;
2007 ui_data->soft_max = INT_MAX;
2008 ui_data->step = 1;
2009 return &ui_data->base;
2010 }
2012 IDPropertyUIDataBool *ui_data = MEM_new<IDPropertyUIDataBool>(__func__);
2013 return &ui_data->base;
2014 }
2016 IDPropertyUIDataFloat *ui_data = MEM_new<IDPropertyUIDataFloat>(__func__);
2017 ui_data->min = -FLT_MAX;
2018 ui_data->max = FLT_MAX;
2019 ui_data->soft_min = -FLT_MAX;
2020 ui_data->soft_max = FLT_MAX;
2021 ui_data->step = 1.0f;
2022 ui_data->precision = 3;
2023 return &ui_data->base;
2024 }
2026 /* UI data not supported for remaining types, this shouldn't be called in those cases. */
2028 break;
2029 }
2030 }
2031 return nullptr;
2032}
2033
2035{
2036 if (prop->ui_data != nullptr) {
2037 return prop->ui_data;
2038 }
2039 prop->ui_data = ui_data_alloc(IDP_ui_data_type(prop));
2040 return prop->ui_data;
2041}
2042
2044 const eIDPropertyUIDataType dst_type)
2045{
2046 IDPropertyUIData *dst = ui_data_alloc(dst_type);
2047 *dst = *src;
2048 src->description = nullptr;
2049 return dst;
2050}
2051
2053 const eIDPropertyUIDataType src_type,
2054 const eIDPropertyUIDataType dst_type)
2055{
2056 switch (src_type) {
2058 switch (dst_type) {
2060 return src;
2064 case IDP_UI_DATA_TYPE_ID: {
2065 IDPropertyUIData *dst = convert_base_ui_data(src, dst_type);
2066 ui_data_free(src, src_type);
2067 return dst;
2068 }
2070 break;
2071 }
2072 break;
2073 }
2074 case IDP_UI_DATA_TYPE_ID: {
2075 switch (dst_type) {
2077 return src;
2082 IDPropertyUIData *dst = convert_base_ui_data(src, dst_type);
2083 ui_data_free(src, src_type);
2084 return dst;
2085 }
2087 break;
2088 }
2089 break;
2090 }
2091 case IDP_UI_DATA_TYPE_INT: {
2092 IDPropertyUIDataInt *src_int = reinterpret_cast<IDPropertyUIDataInt *>(src);
2093 switch (dst_type) {
2095 return src;
2098 IDPropertyUIData *dst = convert_base_ui_data(src, dst_type);
2099 ui_data_free(src, src_type);
2100 return dst;
2101 }
2103 IDPropertyUIDataBool *dst = reinterpret_cast<IDPropertyUIDataBool *>(
2104 convert_base_ui_data(src, dst_type));
2105 dst->default_value = src_int->default_value != 0;
2106 if (src_int->default_array) {
2108 size_t(src_int->default_array_len), __func__);
2109 for (int i = 0; i < src_int->default_array_len; i++) {
2110 dst->default_array[i] = src_int->default_array[i] != 0;
2111 }
2112 }
2113 ui_data_free(src, src_type);
2114 return &dst->base;
2115 }
2117 IDPropertyUIDataFloat *dst = reinterpret_cast<IDPropertyUIDataFloat *>(
2118 convert_base_ui_data(src, dst_type));
2119 dst->min = double(src_int->min);
2120 dst->max = double(src_int->max);
2121 dst->soft_min = double(src_int->soft_min);
2122 dst->soft_max = double(src_int->soft_max);
2123 dst->step = float(src_int->step);
2124 dst->default_value = double(src_int->default_value);
2125 if (src_int->default_array) {
2127 size_t(src_int->default_array_len), __func__);
2128 for (int i = 0; i < src_int->default_array_len; i++) {
2129 dst->default_array[i] = double(src_int->default_array[i]);
2130 }
2131 }
2132 ui_data_free(src, src_type);
2133 return &dst->base;
2134 }
2136 break;
2137 }
2138 break;
2139 }
2141 IDPropertyUIDataBool *src_bool = reinterpret_cast<IDPropertyUIDataBool *>(src);
2142 switch (dst_type) {
2144 return src;
2147 IDPropertyUIData *dst = convert_base_ui_data(src, dst_type);
2148 ui_data_free(src, src_type);
2149 return dst;
2150 }
2151 case IDP_UI_DATA_TYPE_INT: {
2152 IDPropertyUIDataInt *dst = reinterpret_cast<IDPropertyUIDataInt *>(
2153 convert_base_ui_data(src, dst_type));
2154 dst->min = 0;
2155 dst->max = 1;
2156 dst->soft_min = 0;
2157 dst->soft_max = 1;
2158 dst->step = 1;
2159 dst->default_value = int(src_bool->default_value);
2160 if (src_bool->default_array) {
2162 size_t(src_bool->default_array_len), __func__);
2163 for (int i = 0; i < src_bool->default_array_len; i++) {
2164 dst->default_array[i] = int(src_bool->default_array[i]);
2165 }
2166 }
2167 ui_data_free(src, src_type);
2168 return &dst->base;
2169 }
2171 IDPropertyUIDataFloat *dst = reinterpret_cast<IDPropertyUIDataFloat *>(
2172 convert_base_ui_data(src, dst_type));
2173 dst->min = 0.0;
2174 dst->max = 1.0;
2175 dst->soft_min = 0.0;
2176 dst->soft_max = 1.0;
2177 dst->step = 1.0;
2178 if (src_bool->default_array) {
2180 size_t(src_bool->default_array_len), __func__);
2181 for (int i = 0; i < src_bool->default_array_len; i++) {
2182 dst->default_array[i] = src_bool->default_array[i] == 0 ? 0.0 : 1.0;
2183 }
2184 }
2185 ui_data_free(src, src_type);
2186 return &dst->base;
2187 }
2189 break;
2190 }
2191 break;
2192 }
2194 IDPropertyUIDataFloat *src_float = reinterpret_cast<IDPropertyUIDataFloat *>(src);
2195 switch (dst_type) {
2197 return src;
2200 return convert_base_ui_data(src, dst_type);
2201 case IDP_UI_DATA_TYPE_INT: {
2202 auto clamp_double_to_int = [](const double value) {
2203 return int(std::clamp<double>(value, INT_MIN, INT_MAX));
2204 };
2205 IDPropertyUIDataInt *dst = reinterpret_cast<IDPropertyUIDataInt *>(
2206 convert_base_ui_data(src, dst_type));
2207 dst->min = clamp_double_to_int(src_float->min);
2208 dst->max = clamp_double_to_int(src_float->max);
2209 dst->soft_min = clamp_double_to_int(src_float->soft_min);
2210 dst->soft_max = clamp_double_to_int(src_float->soft_max);
2211 dst->step = clamp_double_to_int(src_float->step);
2212 dst->default_value = clamp_double_to_int(src_float->default_value);
2213 if (src_float->default_array) {
2215 size_t(src_float->default_array_len), __func__);
2216 for (int i = 0; i < src_float->default_array_len; i++) {
2217 dst->default_array[i] = clamp_double_to_int(src_float->default_array[i]);
2218 }
2219 }
2220 ui_data_free(src, src_type);
2221 return &dst->base;
2222 }
2224 IDPropertyUIDataBool *dst = reinterpret_cast<IDPropertyUIDataBool *>(
2225 convert_base_ui_data(src, dst_type));
2226 dst->default_value = src_float->default_value > 0.0f;
2227 if (src_float->default_array) {
2229 size_t(src_float->default_array_len), __func__);
2230 for (int i = 0; i < src_float->default_array_len; i++) {
2231 dst->default_array[i] = src_float->default_array[i] > 0.0f;
2232 }
2233 }
2234 ui_data_free(src, src_type);
2235 return &dst->base;
2236 }
2238 break;
2239 }
2240 break;
2241 }
2243 break;
2244 }
2245 ui_data_free(src, src_type);
2246 return nullptr;
2247}
2248
2249namespace bke::idprop {
2250
2251void hash(const IDProperty &base_prop, XXH3_state_t *hash_state)
2252{
2253 IDP_foreach_property(&const_cast<IDProperty &>(base_prop), 0, [&](const IDProperty *prop) {
2254 XXH3_64bits_update(hash_state, prop->name, strlen(prop->name));
2255 XXH3_64bits_update(hash_state, &prop->type, sizeof(prop->type));
2256
2257 switch (eIDPropertyType(prop->type)) {
2258 case IDP_INT:
2259 case IDP_FLOAT:
2260 case IDP_BOOLEAN: {
2261 XXH3_64bits_update(hash_state, &prop->data.val, sizeof(prop->data.val));
2262 break;
2263 }
2264 case IDP_DOUBLE: {
2265 const double val = IDP_double_get(prop);
2266 XXH3_64bits_update(hash_state, &val, sizeof(double));
2267 break;
2268 }
2269 case IDP_STRING: {
2270 if (prop->data.pointer) {
2271 XXH3_64bits_update(hash_state, prop->data.pointer, size_t(prop->len));
2272 }
2273 break;
2274 }
2275 case IDP_ARRAY: {
2276 if (prop->data.pointer) {
2277 XXH3_64bits_update(hash_state, &prop->subtype, sizeof(prop->subtype));
2278 const size_t elem_size = idp_size_table[int(prop->subtype)];
2279 XXH3_64bits_update(hash_state, prop->data.pointer, elem_size * size_t(prop->len));
2280 }
2281 break;
2282 }
2283 case IDP_ID: {
2284 /* NOTE: Hashing the session_uid of the ID makes the hash session-specific. An alternative
2285 * hash wouldn't be complete though, because data-block names aren't necessarily unique. */
2286 if (const ID *id = static_cast<const ID *>(prop->data.pointer)) {
2287 XXH3_64bits_update(hash_state, &id->session_uid, sizeof(ID::session_uid));
2288 }
2289 break;
2290 }
2291 case IDP_GROUP:
2292 case IDP_IDPARRAY: {
2293 /* Handled by the recursion in #IDP_foreach_property. */
2294 break;
2295 }
2296 }
2297 });
2298}
2299
2300} // namespace bke::idprop
2301
2303
2304/* -------------------------------------------------------------------- */
2307
2308#ifndef NDEBUG
2309const IDProperty *_IDP_assert_type(const IDProperty *prop, const char ty)
2310{
2311 BLI_assert(prop->type == ty);
2312 return prop;
2313}
2315 const char ty,
2316 const char sub_ty)
2317{
2318 BLI_assert((prop->type == ty) && (prop->subtype == sub_ty));
2319 return prop;
2320}
2321
2322const IDProperty *_IDP_assert_type_mask(const IDProperty *prop, const int ty_mask)
2323{
2324 BLI_assert(1 << int(prop->type) & ty_mask);
2325 return prop;
2326}
2327#endif /* !NDEBUG */
2328
2330
2331} // namespace blender
#define IDP_ID_get(prop)
#define IDP_float_get(prop)
#define IDP_array_voidp_get(prop)
#define IDP_int_get(prop)
#define IDP_int_set(prop, value)
#define IDP_string_get(prop)
#define IDP_double_get(prop)
#define IDP_property_array_get(prop)
#define IDP_array_float_get(prop)
#define IDP_bool_get(prop)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define DEFAULT_ALLOC_FOR_NULL_STRINGS
Definition DNA_ID.h:175
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define STREQLEN(a, b, n)
#define ELEM(...)
#define MEM_realloc_zeroed(vmemh, len)
constexpr IndexRange()=default
void reserve(const int64_t n)
Definition BLI_set.hh:656
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr Span()=default
constexpr int64_t size() const
constexpr const char * data() const
void copy_utf8_truncated(char *dst, int64_t dst_size) const
Definition string_ref.cc:28
#define FLT_MAX
#define INT_MAX
#define IDP_ARRAY_REALLOC_LIMIT
Definition idprop.cc:47
#define GETPROP(prop, i)
Definition idprop.cc:102
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
void hash(const IDProperty &base_prop, XXH3_state_t *hash_state)
Definition idprop.cc:2251
BMesh Iterators.
static IDPropertyUIData * convert_base_ui_data(IDPropertyUIData *src, const eIDPropertyUIDataType dst_type)
Definition idprop.cc:2043
static void idp_group_children_map_ensure(IDProperty &prop)
Definition idprop.cc:180
bool IDP_EnumItemsValidate(const IDPropertyUIDataEnumItem *items, int items_num, void(*error_fn)(const char *))
Definition idprop.cc:558
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void IDP_FreeFromGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:812
float IDP_coerce_to_float_or_zero(const IDProperty *prop)
Definition idprop.cc:952
void IDP_print(const IDProperty *prop)
static IDProperty * IDP_CopyGroup(const IDProperty *prop, const int flag)
Definition idprop.cc:642
__int64 int64_t
Definition BKE_text.h:90
void IDP_FreeProperty_ex(IDProperty *prop, bool do_id_user)
Definition idprop.cc:1398
void IDP_ReplaceGroupInGroup(IDProperty *dest, const IDProperty *src) ATTR_NONNULL()
Definition idprop.cc:705
char * STRNCPY(char(&dst)[N], const char *src)
void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:737
IDProperty * IDP_GetPropertyTypeFromGroup(const IDProperty *prop, StringRef name, char type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:839
unsigned int uint
Definition BKE_text.h:55
static void IDP_WriteIDPArray(const IDProperty *prop, BlendWriter *writer, const int recursion_depth)
Definition idprop.cc:1579
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BLO_read_pointer_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size)
static void idp_resize_group_array(IDProperty *prop, int newlen, void *newarr, const bool do_id_users, const int recursion_depth)
Definition idprop.cc:239
void id_us_plus(ID *id)
Definition lib_id.cc:433
void BLI_insertlinkreplace(ListBase *listbase, void *vreplacelink, void *vnewlink) ATTR_NONNULL(1
Definition listbase.cc:417
static void IDP_int_ui_data_free_enum_items(IDPropertyUIDataInt *ui_data)
Definition idprop.cc:537
IDProperty * IDP_ID_system_properties_ensure(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:1023
static IDProperty * idp_generic_copy(const IDProperty *prop, const int)
Definition idprop.cc:353
static void IDP_DirectLinkIDPArray(IDProperty *prop, BlendDataReader *reader, const int recursion_depth)
Definition idprop.cc:1785
static void IDP_DirectLinkString(IDProperty *prop, BlendDataReader *reader)
Definition idprop.cc:1854
double IDP_coerce_to_double_or_zero(const IDProperty *prop)
Definition idprop.cc:936
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:788
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:986
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:818
void IDP_BlendWrite(BlendWriter *writer, const IDProperty *prop)
Definition idprop.cc:1696
void IDP_foreach_property(IDProperty *id_property_root, int type_filter, FunctionRef< void(IDProperty *id_property)> callback)
void IDP_FreeString(IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:512
constexpr int MAX_IDPROP_DEPTH_LEVEL
Definition idprop.cc:73
int IDP_coerce_to_int_or_zero(const IDProperty *prop)
Definition idprop.cc:920
static void ui_data_free(IDPropertyUIData *ui_data, const eIDPropertyUIDataType type)
Definition idprop.cc:1303
static void write_ui_data(const IDProperty *prop, BlendWriter *writer)
Definition idprop.cc:1483
const IDProperty * _IDP_assert_type_mask(const IDProperty *prop, int ty_mask)
Definition idprop.cc:2322
std::optional< int > IDP_group_lookup_int(const IDProperty &group, StringRef name)
Definition idprop.cc:880
static void IDP_WriteProperty_OnlyData(const IDProperty *prop, BlendWriter *writer, const int recursion_depth)
Definition idprop.cc:1640
static void IDP_FreeIDPArray(IDProperty *prop, const bool do_id_user, const int recursion_depth)
Definition idprop.cc:137
std::optional< float > IDP_group_lookup_float(const IDProperty &group, StringRef name)
Definition idprop.cc:871
eIDPropertyUIDataType IDP_ui_data_type(const IDProperty *prop)
Definition idprop.cc:1964
IDProperty * IDP_NewString(const char *st, StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:443
std::optional< StringRefNull > IDP_group_lookup_string(const IDProperty &group, StringRef name)
Definition idprop.cc:862
void IDP_AssignID(IDProperty *prop, ID *id, int flag)
Definition idprop.cc:616
IDProperty * IDP_ID_system_properties_get(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:1018
void MEM_delete_void(void *vmemh)
void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, bool do_overwrite) ATTR_NONNULL()
Definition idprop.cc:783
@ LIB_ID_CREATE_NO_USER_REFCOUNT
void IDP_ReplaceInGroup_ex(IDProperty *group, IDProperty *prop, IDProperty *prop_exist, int flag)
Definition idprop.cc:716
std::optional< bool > IDP_group_lookup_bool(const IDProperty &group, StringRef name)
Definition idprop.cc:889
void IDP_CopyPropertyContent(IDProperty *dst, const IDProperty *src) ATTR_NONNULL()
Definition idprop.cc:991
unsigned int uint32_t
Definition BKE_text.h:81
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
static void IDP_FreeArray(IDProperty *prop, const bool do_id_user, const int recursion_depth)
Definition idprop.cc:290
void IDP_ResizeIDPArray(IDProperty *prop, int newlen)
Definition idprop.cc:203
void * MEM_dupalloc_void(const void *vmemh) ATTR_WARN_UNUSED_RESULT
void IDP_ClearProperty(IDProperty *prop)
Definition idprop.cc:1408
IDPropertyUIData * IDP_TryConvertUIData(IDPropertyUIData *src, eIDPropertyUIDataType src_type, eIDPropertyUIDataType dst_type)
Definition idprop.cc:2052
static IDProperty * IDP_CopyString(const IDProperty *prop, const int flag)
Definition idprop.cc:455
void IDP_RemoveFromGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:801
static void idp_foreach_property_recurse(IDProperty *id_property_root, const int type_filter, const int recursion_depth, const FunctionRef< void(IDProperty *id_property)> callback)
Definition idprop.cc:1426
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
static void IDP_WriteGroup(const IDProperty *prop, BlendWriter *writer, const int recursion_depth)
Definition idprop.cc:1632
void IDP_ui_data_free(IDProperty *prop)
Definition idprop.cc:1340
IDProperty * IDP_GetProperties(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:1000
void IDP_SetIndexArray(IDProperty *prop, int index, IDProperty *item) ATTR_NONNULL()
Definition idprop.cc:149
void IDP_AssignString(IDProperty *prop, const char *st) ATTR_NONNULL()
Definition idprop.cc:505
int char char int int int int size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
const IDProperty * _IDP_assert_type(const IDProperty *prop, char ty)
Definition idprop.cc:2309
static void read_ui_data(IDProperty *prop, BlendDataReader *reader)
Definition idprop.cc:1705
@ IDP_STRING_SUB_UTF8
@ IDP_STRING_SUB_BYTE
void IDP_ResizeArray(IDProperty *prop, int newlen)
Definition idprop.cc:263
IDProperty * IDP_GetIndexArray(IDProperty *prop, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:165
void IDP_SyncGroupValues(IDProperty *dest, const IDProperty *src) ATTR_NONNULL()
Definition idprop.cc:655
static void IDP_WriteArray(const IDProperty *prop, BlendWriter *writer, const int recursion_depth)
Definition idprop.cc:1541
static void idp_free_property_recurse(IDProperty *prop, const bool do_id_user, const int recursion_depth)
Definition idprop.cc:1390
static IDPropertyUIData * ui_data_alloc(const eIDPropertyUIDataType type)
Definition idprop.cc:1991
void IDP_BlendReadData_impl(BlendDataReader *reader, IDProperty **prop, const char *caller_func_id)
Definition idprop.cc:1948
void BLO_read_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size, const int elems=1)
static IDProperty * IDP_CopyID(const IDProperty *prop, const int flag)
Definition idprop.cc:603
void IDP_AppendArray(IDProperty *prop, IDProperty *item)
Definition idprop.cc:172
void IDP_SyncGroupTypes(IDProperty *dest, const IDProperty *src, bool do_arraylen) ATTR_NONNULL()
Definition idprop.cc:682
static void IDP_DirectLinkGroup(IDProperty *prop, BlendDataReader *reader, const int recursion_depth)
Definition idprop.cc:1862
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
static size_t idp_size_table[]
Definition idprop.cc:52
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1403
void IDP_ui_data_free_unique_contents(IDPropertyUIData *ui_data, eIDPropertyUIDataType type, const IDPropertyUIData *other)
Definition idprop.cc:1247
static void idp_blend_write_recurse(BlendWriter *writer, const IDProperty *prop, const int recursion_depth)
Definition idprop.cc:1669
MINLINE float max_ff(float a, float b)
IDProperty * IDP_NewInt(int value, blender::StringRef name, eIDPropertyFlag flags={})
Definition idprop.cc:1240
IDProperty * IDP_CopyIDPArray(const IDProperty *array, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:114
void IDP_MergeGroup_ex(IDProperty *dest, const IDProperty *src, bool do_overwrite, int flag) ATTR_NONNULL()
Definition idprop.cc:744
signed int int32_t
Definition BKE_text.h:78
std::optional< Span< float > > IDP_group_lookup_float_array(const IDProperty &group, StringRef name, int required_size)
Definition idprop.cc:898
IDProperty * IDP_EnsureProperties(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:1005
static CLG_LogRef LOG
Definition logging.cpp:12
static IDProperty * IDP_CopyArray(const IDProperty *prop, const int flag)
Definition idprop.cc:370
const IDPropertyUIDataEnumItem * IDP_EnumItemFind(const IDProperty *prop)
Definition idprop.cc:543
IDProperty * IDP_New(char type, const IDPropertyTemplate *val, StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:1132
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
@ ID_FLAG_EMBEDDED_DATA
Definition DNA_ID.h:775
IDProperty * IDP_NewStringMaxSize(const char *st, size_t st_maxncpy, StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:400
void IDP_EnumItemsFree(IDPropertyUIDataEnumItem *items, int items_num)
Definition idprop.cc:526
constexpr int MAX_IDPROP_DEPTH_LEVEL_FOR_WRITE
Definition idprop.cc:81
IDPropertyUIData * IDP_ui_data_copy(const IDProperty *prop)
Definition idprop.cc:298
IDProperty * IDP_CopyProperty_ex(const IDProperty *prop, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:968
IDPropertyUIData * IDP_ui_data_ensure(IDProperty *prop)
Definition idprop.cc:2034
static int idp_resize_grow_size_calc(const int newsize)
Definition idprop.cc:188
static void idp_free_property_content_recurse(IDProperty *prop, const bool do_id_user, const int recursion_depth)
Definition idprop.cc:1346
void id_us_min(ID *id)
Definition lib_id.cc:441
IDProperty * IDP_GetPropertyFromGroup_null(const IDProperty *prop, StringRef name) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:831
eIDPropertyUIDataType
@ IDP_UI_DATA_TYPE_ID
@ IDP_UI_DATA_TYPE_STRING
@ IDP_UI_DATA_TYPE_FLOAT
@ IDP_UI_DATA_TYPE_INT
@ IDP_UI_DATA_TYPE_UNSUPPORTED
@ IDP_UI_DATA_TYPE_BOOLEAN
constexpr int MAX_IDPROP_DEPTH_LEVEL_FOR_READ
Definition idprop.cc:89
static void IDP_DirectLinkProperty(IDProperty *prop, BlendDataReader *reader, const int recursion_depth)
Definition idprop.cc:1884
bool IDP_ui_data_supported(const IDProperty *prop)
Definition idprop.cc:1986
bool IDP_EqualsProperties(const IDProperty *prop1, const IDProperty *prop2) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:1127
void IDP_Reset(IDProperty *prop, const IDProperty *reference)
Definition idprop.cc:1415
static void IDP_WriteString(const IDProperty *prop, BlendWriter *writer)
Definition idprop.cc:1624
IDProperty * IDP_NewIDPArray(StringRef name) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:104
static void IDP_FreeGroup(IDProperty *prop, const bool do_id_user, const int recursion_depth)
Definition idprop.cc:851
static void IDP_DirectLinkArray(IDProperty *prop, BlendDataReader *reader, const int recursion_depth)
Definition idprop.cc:1808
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
Definition readfile.cc:6653
signed char int8_t
Definition BKE_text.h:76
void IDP_AssignStringMaxSize(IDProperty *prop, const char *st, size_t st_maxncpy) ATTR_NONNULL()
Definition idprop.cc:470
size_t BLI_strnlen_utf8_ex(const char *strc, size_t strc_maxlen, size_t *r_len_bytes) ATTR_NONNULL(1
const IDProperty * _IDP_assert_type_and_subtype(const IDProperty *prop, char ty, char sub_ty)
Definition idprop.cc:2314
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bool IDP_EqualsProperties_ex(const IDProperty *prop1, const IDProperty *prop2, bool is_strict) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:1036
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
void write_pointer_array(int64_t num, const void *data)
void write_string(const char *data)
void write_int8_array(int64_t num, const int8_t *data)
void write_float_array(int64_t num, const float *data)
void write_struct_at_address(const void *address, const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_char_array(int64_t num, const char *data)
void write_struct_cast(const void *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_double_array(int64_t num, const double *data)
void write_struct_array_at_address(const int64_t array_size, const void *address, const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct_array(const int64_t array_size, const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_int32_array(int64_t num, const int32_t *data)
bke::idprop::IDPropertyGroupChildrenSet * children_map
Definition DNA_ID.h:138
ListBaseT< struct IDProperty > group
Definition DNA_ID.h:133
IDPropertyUIData base
Definition DNA_ID.h:86
IDPropertyUIData base
Definition DNA_ID.h:96
IDPropertyUIData base
Definition DNA_ID.h:119
IDPropertyUIData base
Definition DNA_ID.h:69
IDPropertyUIDataEnumItem * enum_items
Definition DNA_ID.h:81
eIDPropertyFlag flag
Definition DNA_ID.h:151
IDPropertyUIData * ui_data
Definition DNA_ID.h:171
eIDPropertyType type
Definition DNA_ID.h:145
struct IDProperty * prev
Definition DNA_ID.h:144
struct IDProperty * next
Definition DNA_ID.h:144
IDPropertyData data
Definition DNA_ID.h:157
unsigned int session_uid
Definition DNA_ID.h:463
CustomIDVectorSet< IDProperty *, IDPropNameGetter, 8 > children
struct blender::IDPropertyTemplate::@100215251242210352227251277016155305041022127377 array
struct blender::IDPropertyTemplate::@116303142222164257205355242364302075230051143265 string