Blender V4.5
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_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
64
68void IDP_SetIndexArray(IDProperty *prop, int index, IDProperty *item) ATTR_NONNULL();
70void IDP_AppendArray(IDProperty *prop, IDProperty *item);
71void IDP_ResizeIDPArray(IDProperty *prop, int newlen);
72
73/* ----------- Numeric Array Type ----------- */
74
78void IDP_ResizeArray(IDProperty *prop, int newlen);
79void IDP_FreeArray(IDProperty *prop);
80
81/* ---------- String Type ------------ */
90IDProperty *IDP_NewStringMaxSize(const char *st,
91 size_t st_maxncpy,
94IDProperty *IDP_NewString(const char *st,
103void IDP_AssignStringMaxSize(IDProperty *prop, const char *st, size_t st_maxncpy) ATTR_NONNULL();
104void IDP_AssignString(IDProperty *prop, const char *st) ATTR_NONNULL();
106
107/*-------- Enum Type -------*/
108
110
112 int items_num,
113 void (*error_fn)(const char *));
114
115/*-------- ID Type -------*/
116
117using IDPWalkFunc = void (*)(void *user_data, IDProperty *idp);
118
123void IDP_AssignID(IDProperty *prop, ID *id, int flag);
124
125/*-------- Group Functions -------*/
126
133void IDP_SyncGroupValues(IDProperty *dest, const IDProperty *src) ATTR_NONNULL();
134void IDP_SyncGroupTypes(IDProperty *dest, const IDProperty *src, bool do_arraylen) ATTR_NONNULL();
147void IDP_ReplaceInGroup_ex(IDProperty *group, IDProperty *prop, IDProperty *prop_exist, int flag);
152void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, bool do_overwrite) ATTR_NONNULL();
160void IDP_MergeGroup_ex(IDProperty *dest, const IDProperty *src, bool do_overwrite, int flag)
161 ATTR_NONNULL();
177bool IDP_InsertToGroup(IDProperty *group, IDProperty *previous, IDProperty *pnew)
178 ATTR_NONNULL(1 /*group*/, 3 /*pnew*/);
190
193 ATTR_NONNULL();
200 const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
207
208/*-------- Main Functions --------*/
223 ATTR_NONNULL();
229
233bool IDP_EqualsProperties_ex(const IDProperty *prop1,
234 const IDProperty *prop2,
235 bool is_strict) ATTR_WARN_UNUSED_RESULT;
236
237bool IDP_EqualsProperties(const IDProperty *prop1,
239
267IDProperty *IDP_New(char type,
268 const IDPropertyTemplate *val,
271
276void IDP_FreePropertyContent_ex(IDProperty *prop, bool do_id_user);
278void IDP_FreeProperty_ex(IDProperty *prop, bool do_id_user);
279void IDP_FreeProperty(IDProperty *prop);
280
281void IDP_ClearProperty(IDProperty *prop);
282
283void IDP_Reset(IDProperty *prop, const IDProperty *reference);
284
285#define IDP_Int(prop) ((prop)->data.val)
286#define IDP_Bool(prop) ((prop)->data.val)
287#define IDP_Array(prop) ((prop)->data.pointer)
288/* C11 const correctness for casts */
289#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
290# define IDP_Float(prop) \
291 _Generic((prop), \
292 IDProperty *: (*(float *)&(prop)->data.val), \
293 const IDProperty *: (*(const float *)&(prop)->data.val))
294# define IDP_Double(prop) \
295 _Generic((prop), \
296 IDProperty *: (*(double *)&(prop)->data.val), \
297 const IDProperty *: (*(const double *)&(prop)->data.val))
298# define IDP_String(prop) \
299 _Generic((prop), \
300 IDProperty *: ((char *)(prop)->data.pointer), \
301 const IDProperty *: ((const char *)(prop)->data.pointer))
302# define IDP_IDPArray(prop) \
303 _Generic((prop), \
304 IDProperty *: ((IDProperty *)(prop)->data.pointer), \
305 const IDProperty *: ((const IDProperty *)(prop)->data.pointer))
306# define IDP_Id(prop) \
307 _Generic((prop), \
308 IDProperty *: ((ID *)(prop)->data.pointer), \
309 const IDProperty *: ((const ID *)(prop)->data.pointer))
310#else
311# define IDP_Float(prop) (*(float *)&(prop)->data.val)
312# define IDP_Double(prop) (*(double *)&(prop)->data.val)
313# define IDP_String(prop) ((char *)(prop)->data.pointer)
314# define IDP_IDPArray(prop) ((IDProperty *)(prop)->data.pointer)
315# define IDP_Id(prop) ((ID *)(prop)->data.pointer)
316#endif
317
327float IDP_coerce_to_float_or_zero(const IDProperty *prop);
332double IDP_coerce_to_double_or_zero(const IDProperty *prop);
333
342void IDP_foreach_property(IDProperty *id_property_root,
343 int type_filter,
344 blender::FunctionRef<void(IDProperty *id_property)> callback);
345
346/* Format IDProperty as strings */
347char *IDP_reprN(const IDProperty *prop, uint *r_len);
348void IDP_repr_fn(const IDProperty *prop,
349 void (*str_append_fn)(void *user_data, const char *str, uint str_len),
350 void *user_data);
351void IDP_print(const IDProperty *prop);
352
353const char *IDP_type_str(eIDPropertyType type, short sub_type);
354const char *IDP_type_str(const IDProperty *prop);
355
356void IDP_BlendWrite(BlendWriter *writer, const IDProperty *prop);
358 IDProperty **prop,
359 const char *caller_func_id);
360#define IDP_BlendDataRead(reader, prop) IDP_BlendReadData_impl(reader, prop, __func__)
361
376
377bool IDP_ui_data_supported(const IDProperty *prop);
379void IDP_ui_data_free(IDProperty *prop);
387 const IDPropertyUIData *other);
395 eIDPropertyUIDataType src_type,
396 eIDPropertyUIDataType dst_type);
397
399
407std::unique_ptr<blender::io::serialize::ArrayValue> convert_to_serialize_values(
408 const IDProperty *properties);
409
414
416 public:
417 void operator()(IDProperty *id_prop)
418 {
419 IDP_FreeProperty(id_prop);
420 }
421};
422
424std::unique_ptr<IDProperty, IDPropertyDeleter> create_bool(StringRef prop_name,
425 bool value,
426 eIDPropertyFlag flags = {});
427
429std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
430 int32_t value,
431 eIDPropertyFlag flags = {});
432
434std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
435 float value,
436 eIDPropertyFlag flags = {});
437
439std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
440 double value,
441 eIDPropertyFlag flags = {});
442
444std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
445 StringRefNull value,
446 eIDPropertyFlag flags = {});
447
449std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
450 ID *value,
451 eIDPropertyFlag flags = {});
452
458std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
459 Span<int32_t> values,
460 eIDPropertyFlag flags = {});
461
467std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
468 Span<float> values,
469 eIDPropertyFlag flags = {});
470
476std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRef prop_name,
477 Span<double> values,
478 eIDPropertyFlag flags = {});
479
485
486std::unique_ptr<IDProperty, IDPropertyDeleter> create_group(StringRef prop_name,
487 eIDPropertyFlag flags = {});
488
489} // namespace blender::bke::idprop
void IDP_Reset(IDProperty *prop, const IDProperty *reference)
Definition idprop.cc:1256
void IDP_ui_data_free(IDProperty *prop)
Definition idprop.cc:1199
IDPropertyUIData * IDP_TryConvertUIData(IDPropertyUIData *src, eIDPropertyUIDataType src_type, eIDPropertyUIDataType dst_type)
Definition idprop.cc:1769
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, blender::StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:766
IDProperty * IDP_NewString(const char *st, blender::StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:391
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:760
void IDP_CopyPropertyContent(IDProperty *dst, const IDProperty *src) ATTR_NONNULL()
Definition idprop.cc:878
float IDP_coerce_to_float_or_zero(const IDProperty *prop)
Definition idprop.cc:839
bool IDP_InsertToGroup(IDProperty *group, IDProperty *previous, IDProperty *pnew) ATTR_NONNULL(1
eIDPropertyUIDataType IDP_ui_data_type(const IDProperty *prop)
Definition idprop.cc:1681
bool IDP_ui_data_supported(const IDProperty *prop)
Definition idprop.cc:1703
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:258
void IDP_MergeGroup_ex(IDProperty *dest, const IDProperty *src, bool do_overwrite, int flag) ATTR_NONNULL()
Definition idprop.cc:679
IDProperty * IDP_GetPropertyTypeFromGroup(const IDProperty *prop, blender::StringRef name, char type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:779
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_ReplaceInGroup_ex(IDProperty *group, IDProperty *prop, IDProperty *prop_exist, int flag)
Definition idprop.cc:654
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:131
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1243
int IDP_coerce_to_int_or_zero(const IDProperty *prop)
Definition idprop.cc:807
IDProperty * IDP_New(char type, const IDPropertyTemplate *val, blender::StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:1001
IDProperty * IDP_CopyIDPArray(const IDProperty *array, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:78
void IDP_FreePropertyContent(IDProperty *prop)
Definition idprop.cc:1232
void IDP_FreePropertyContent_ex(IDProperty *prop, bool do_id_user)
Definition idprop.cc:1205
bool void IDP_RemoveFromGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:751
void IDP_ClearProperty(IDProperty *prop)
Definition idprop.cc:1249
double IDP_coerce_to_double_or_zero(const IDProperty *prop)
Definition idprop.cc:823
void IDP_SetIndexArray(IDProperty *prop, int index, IDProperty *item) ATTR_NONNULL()
Definition idprop.cc:115
void IDP_ResizeIDPArray(IDProperty *prop, int newlen)
Definition idprop.cc:146
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:725
IDProperty * IDP_CopyProperty_ex(const IDProperty *prop, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:855
bool IDP_EqualsProperties_ex(const IDProperty *prop1, const IDProperty *prop2, bool is_strict) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:905
void IDP_AppendArray(IDProperty *prop, IDProperty *item)
Definition idprop.cc:138
IDProperty * IDP_EnsureProperties(ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition idprop.cc:892
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:887
void IDP_ResizeArray(IDProperty *prop, int newlen)
Definition idprop.cc:213
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:873
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:1109
void IDP_ReplaceGroupInGroup(IDProperty *dest, const IDProperty *src) ATTR_NONNULL()
Definition idprop.cc:630
void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, bool do_overwrite) ATTR_NONNULL()
Definition idprop.cc:720
IDProperty * IDP_NewStringMaxSize(const char *st, size_t st_maxncpy, blender::StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:355
void IDP_FreeString(IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:438
void IDP_BlendWrite(BlendWriter *writer, const IDProperty *prop)
Definition idprop.cc:1453
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:1237
IDPropertyUIData * IDP_ui_data_ensure(IDProperty *prop)
Definition idprop.cc:1751
bool IDP_EqualsProperties(const IDProperty *prop1, const IDProperty *prop2) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:996
void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:672
void IDP_FreeArray(IDProperty *prop)
Definition idprop.cc:250
void(*)(void *user_data, IDProperty *idp) IDPWalkFunc
void IDP_BlendReadData_impl(BlendDataReader *reader, IDProperty **prop, const char *caller_func_id)
Definition idprop.cc:1665
IDProperty * IDP_NewIDPArray(blender::StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:68
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
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.
Definition DNA_ID.h:404
struct IDPropertyTemplate::@347174163205254236177334334344125337263066142041 string
const char * str
Definition BKE_idprop.hh:37
uint8_t flag
Definition wm_window.cc:139