Blender V5.0
BKE_idprop.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#include <memory>
12
13#include "DNA_ID.h"
14#include "DNA_ID_enums.h"
15
16#include "BLI_compiler_attrs.h"
17#include "BLI_function_ref.hh"
18#include "BLI_span.hh"
19#include "BLI_string_ref.hh"
20#include "BLI_sys_types.h"
21#include "BLI_vector_set.hh"
22
23struct BlendDataReader;
24struct BlendWriter;
25struct ID;
26struct IDProperty;
27struct IDPropertyUIData;
30class ArrayValue;
31class Value;
32} // namespace blender::io::serialize
33
35 int i;
36 float f;
37 double d;
38 struct {
39 const char *str;
41 int len;
43 char subtype;
46 struct {
47 int len;
49 char type;
51};
52
53/* ----------- Property Array Type ---------- */
54
66
70void IDP_SetIndexArray(IDProperty *prop, int index, IDProperty *item) ATTR_NONNULL();
72void IDP_AppendArray(IDProperty *prop, IDProperty *item);
73void IDP_ResizeIDPArray(IDProperty *prop, int newlen);
74
75/* ----------- Numeric Array Type ----------- */
76
80void IDP_ResizeArray(IDProperty *prop, int newlen);
81void IDP_FreeArray(IDProperty *prop);
82
83/* ---------- String Type ------------ */
92IDProperty *IDP_NewStringMaxSize(const char *st,
93 size_t st_maxncpy,
96IDProperty *IDP_NewString(const char *st,
105void IDP_AssignStringMaxSize(IDProperty *prop, const char *st, size_t st_maxncpy) ATTR_NONNULL();
106void IDP_AssignString(IDProperty *prop, const char *st) ATTR_NONNULL();
108
109/*-------- Enum Type -------*/
110
112
114 int items_num,
115 void (*error_fn)(const char *));
116
117/*-------- ID Type -------*/
118
119using IDPWalkFunc = void (*)(void *user_data, IDProperty *idp);
120
125void IDP_AssignID(IDProperty *prop, ID *id, int flag);
126
127/*-------- Group Functions -------*/
128
135void IDP_SyncGroupValues(IDProperty *dest, const IDProperty *src) ATTR_NONNULL();
136void IDP_SyncGroupTypes(IDProperty *dest, const IDProperty *src, bool do_arraylen) ATTR_NONNULL();
149void IDP_ReplaceInGroup_ex(IDProperty *group, IDProperty *prop, IDProperty *prop_exist, int flag);
154void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, bool do_overwrite) ATTR_NONNULL();
162void IDP_MergeGroup_ex(IDProperty *dest, const IDProperty *src, bool do_overwrite, int flag)
163 ATTR_NONNULL();
186
189 ATTR_NONNULL();
193
200
201/*-------- Main Functions --------*/
220
227 ATTR_NONNULL();
233
237bool IDP_EqualsProperties_ex(const IDProperty *prop1,
238 const IDProperty *prop2,
239 bool is_strict) ATTR_WARN_UNUSED_RESULT;
240
241bool IDP_EqualsProperties(const IDProperty *prop1,
243
271IDProperty *IDP_New(char type,
272 const IDPropertyTemplate *val,
275
280void IDP_FreePropertyContent_ex(IDProperty *prop, bool do_id_user);
282void IDP_FreeProperty_ex(IDProperty *prop, bool do_id_user);
283void IDP_FreeProperty(IDProperty *prop);
284
285void IDP_ClearProperty(IDProperty *prop);
286
287void IDP_Reset(IDProperty *prop, const IDProperty *reference);
288
289#ifndef NDEBUG
290const IDProperty *_IDP_assert_type(const IDProperty *prop, char ty);
291const IDProperty *_IDP_assert_type_and_subtype(const IDProperty *prop, char ty, char sub_ty);
292const IDProperty *_IDP_assert_type_mask(const IDProperty *prop, int ty_mask);
293
294#else
295# define _IDP_assert_type(prop, ty) (prop)
296# define _IDP_assert_type_and_subtype(prop, ty, sub_ty) (prop)
297# define _IDP_assert_type_mask(prop, ty_mask) (prop)
298#endif
299
300#define IDP_int_get(prop) (_IDP_assert_type(prop, IDP_INT)->data.val)
301#define IDP_int_set(prop, value) \
302 { \
303 IDProperty *prop_ = (prop); \
304 BLI_assert(prop_->type == IDP_INT); \
305 prop_->data.val = value; \
306 } \
307 ((void)0)
308
309#define IDP_bool_get(prop) ((_IDP_assert_type(prop, IDP_BOOLEAN))->data.val)
310#define IDP_bool_set(prop, value) \
311 { \
312 IDProperty *prop_ = (prop); \
313 BLI_assert(prop_->type == IDP_BOOLEAN); \
314 prop_->data.val = value; \
315 } \
316 ((void)0)
317
318#define IDP_int_or_bool_get(prop) \
319 (_IDP_assert_type_mask(prop, (1 << IDP_INT) | (1 << IDP_BOOLEAN))->data.val)
320#define IDP_int_or_bool_set(prop, value) \
321 { \
322 IDProperty *prop_ = (prop); \
323 BLI_assert(ELEM(prop_->type, IDP_INT, IDP_BOOLEAN)); \
324 prop_->data.val = value; \
325 } \
326 ((void)0)
327
328#define IDP_float_get(prop) (*(const float *)&(_IDP_assert_type(prop, IDP_FLOAT)->data.val))
329#define IDP_float_set(prop, value) \
330 { \
331 IDProperty *prop_ = (prop); \
332 BLI_assert(prop_->type == IDP_FLOAT); \
333 (*(float *)&(prop_)->data.val) = value; \
334 } \
335 ((void)0)
336
337#define IDP_double_get(prop) (*(const double *)&(_IDP_assert_type(prop, IDP_DOUBLE)->data.val))
338#define IDP_double_set(prop, value) \
339 { \
340 IDProperty *prop_ = (prop); \
341 BLI_assert(prop_->type == IDP_DOUBLE); \
342 (*(double *)&(prop_)->data.val) = value; \
343 } \
344 ((void)0)
345
351#define IDP_array_voidp_get(prop) (_IDP_assert_type(prop, IDP_ARRAY)->data.pointer)
352
353#define IDP_array_int_get(prop) \
354 static_cast<int *>(_IDP_assert_type_and_subtype(prop, IDP_ARRAY, IDP_INT)->data.pointer)
355#define IDP_array_bool_get(prop) \
356 static_cast<int8_t *>(_IDP_assert_type_and_subtype(prop, IDP_ARRAY, IDP_BOOLEAN)->data.pointer)
357#define IDP_array_float_get(prop) \
358 static_cast<float *>(_IDP_assert_type_and_subtype(prop, IDP_ARRAY, IDP_FLOAT)->data.pointer)
359#define IDP_array_double_get(prop) \
360 static_cast<double *>(_IDP_assert_type_and_subtype(prop, IDP_ARRAY, IDP_DOUBLE)->data.pointer)
361#define IDP_property_array_get(prop) \
362 static_cast<IDProperty *>(_IDP_assert_type(prop, IDP_IDPARRAY)->data.pointer)
363
364#define IDP_string_get(prop) ((char *)_IDP_assert_type(prop, IDP_STRING)->data.pointer)
365/* No `IDP_string_set` needed. */
366#define IDP_ID_get(prop) ((void)0, ((ID *)_IDP_assert_type(prop, IDP_ID)->data.pointer))
367/* No `IDP_ID_set` needed. */
368
378float IDP_coerce_to_float_or_zero(const IDProperty *prop);
383double IDP_coerce_to_double_or_zero(const IDProperty *prop);
384
393void IDP_foreach_property(IDProperty *id_property_root,
394 int type_filter,
395 blender::FunctionRef<void(IDProperty *id_property)> callback);
396
397/* Format IDProperty as strings */
398char *IDP_reprN(const IDProperty *prop, uint *r_len);
399void IDP_repr_fn(const IDProperty *prop,
400 void (*str_append_fn)(void *user_data, const char *str, uint str_len),
401 void *user_data);
402void IDP_print(const IDProperty *prop);
403
404const char *IDP_type_str(eIDPropertyType type, short sub_type);
405const char *IDP_type_str(const IDProperty *prop);
406
407void IDP_BlendWrite(BlendWriter *writer, const IDProperty *prop);
409 IDProperty **prop,
410 const char *caller_func_id);
411#define IDP_BlendDataRead(reader, prop) IDP_BlendReadData_impl(reader, prop, __func__)
412
427
428bool IDP_ui_data_supported(const IDProperty *prop);
430void IDP_ui_data_free(IDProperty *prop);
438 const IDPropertyUIData *other);
446 eIDPropertyUIDataType src_type,
447 eIDPropertyUIDataType dst_type);
448
450
458std::unique_ptr<blender::io::serialize::ArrayValue> convert_to_serialize_values(
459 const IDProperty *properties);
460
465
467 public:
468 void operator()(IDProperty *id_prop)
469 {
470 IDP_FreeProperty(id_prop);
471 }
472};
473
484
486std::unique_ptr<IDProperty, IDPropertyDeleter> create_bool(StringRef prop_name,
487 bool value,
488 eIDPropertyFlag flags = {});
489
491std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
492 int32_t value,
493 eIDPropertyFlag flags = {});
494
496std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
497 float value,
498 eIDPropertyFlag flags = {});
499
501std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
502 double value,
503 eIDPropertyFlag flags = {});
504
506std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
507 StringRefNull value,
508 eIDPropertyFlag flags = {});
509
511std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
512 ID *value,
513 eIDPropertyFlag flags = {});
514
520std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
521 Span<int32_t> values,
522 eIDPropertyFlag flags = {});
523
529std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
530 Span<float> values,
531 eIDPropertyFlag flags = {});
532
538std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
539 Span<double> values,
540 eIDPropertyFlag flags = {});
541
547
548std::unique_ptr<IDProperty, IDPropertyDeleter> create_group(StringRef prop_name,
549 eIDPropertyFlag flags = {});
550
551} // namespace blender::bke::idprop
void IDP_Reset(IDProperty *prop, const IDProperty *reference)
Definition idprop.cc:1264
void IDP_ui_data_free(IDProperty *prop)
Definition idprop.cc:1207
IDPropertyUIData * IDP_TryConvertUIData(IDPropertyUIData *src, eIDPropertyUIDataType src_type, eIDPropertyUIDataType dst_type)
Definition idprop.cc:1779
IDProperty * IDP_ID_system_properties_ensure(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:900
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, blender::StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:747
IDProperty * IDP_NewString(const char *st, blender::StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:399
bool IDP_EnumItemsValidate(const IDPropertyUIDataEnumItem *items, int items_num, void(*error_fn)(const char *))
Definition idprop.cc:488
void IDP_FreeFromGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:741
void IDP_CopyPropertyContent(IDProperty *dst, const IDProperty *src) ATTR_NONNULL()
Definition idprop.cc:868
float IDP_coerce_to_float_or_zero(const IDProperty *prop)
Definition idprop.cc:829
IDProperty * IDP_ID_system_properties_get(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:895
eIDPropertyUIDataType IDP_ui_data_type(const IDProperty *prop)
Definition idprop.cc:1691
bool IDP_ui_data_supported(const IDProperty *prop)
Definition idprop.cc:1713
void IDP_AssignString(IDProperty *prop, const char *st) ATTR_NONNULL()
Definition idprop.cc:439
void IDP_foreach_property(IDProperty *id_property_root, int type_filter, blender::FunctionRef< void(IDProperty *id_property)> callback)
IDPropertyUIData * IDP_ui_data_copy(const IDProperty *prop)
Definition idprop.cc:265
void IDP_MergeGroup_ex(IDProperty *dest, const IDProperty *src, bool do_overwrite, int flag) ATTR_NONNULL()
Definition idprop.cc:673
const IDProperty * _IDP_assert_type(const IDProperty *prop, char ty)
Definition idprop.cc:1983
IDProperty * IDP_GetPropertyTypeFromGroup(const IDProperty *prop, blender::StringRef name, char type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:768
void IDP_AssignStringMaxSize(IDProperty *prop, const char *st, size_t st_maxncpy) ATTR_NONNULL()
Definition idprop.cc:421
char * IDP_reprN(const IDProperty *prop, uint *r_len)
const char * IDP_type_str(eIDPropertyType type, short sub_type)
void IDP_ReplaceInGroup_ex(IDProperty *group, IDProperty *prop, IDProperty *prop_exist, int flag)
Definition idprop.cc:645
eIDPropertyUIDataType
@ IDP_UI_DATA_TYPE_ID
@ IDP_UI_DATA_TYPE_BOOLEAN
@ IDP_UI_DATA_TYPE_UNSUPPORTED
@ IDP_UI_DATA_TYPE_INT
@ IDP_UI_DATA_TYPE_FLOAT
@ IDP_UI_DATA_TYPE_STRING
IDProperty * IDP_GetIndexArray(IDProperty *prop, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:130
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1251
IDProperty * IDP_GetPropertyFromGroup_null(const IDProperty *prop, blender::StringRef name) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:760
int IDP_coerce_to_int_or_zero(const IDProperty *prop)
Definition idprop.cc:797
IDProperty * IDP_New(char type, const IDPropertyTemplate *val, blender::StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:1009
IDProperty * IDP_CopyIDPArray(const IDProperty *array, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:77
void IDP_FreePropertyContent(IDProperty *prop)
Definition idprop.cc:1240
const IDProperty * _IDP_assert_type_mask(const IDProperty *prop, int ty_mask)
Definition idprop.cc:1996
const IDProperty * _IDP_assert_type_and_subtype(const IDProperty *prop, char ty, char sub_ty)
Definition idprop.cc:1988
void IDP_FreePropertyContent_ex(IDProperty *prop, bool do_id_user)
Definition idprop.cc:1213
void IDP_ClearProperty(IDProperty *prop)
Definition idprop.cc:1257
double IDP_coerce_to_double_or_zero(const IDProperty *prop)
Definition idprop.cc:813
void IDP_SetIndexArray(IDProperty *prop, int index, IDProperty *item) ATTR_NONNULL()
Definition idprop.cc:114
void IDP_ResizeIDPArray(IDProperty *prop, int newlen)
Definition idprop.cc:153
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:717
IDProperty * IDP_CopyProperty_ex(const IDProperty *prop, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:845
bool IDP_EqualsProperties_ex(const IDProperty *prop1, const IDProperty *prop2, bool is_strict) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:913
void IDP_AppendArray(IDProperty *prop, IDProperty *item)
Definition idprop.cc:137
void IDP_RemoveFromGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:730
IDProperty * IDP_EnsureProperties(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:882
void IDP_AssignID(IDProperty *prop, ID *id, int flag)
Definition idprop.cc:546
IDProperty * IDP_GetProperties(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:877
void IDP_ResizeArray(IDProperty *prop, int newlen)
Definition idprop.cc:220
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:863
void IDP_print(const IDProperty *prop)
void IDP_repr_fn(const IDProperty *prop, void(*str_append_fn)(void *user_data, const char *str, uint str_len), void *user_data)
void IDP_ui_data_free_unique_contents(IDPropertyUIData *ui_data, eIDPropertyUIDataType type, const IDPropertyUIData *other)
Definition idprop.cc:1117
void IDP_ReplaceGroupInGroup(IDProperty *dest, const IDProperty *src) ATTR_NONNULL()
Definition idprop.cc:634
void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, bool do_overwrite) ATTR_NONNULL()
Definition idprop.cc:712
IDProperty * IDP_NewStringMaxSize(const char *st, size_t st_maxncpy, blender::StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:363
void IDP_FreeString(IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:446
void IDP_BlendWrite(BlendWriter *writer, const IDProperty *prop)
Definition idprop.cc:1461
void IDP_SyncGroupValues(IDProperty *dest, const IDProperty *src) ATTR_NONNULL()
Definition idprop.cc:585
void IDP_FreeProperty_ex(IDProperty *prop, bool do_id_user)
Definition idprop.cc:1245
IDPropertyUIData * IDP_ui_data_ensure(IDProperty *prop)
Definition idprop.cc:1761
bool IDP_EqualsProperties(const IDProperty *prop1, const IDProperty *prop2) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:1004
void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:666
void IDP_FreeArray(IDProperty *prop)
Definition idprop.cc:257
void(*)(void *user_data, IDProperty *idp) IDPWalkFunc
void IDP_BlendReadData_impl(BlendDataReader *reader, IDProperty **prop, const char *caller_func_id)
Definition idprop.cc:1675
IDProperty * IDP_NewIDPArray(blender::StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:67
const IDPropertyUIDataEnumItem * IDP_EnumItemFind(const IDProperty *prop)
Definition idprop.cc:471
void IDP_SyncGroupTypes(IDProperty *dest, const IDProperty *src, bool do_arraylen) ATTR_NONNULL()
Definition idprop.cc:612
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_NONNULL(...)
unsigned int uint
ID and Library types, which are fundamental for SDNA.
struct ID ID
Enumerations for DNA_ID.h.
eIDPropertyType
eIDPropertyFlag
void operator()(IDProperty *id_prop)
#define str(s)
std::unique_ptr< IDProperty, IDPropertyDeleter > create_bool(StringRef prop_name, bool value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_BOOLEAN, set its name and value.
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRef prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
std::unique_ptr< blender::io::serialize::ArrayValue > convert_to_serialize_values(const IDProperty *properties)
Convert the given properties to Value objects for serialization.
IDProperty * convert_from_serialize_value(const blender::io::serialize::Value &value)
Convert the given value to an IDProperty.
VectorSet< T, InlineBufferCapacity, DefaultProbingStrategy, CustomIDHash< T, GetIDFn >, CustomIDEqual< T, GetIDFn > > CustomIDVectorSet
const char * name
char name[64]
Definition DNA_ID.h:164
Definition DNA_ID.h:414
CustomIDVectorSet< IDProperty *, IDPropNameGetter, 8 > children
const char * str
Definition BKE_idprop.hh:39
struct IDPropertyTemplate::@306303166102371126056157213146124155011254157272 string
uint8_t flag
Definition wm_window.cc:145