Blender  V3.3
BKE_idprop.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
9 #include "BLI_compiler_attrs.h"
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 struct BlendDataReader;
16 struct BlendExpander;
17 struct BlendLibReader;
18 struct BlendWriter;
19 struct ID;
20 struct IDProperty;
21 struct IDPropertyUIData;
22 struct Library;
23 
24 typedef union IDPropertyTemplate {
25  int i;
26  float f;
27  double d;
28  struct {
29  const char *str;
30  int len;
31  char subtype;
32  } string;
33  struct ID *id;
34  struct {
35  int len;
36  char type;
37  } array;
38  struct {
40  const float *example;
43 
44 /* ----------- Property Array Type ---------- */
45 
53 
57 void IDP_SetIndexArray(struct IDProperty *prop, int index, struct IDProperty *item) ATTR_NONNULL();
58 struct IDProperty *IDP_GetIndexArray(struct IDProperty *prop, int index) ATTR_WARN_UNUSED_RESULT
59  ATTR_NONNULL();
60 void IDP_AppendArray(struct IDProperty *prop, struct IDProperty *item);
61 void IDP_ResizeIDPArray(struct IDProperty *prop, int len);
62 
63 /* ----------- Numeric Array Type ----------- */
64 
68 void IDP_ResizeArray(struct IDProperty *prop, int newlen);
69 void IDP_FreeArray(struct IDProperty *prop);
70 
71 /* ---------- String Type ------------ */
78 struct IDProperty *IDP_NewString(const char *st,
79  const char *name,
80  int maxlen) ATTR_WARN_UNUSED_RESULT
81  ATTR_NONNULL(2 /* 'name 'arg */); /* maxlen excludes '\0' */
82 void IDP_AssignString(struct IDProperty *prop, const char *st, int maxlen)
83  ATTR_NONNULL(); /* maxlen excludes '\0' */
84 void IDP_ConcatStringC(struct IDProperty *prop, const char *st) ATTR_NONNULL();
85 void IDP_ConcatString(struct IDProperty *str1, struct IDProperty *append) ATTR_NONNULL();
86 void IDP_FreeString(struct IDProperty *prop) ATTR_NONNULL();
87 
88 /*-------- ID Type -------*/
89 
90 typedef void (*IDPWalkFunc)(void *userData, struct IDProperty *idp);
91 
92 void IDP_AssignID(struct IDProperty *prop, struct ID *id, int flag);
93 
94 /*-------- Group Functions -------*/
95 
103 void IDP_SyncGroupTypes(struct IDProperty *dest, const struct IDProperty *src, bool do_arraylen)
104  ATTR_NONNULL();
109 void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
114 void IDP_ReplaceInGroup_ex(struct IDProperty *group,
115  struct IDProperty *prop,
116  struct IDProperty *prop_exist);
121 void IDP_MergeGroup(struct IDProperty *dest, const struct IDProperty *src, bool do_overwrite)
122  ATTR_NONNULL();
128  const struct IDProperty *src,
129  bool do_overwrite,
130  int flag) ATTR_NONNULL();
141 bool IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
146 bool IDP_InsertToGroup(struct IDProperty *group,
147  struct IDProperty *previous,
148  struct IDProperty *pnew) ATTR_NONNULL(1 /* group */, 3 /* pnew */);
155 void IDP_RemoveFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
159 void IDP_FreeFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
160 
161 struct IDProperty *IDP_GetPropertyFromGroup(const struct IDProperty *prop,
162  const char *name) ATTR_WARN_UNUSED_RESULT
163  ATTR_NONNULL();
168  const char *name,
170 
171 /*-------- Main Functions --------*/
178 struct IDProperty *IDP_GetProperties(struct ID *id, bool create_if_needed) ATTR_WARN_UNUSED_RESULT
179  ATTR_NONNULL();
181  ATTR_NONNULL();
182 struct IDProperty *IDP_CopyProperty_ex(const struct IDProperty *prop,
188 void IDP_CopyPropertyContent(struct IDProperty *dst, struct IDProperty *src) ATTR_NONNULL();
189 
193 bool IDP_EqualsProperties_ex(struct IDProperty *prop1,
194  struct IDProperty *prop2,
195  bool is_strict) ATTR_WARN_UNUSED_RESULT;
196 
197 bool IDP_EqualsProperties(struct IDProperty *prop1,
198  struct IDProperty *prop2) ATTR_WARN_UNUSED_RESULT;
199 
227 struct IDProperty *IDP_New(char type,
228  const IDPropertyTemplate *val,
230 
235 void IDP_FreePropertyContent_ex(struct IDProperty *prop, bool do_id_user);
236 void IDP_FreePropertyContent(struct IDProperty *prop);
237 void IDP_FreeProperty_ex(struct IDProperty *prop, bool do_id_user);
238 void IDP_FreeProperty(struct IDProperty *prop);
239 
240 void IDP_ClearProperty(struct IDProperty *prop);
241 
242 void IDP_Reset(struct IDProperty *prop, const struct IDProperty *reference);
243 
244 #define IDP_Int(prop) ((prop)->data.val)
245 #define IDP_Array(prop) ((prop)->data.pointer)
246 /* C11 const correctness for casts */
247 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
248 # define IDP_Float(prop) \
249  _Generic((prop), \
250  struct IDProperty *: (*(float *)&(prop)->data.val), \
251  const struct IDProperty *: (*(const float *)&(prop)->data.val))
252 # define IDP_Double(prop) \
253  _Generic((prop), \
254  struct IDProperty *: (*(double *)&(prop)->data.val), \
255  const struct IDProperty *: (*(const double *)&(prop)->data.val))
256 # define IDP_String(prop) \
257  _Generic((prop), \
258  struct IDProperty *: ((char *) (prop)->data.pointer), \
259  const struct IDProperty *: ((const char *) (prop)->data.pointer))
260 # define IDP_IDPArray(prop) \
261  _Generic((prop), \
262  struct IDProperty *: ((struct IDProperty *) (prop)->data.pointer), \
263  const struct IDProperty *: ((const struct IDProperty *) (prop)->data.pointer))
264 # define IDP_Id(prop) \
265  _Generic((prop), \
266  struct IDProperty *: ((ID *) (prop)->data.pointer), \
267  const struct IDProperty *: ((const ID *) (prop)->data.pointer))
268 #else
269 # define IDP_Float(prop) (*(float *)&(prop)->data.val)
270 # define IDP_Double(prop) (*(double *)&(prop)->data.val)
271 # define IDP_String(prop) ((char *)(prop)->data.pointer)
272 # define IDP_IDPArray(prop) ((struct IDProperty *)(prop)->data.pointer)
273 # define IDP_Id(prop) ((ID *)(prop)->data.pointer)
274 #endif
275 
280 int IDP_coerce_to_int_or_zero(const struct IDProperty *prop);
285 float IDP_coerce_to_float_or_zero(const struct IDProperty *prop);
290 double IDP_coerce_to_double_or_zero(const struct IDProperty *prop);
291 
295 typedef void (*IDPForeachPropertyCallback)(struct IDProperty *id_property, void *user_data);
296 
305 void IDP_foreach_property(struct IDProperty *id_property_root,
306  int type_filter,
308  void *user_data);
309 
310 /* Format IDProperty as strings */
311 char *IDP_reprN(const struct IDProperty *prop, uint *r_len);
312 void IDP_repr_fn(const struct IDProperty *prop,
313  void (*str_append_fn)(void *user_data, const char *str, uint str_len),
314  void *user_data);
315 void IDP_print(const struct IDProperty *prop);
316 
317 void IDP_BlendWrite(struct BlendWriter *writer, const struct IDProperty *prop);
318 void IDP_BlendReadData_impl(struct BlendDataReader *reader,
319  struct IDProperty **prop,
320  const char *caller_func_id);
321 #define IDP_BlendDataRead(reader, prop) IDP_BlendReadData_impl(reader, prop, __func__)
322 void IDP_BlendReadLib(struct BlendLibReader *reader, struct Library *lib, struct IDProperty *prop);
323 void IDP_BlendReadExpand(struct BlendExpander *expander, struct IDProperty *prop);
324 
325 typedef enum eIDPropertyUIDataType {
337 
338 bool IDP_ui_data_supported(const struct IDProperty *prop);
340 void IDP_ui_data_free(struct IDProperty *prop);
348  const struct IDPropertyUIData *other);
349 struct IDPropertyUIData *IDP_ui_data_ensure(struct IDProperty *prop);
350 struct IDPropertyUIData *IDP_ui_data_copy(const struct IDProperty *prop);
351 
352 #ifdef __cplusplus
353 }
354 #endif
eIDPropertyUIDataType IDP_ui_data_type(const struct IDProperty *prop)
void IDP_MergeGroup_ex(struct IDProperty *dest, const struct IDProperty *src, bool do_overwrite, int flag) ATTR_NONNULL()
void IDP_BlendReadExpand(struct BlendExpander *expander, struct IDProperty *prop)
Definition: idprop.c:1471
bool IDP_EqualsProperties(struct IDProperty *prop1, struct IDProperty *prop2) ATTR_WARN_UNUSED_RESULT
Definition: idprop.c:882
void IDP_AssignID(struct IDProperty *prop, struct ID *id, int flag)
Definition: idprop.c:452
struct IDProperty * IDP_CopyProperty_ex(const struct IDProperty *prop, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void IDP_AppendArray(struct IDProperty *prop, struct IDProperty *item)
Definition: idprop.c:133
void IDP_FreePropertyContent(struct IDProperty *prop)
Definition: idprop.c:1082
void(* IDPWalkFunc)(void *userData, struct IDProperty *idp)
Definition: BKE_idprop.h:90
struct IDPropertyUIData * IDP_ui_data_ensure(struct IDProperty *prop)
Definition: idprop.c:1519
void IDP_BlendWrite(struct BlendWriter *writer, const struct IDProperty *prop)
void IDP_SetIndexArray(struct IDProperty *prop, int index, struct IDProperty *item) ATTR_NONNULL()
Definition: idprop.c:110
struct IDProperty * IDP_GetProperties(struct ID *id, bool create_if_needed) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:778
void IDP_CopyPropertyContent(struct IDProperty *dst, struct IDProperty *src) ATTR_NONNULL()
Definition: idprop.c:769
void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:578
struct IDProperty * IDP_CopyIDPArray(const struct IDProperty *array, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void IDP_foreach_property(struct IDProperty *id_property_root, int type_filter, IDPForeachPropertyCallback callback, void *user_data)
Definition: idprop.c:1117
void(* IDPForeachPropertyCallback)(struct IDProperty *id_property, void *user_data)
Definition: BKE_idprop.h:295
bool IDP_ui_data_supported(const struct IDProperty *prop)
void IDP_ui_data_free_unique_contents(struct IDPropertyUIData *ui_data, eIDPropertyUIDataType type, const struct IDPropertyUIData *other)
int IDP_coerce_to_int_or_zero(const struct IDProperty *prop)
struct IDProperty * IDP_GetIndexArray(struct IDProperty *prop, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:126
void IDP_ConcatString(struct IDProperty *str1, struct IDProperty *append) ATTR_NONNULL()
Definition: idprop.c:413
void IDP_print(const struct IDProperty *prop)
char * IDP_reprN(const struct IDProperty *prop, uint *r_len)
eIDPropertyUIDataType
Definition: BKE_idprop.h:325
@ IDP_UI_DATA_TYPE_ID
Definition: BKE_idprop.h:335
@ IDP_UI_DATA_TYPE_UNSUPPORTED
Definition: BKE_idprop.h:327
@ IDP_UI_DATA_TYPE_INT
Definition: BKE_idprop.h:329
@ IDP_UI_DATA_TYPE_FLOAT
Definition: BKE_idprop.h:331
@ IDP_UI_DATA_TYPE_STRING
Definition: BKE_idprop.h:333
struct IDProperty * IDP_New(char type, const IDPropertyTemplate *val, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:887
void IDP_ConcatStringC(struct IDProperty *prop, const char *st) ATTR_NONNULL()
Definition: idprop.c:402
struct IDPropertyUIData * IDP_ui_data_copy(const struct IDProperty *prop)
bool IDP_InsertToGroup(struct IDProperty *group, struct IDProperty *previous, struct IDProperty *pnew) ATTR_NONNULL(1
struct IDProperty * IDP_NewIDPArray(const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:63
struct IDProperty * IDP_GetPropertyTypeFromGroup(const struct IDProperty *prop, const char *name, char type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool void IDP_RemoveFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:657
void IDP_ReplaceInGroup_ex(struct IDProperty *group, struct IDProperty *prop, struct IDProperty *prop_exist)
Definition: idprop.c:563
struct IDProperty * IDP_NewString(const char *st, const char *name, int maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition: idprop.c:339
void IDP_ResizeIDPArray(struct IDProperty *prop, int len)
Definition: idprop.c:141
void IDP_FreeString(struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:424
void IDP_SyncGroupTypes(struct IDProperty *dest, const struct IDProperty *src, bool do_arraylen) ATTR_NONNULL()
union IDPropertyTemplate IDPropertyTemplate
void IDP_BlendReadData_impl(struct BlendDataReader *reader, struct IDProperty **prop, const char *caller_func_id)
Definition: idprop.c:1419
void IDP_repr_fn(const struct IDProperty *prop, void(*str_append_fn)(void *user_data, const char *str, uint str_len), void *user_data)
void IDP_ReplaceGroupInGroup(struct IDProperty *dest, const struct IDProperty *src) ATTR_NONNULL()
void IDP_FreeProperty_ex(struct IDProperty *prop, bool do_id_user)
Definition: idprop.c:1087
void IDP_ui_data_free(struct IDProperty *prop)
Definition: idprop.c:1023
void IDP_MergeGroup(struct IDProperty *dest, const struct IDProperty *src, bool do_overwrite) ATTR_NONNULL()
void IDP_FreeProperty(struct IDProperty *prop)
Definition: idprop.c:1093
void IDP_FreePropertyContent_ex(struct IDProperty *prop, bool do_id_user)
Definition: idprop.c:1055
void IDP_SyncGroupValues(struct IDProperty *dest, const struct IDProperty *src) ATTR_NONNULL()
void IDP_ResizeArray(struct IDProperty *prop, int newlen)
Definition: idprop.c:211
bool IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:631
bool IDP_EqualsProperties_ex(struct IDProperty *prop1, struct IDProperty *prop2, bool is_strict) ATTR_WARN_UNUSED_RESULT
Definition: idprop.c:795
struct IDProperty * IDP_GetPropertyFromGroup(const struct IDProperty *prop, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
float IDP_coerce_to_float_or_zero(const struct IDProperty *prop)
void IDP_Reset(struct IDProperty *prop, const struct IDProperty *reference)
void IDP_BlendReadLib(struct BlendLibReader *reader, struct Library *lib, struct IDProperty *prop)
Definition: idprop.c:1435
void IDP_AssignString(struct IDProperty *prop, const char *st, int maxlen) ATTR_NONNULL()
Definition: idprop.c:383
void IDP_FreeArray(struct IDProperty *prop)
Definition: idprop.c:248
double IDP_coerce_to_double_or_zero(const struct IDProperty *prop)
void IDP_FreeFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:666
void IDP_ClearProperty(struct IDProperty *prop)
Definition: idprop.c:1099
struct IDProperty * IDP_CopyProperty(const struct IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_NONNULL(...)
unsigned int uint
Definition: BLI_sys_types.h:67
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
void * user_data
DEGForeachIDComponentCallback callback
SyclQueue void void * src
SyclQueue void void size_t num_bytes void
SyclQueue void * dest
int len
Definition: draw_manager.c:108
DRWShaderLibrary * lib
#define str(s)
static const pxr::TfToken st("st", pxr::TfToken::Immortal)
short flag
Definition: DNA_ID.h:109
IDPropertyUIData * ui_data
Definition: DNA_ID.h:128
char name[64]
Definition: DNA_ID.h:111
Definition: DNA_ID.h:368
const float * example
Definition: BKE_idprop.h:40
struct IDPropertyTemplate::@27 array
const char * str
Definition: BKE_idprop.h:29
struct IDPropertyTemplate::@28 matrix_or_vector
struct ID * id
Definition: BKE_idprop.h:33
struct IDPropertyTemplate::@26 string