Blender V4.3
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
11#include <memory>
12
13#include "DNA_ID_enums.h"
14
15#include "BLI_compiler_attrs.h"
16#include "BLI_function_ref.hh"
17#include "BLI_span.hh"
18#include "BLI_string_ref.hh"
19#include "BLI_sys_types.h"
20
21struct BlendDataReader;
22struct BlendWriter;
23struct ID;
24struct IDProperty;
25struct IDPropertyUIData;
28class ArrayValue;
29class Value;
30} // namespace blender::io::serialize
31
33 int i;
34 float f;
35 double d;
36 struct {
37 const char *str;
39 int len;
41 char subtype;
44 struct {
45 int len;
47 char type;
49};
50
51/* ----------- Property Array Type ---------- */
52
60
64void IDP_SetIndexArray(IDProperty *prop, int index, IDProperty *item) ATTR_NONNULL();
66void IDP_AppendArray(IDProperty *prop, IDProperty *item);
67void IDP_ResizeIDPArray(IDProperty *prop, int len);
68
69/* ----------- Numeric Array Type ----------- */
70
74void IDP_ResizeArray(IDProperty *prop, int newlen);
75void IDP_FreeArray(IDProperty *prop);
76
77/* ---------- String Type ------------ */
86IDProperty *IDP_NewStringMaxSize(const char *st,
87 size_t st_maxncpy,
88 const char *name,
90 ATTR_NONNULL(3);
91IDProperty *IDP_NewString(const char *st,
92 const char *name,
100void IDP_AssignStringMaxSize(IDProperty *prop, const char *st, size_t st_maxncpy) ATTR_NONNULL();
101void IDP_AssignString(IDProperty *prop, const char *st) ATTR_NONNULL();
103
104/*-------- Enum Type -------*/
105
107
109 int items_num,
110 void (*error_fn)(const char *));
111
112/*-------- ID Type -------*/
113
114using IDPWalkFunc = void (*)(void *user_data, IDProperty *idp);
115
116void IDP_AssignID(IDProperty *prop, ID *id, int flag);
117
118/*-------- Group Functions -------*/
119
126void IDP_SyncGroupValues(IDProperty *dest, const IDProperty *src) ATTR_NONNULL();
127void IDP_SyncGroupTypes(IDProperty *dest, const IDProperty *src, bool do_arraylen) ATTR_NONNULL();
137void IDP_ReplaceInGroup_ex(IDProperty *group, IDProperty *prop, IDProperty *prop_exist);
142void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, bool do_overwrite) ATTR_NONNULL();
147void IDP_MergeGroup_ex(IDProperty *dest, const IDProperty *src, bool do_overwrite, int flag)
148 ATTR_NONNULL();
164bool IDP_InsertToGroup(IDProperty *group, IDProperty *previous, IDProperty *pnew)
165 ATTR_NONNULL(1 /*group*/, 3 /*pnew*/);
177
179 const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
184 const char *name,
186
187/*-------- Main Functions --------*/
198 ATTR_NONNULL();
204
208bool IDP_EqualsProperties_ex(const IDProperty *prop1,
209 const IDProperty *prop2,
210 bool is_strict) ATTR_WARN_UNUSED_RESULT;
211
212bool IDP_EqualsProperties(const IDProperty *prop1,
214
242IDProperty *IDP_New(char type,
243 const IDPropertyTemplate *val,
244 const char *name,
246
251void IDP_FreePropertyContent_ex(IDProperty *prop, bool do_id_user);
253void IDP_FreeProperty_ex(IDProperty *prop, bool do_id_user);
254void IDP_FreeProperty(IDProperty *prop);
255
256void IDP_ClearProperty(IDProperty *prop);
257
258void IDP_Reset(IDProperty *prop, const IDProperty *reference);
259
260#define IDP_Int(prop) ((prop)->data.val)
261#define IDP_Bool(prop) ((prop)->data.val)
262#define IDP_Array(prop) ((prop)->data.pointer)
263/* C11 const correctness for casts */
264#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
265# define IDP_Float(prop) \
266 _Generic((prop), \
267 IDProperty *: (*(float *)&(prop)->data.val), \
268 const IDProperty *: (*(const float *)&(prop)->data.val))
269# define IDP_Double(prop) \
270 _Generic((prop), \
271 IDProperty *: (*(double *)&(prop)->data.val), \
272 const IDProperty *: (*(const double *)&(prop)->data.val))
273# define IDP_String(prop) \
274 _Generic((prop), \
275 IDProperty *: ((char *)(prop)->data.pointer), \
276 const IDProperty *: ((const char *)(prop)->data.pointer))
277# define IDP_IDPArray(prop) \
278 _Generic((prop), \
279 IDProperty *: ((IDProperty *)(prop)->data.pointer), \
280 const IDProperty *: ((const IDProperty *)(prop)->data.pointer))
281# define IDP_Id(prop) \
282 _Generic((prop), \
283 IDProperty *: ((ID *)(prop)->data.pointer), \
284 const IDProperty *: ((const ID *)(prop)->data.pointer))
285#else
286# define IDP_Float(prop) (*(float *)&(prop)->data.val)
287# define IDP_Double(prop) (*(double *)&(prop)->data.val)
288# define IDP_String(prop) ((char *)(prop)->data.pointer)
289# define IDP_IDPArray(prop) ((IDProperty *)(prop)->data.pointer)
290# define IDP_Id(prop) ((ID *)(prop)->data.pointer)
291#endif
292
302float IDP_coerce_to_float_or_zero(const IDProperty *prop);
307double IDP_coerce_to_double_or_zero(const IDProperty *prop);
308
317void IDP_foreach_property(IDProperty *id_property_root,
318 int type_filter,
319 blender::FunctionRef<void(IDProperty *id_property)> callback);
320
321/* Format IDProperty as strings */
322char *IDP_reprN(const IDProperty *prop, uint *r_len);
323void IDP_repr_fn(const IDProperty *prop,
324 void (*str_append_fn)(void *user_data, const char *str, uint str_len),
325 void *user_data);
326void IDP_print(const IDProperty *prop);
327
328const char *IDP_type_str(eIDPropertyType type, short sub_type);
329const char *IDP_type_str(const IDProperty *prop);
330
331void IDP_BlendWrite(BlendWriter *writer, const IDProperty *prop);
333 IDProperty **prop,
334 const char *caller_func_id);
335#define IDP_BlendDataRead(reader, prop) IDP_BlendReadData_impl(reader, prop, __func__)
336
351
352bool IDP_ui_data_supported(const IDProperty *prop);
354void IDP_ui_data_free(IDProperty *prop);
362 const IDPropertyUIData *other);
370 eIDPropertyUIDataType src_type,
371 eIDPropertyUIDataType dst_type);
372
374
382std::unique_ptr<blender::io::serialize::ArrayValue> convert_to_serialize_values(
383 const IDProperty *properties);
384
389
391 public:
392 void operator()(IDProperty *id_prop)
393 {
394 IDP_FreeProperty(id_prop);
395 }
396};
397
399std::unique_ptr<IDProperty, IDPropertyDeleter> create_bool(StringRefNull prop_name,
400 bool value,
401 eIDPropertyFlag flags = {});
402
404std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name,
405 int32_t value,
406 eIDPropertyFlag flags = {});
407
409std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name,
410 float value,
411 eIDPropertyFlag flags = {});
412
414std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name,
415 double value,
416 eIDPropertyFlag flags = {});
417
419std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name,
420 const StringRefNull value,
421 eIDPropertyFlag flags = {});
422
424std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name,
425 ID *value,
426 eIDPropertyFlag flags = {});
427
433std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name,
434 Span<int32_t> values,
435 eIDPropertyFlag flags = {});
436
442std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name,
443 Span<float> values,
444 eIDPropertyFlag flags = {});
445
451std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name,
452 Span<double> values,
453 eIDPropertyFlag flags = {});
454
461std::unique_ptr<IDProperty, IDPropertyDeleter> create_group(StringRefNull prop_name,
462 eIDPropertyFlag flags = {});
463
464} // namespace blender::bke::idprop
IDProperty * IDP_NewIDPArray(const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:69
void IDP_Reset(IDProperty *prop, const IDProperty *reference)
Definition idprop.cc:1240
void IDP_ui_data_free(IDProperty *prop)
Definition idprop.cc:1183
IDPropertyUIData * IDP_TryConvertUIData(IDPropertyUIData *src, eIDPropertyUIDataType src_type, eIDPropertyUIDataType dst_type)
Definition idprop.cc:1757
bool IDP_EnumItemsValidate(const IDPropertyUIDataEnumItem *items, int items_num, void(*error_fn)(const char *))
Definition idprop.cc:480
void IDP_FreeFromGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:757
void IDP_CopyPropertyContent(IDProperty *dst, const IDProperty *src) ATTR_NONNULL()
Definition idprop.cc:866
float IDP_coerce_to_float_or_zero(const IDProperty *prop)
Definition idprop.cc:827
bool IDP_InsertToGroup(IDProperty *group, IDProperty *previous, IDProperty *pnew) ATTR_NONNULL(1
eIDPropertyUIDataType IDP_ui_data_type(const IDProperty *prop)
Definition idprop.cc:1665
bool IDP_ui_data_supported(const IDProperty *prop)
Definition idprop.cc:1687
void IDP_AssignString(IDProperty *prop, const char *st) ATTR_NONNULL()
Definition idprop.cc:431
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:260
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:763
void IDP_MergeGroup_ex(IDProperty *dest, const IDProperty *src, bool do_overwrite, int flag) ATTR_NONNULL()
Definition idprop.cc:676
void IDP_AssignStringMaxSize(IDProperty *prop, const char *st, size_t st_maxncpy) ATTR_NONNULL()
Definition idprop.cc:413
char * IDP_reprN(const IDProperty *prop, uint *r_len)
const char * IDP_type_str(eIDPropertyType type, short sub_type)
void IDP_ResizeIDPArray(IDProperty *prop, int len)
Definition idprop.cc:148
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:133
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1227
int IDP_coerce_to_int_or_zero(const IDProperty *prop)
Definition idprop.cc:795
IDProperty * IDP_CopyIDPArray(const IDProperty *array, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:80
void IDP_FreePropertyContent(IDProperty *prop)
Definition idprop.cc:1216
void IDP_ReplaceInGroup_ex(IDProperty *group, IDProperty *prop, IDProperty *prop_exist)
Definition idprop.cc:654
void IDP_FreePropertyContent_ex(IDProperty *prop, bool do_id_user)
Definition idprop.cc:1189
IDProperty * IDP_GetPropertyTypeFromGroup(const IDProperty *prop, const char *name, char type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:769
bool void IDP_RemoveFromGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:748
void IDP_ClearProperty(IDProperty *prop)
Definition idprop.cc:1233
IDProperty * IDP_New(char type, const IDPropertyTemplate *val, const char *name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:989
double IDP_coerce_to_double_or_zero(const IDProperty *prop)
Definition idprop.cc:811
void IDP_SetIndexArray(IDProperty *prop, int index, IDProperty *item) ATTR_NONNULL()
Definition idprop.cc:117
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:722
IDProperty * IDP_CopyProperty_ex(const IDProperty *prop, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:843
bool IDP_EqualsProperties_ex(const IDProperty *prop1, const IDProperty *prop2, bool is_strict) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:893
void IDP_AppendArray(IDProperty *prop, IDProperty *item)
Definition idprop.cc:140
IDProperty * IDP_EnsureProperties(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:880
void IDP_AssignID(IDProperty *prop, ID *id, int flag)
Definition idprop.cc:538
IDProperty * IDP_GetProperties(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:875
void IDP_ResizeArray(IDProperty *prop, int newlen)
Definition idprop.cc:215
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:861
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:1093
void IDP_ReplaceGroupInGroup(IDProperty *dest, const IDProperty *src) ATTR_NONNULL()
Definition idprop.cc:630
IDProperty * IDP_NewStringMaxSize(const char *st, size_t st_maxncpy, const char *name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(3)
Definition idprop.cc:357
void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, bool do_overwrite) ATTR_NONNULL()
Definition idprop.cc:717
void IDP_FreeString(IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:438
void IDP_BlendWrite(BlendWriter *writer, const IDProperty *prop)
Definition idprop.cc:1437
void IDP_SyncGroupValues(IDProperty *dest, const IDProperty *src) ATTR_NONNULL()
Definition idprop.cc:578
void IDP_FreeProperty_ex(IDProperty *prop, bool do_id_user)
Definition idprop.cc:1221
IDPropertyUIData * IDP_ui_data_ensure(IDProperty *prop)
Definition idprop.cc:1739
bool IDP_EqualsProperties(const IDProperty *prop1, const IDProperty *prop2) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:984
void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:669
void IDP_FreeArray(IDProperty *prop)
Definition idprop.cc:252
void(*)(void *user_data, IDProperty *idp) IDPWalkFunc
IDProperty * IDP_NewString(const char *st, const char *name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition idprop.cc:393
void IDP_BlendReadData_impl(BlendDataReader *reader, IDProperty **prop, const char *caller_func_id)
Definition idprop.cc:1649
const IDPropertyUIDataEnumItem * IDP_EnumItemFind(const IDProperty *prop)
Definition idprop.cc:463
void IDP_SyncGroupTypes(IDProperty *dest, const IDProperty *src, bool do_arraylen) ATTR_NONNULL()
Definition idprop.cc:607
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_NONNULL(...)
unsigned int uint
Enumerations for DNA_ID.h.
eIDPropertyType
eIDPropertyFlag
void operator()(IDProperty *id_prop)
DEGForeachIDComponentCallback callback
int len
#define str(s)
std::unique_ptr< IDProperty, IDPropertyDeleter > create_bool(StringRefNull prop_name, bool value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_BOOLEAN, set its name and value.
std::unique_ptr< blender::io::serialize::ArrayValue > convert_to_serialize_values(const IDProperty *properties)
Convert the given properties to Value objects for serialization.
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRefNull 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(StringRefNull prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
IDProperty * convert_from_serialize_value(const blender::io::serialize::Value &value)
Convert the given value to an IDProperty.
signed int int32_t
Definition stdint.h:77
Definition DNA_ID.h:413
const char * str
Definition BKE_idprop.hh:37
struct IDPropertyTemplate::@30 array
struct IDPropertyTemplate::@29 string
uint8_t flag
Definition wm_window.cc:138