Blender  V2.93
BKE_idprop.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
23 #include "BLI_compiler_attrs.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 struct BlendDataReader;
30 struct BlendExpander;
31 struct BlendLibReader;
32 struct BlendWriter;
33 struct ID;
34 struct IDProperty;
35 
36 typedef union IDPropertyTemplate {
37  int i;
38  float f;
39  double d;
40  struct {
41  const char *str;
42  int len;
43  char subtype;
44  } string;
45  struct ID *id;
46  struct {
47  int len;
48  char type;
49  } array;
50  struct {
52  const float *example;
55 
56 /* ----------- Property Array Type ---------- */
57 
61 
62 /* shallow copies item */
63 void IDP_SetIndexArray(struct IDProperty *prop, int index, struct IDProperty *item) ATTR_NONNULL();
64 struct IDProperty *IDP_GetIndexArray(struct IDProperty *prop, int index) ATTR_WARN_UNUSED_RESULT
65  ATTR_NONNULL();
66 void IDP_AppendArray(struct IDProperty *prop, struct IDProperty *item);
67 void IDP_ResizeIDPArray(struct IDProperty *prop, int len);
68 
69 /* ----------- Numeric Array Type ----------- */
70 /*this function works for strings too!*/
71 void IDP_ResizeArray(struct IDProperty *prop, int newlen);
72 void IDP_FreeArray(struct IDProperty *prop);
73 
74 /* ---------- String Type ------------ */
75 struct IDProperty *IDP_NewString(const char *st,
76  const char *name,
77  int maxlen) ATTR_WARN_UNUSED_RESULT
78  ATTR_NONNULL(2 /* 'name 'arg */); /* maxlen excludes '\0' */
79 void IDP_AssignString(struct IDProperty *prop, const char *st, int maxlen)
80  ATTR_NONNULL(); /* maxlen excludes '\0' */
81 void IDP_ConcatStringC(struct IDProperty *prop, const char *st) ATTR_NONNULL();
82 void IDP_ConcatString(struct IDProperty *str1, struct IDProperty *append) ATTR_NONNULL();
83 void IDP_FreeString(struct IDProperty *prop) ATTR_NONNULL();
84 
85 /*-------- ID Type -------*/
86 
87 typedef void (*IDPWalkFunc)(void *userData, struct IDProperty *idp);
88 
89 void IDP_AssignID(struct IDProperty *prop, struct ID *id, const int flag);
90 
91 /*-------- Group Functions -------*/
92 
94 void IDP_SyncGroupValues(struct IDProperty *dest, const struct IDProperty *src) ATTR_NONNULL();
95 void IDP_SyncGroupTypes(struct IDProperty *dest,
96  const struct IDProperty *src,
97  const bool do_arraylen) ATTR_NONNULL();
98 void IDP_ReplaceGroupInGroup(struct IDProperty *dest, const struct IDProperty *src) ATTR_NONNULL();
99 void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
100 void IDP_ReplaceInGroup_ex(struct IDProperty *group,
101  struct IDProperty *prop,
102  struct IDProperty *prop_exist);
103 void IDP_MergeGroup(struct IDProperty *dest, const struct IDProperty *src, const bool do_overwrite)
104  ATTR_NONNULL();
105 void IDP_MergeGroup_ex(struct IDProperty *dest,
106  const struct IDProperty *src,
107  const bool do_overwrite,
108  const int flag) ATTR_NONNULL();
109 bool IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
110 bool IDP_InsertToGroup(struct IDProperty *group,
111  struct IDProperty *previous,
112  struct IDProperty *pnew) ATTR_NONNULL(1 /* group */, 3 /* pnew */);
113 void IDP_RemoveFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
114 void IDP_FreeFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
115 
116 struct IDProperty *IDP_GetPropertyFromGroup(const struct IDProperty *prop,
117  const char *name) ATTR_WARN_UNUSED_RESULT
118  ATTR_NONNULL();
120  const char *name,
121  const char type) ATTR_WARN_UNUSED_RESULT
122  ATTR_NONNULL();
123 
124 /*-------- Main Functions --------*/
125 struct IDProperty *IDP_GetProperties(struct ID *id,
126  const bool create_if_needed) ATTR_WARN_UNUSED_RESULT
127  ATTR_NONNULL();
129  ATTR_NONNULL();
130 struct IDProperty *IDP_CopyProperty_ex(const struct IDProperty *prop,
132 void IDP_CopyPropertyContent(struct IDProperty *dst, struct IDProperty *src) ATTR_NONNULL();
133 
134 bool IDP_EqualsProperties_ex(struct IDProperty *prop1,
135  struct IDProperty *prop2,
136  const bool is_strict) ATTR_WARN_UNUSED_RESULT;
137 
138 bool IDP_EqualsProperties(struct IDProperty *prop1,
139  struct IDProperty *prop2) ATTR_WARN_UNUSED_RESULT;
140 
141 struct IDProperty *IDP_New(const char type,
142  const IDPropertyTemplate *val,
144 
145 void IDP_FreePropertyContent_ex(struct IDProperty *prop, const bool do_id_user);
146 void IDP_FreePropertyContent(struct IDProperty *prop);
147 void IDP_FreeProperty_ex(struct IDProperty *prop, const bool do_id_user);
148 void IDP_FreeProperty(struct IDProperty *prop);
149 
150 void IDP_ClearProperty(struct IDProperty *prop);
151 
152 void IDP_Reset(struct IDProperty *prop, const struct IDProperty *reference);
153 
154 #define IDP_Int(prop) ((prop)->data.val)
155 #define IDP_Array(prop) ((prop)->data.pointer)
156 /* C11 const correctness for casts */
157 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
158 # define IDP_Float(prop) \
159  _Generic((prop), \
160  struct IDProperty *: (*(float *)&(prop)->data.val), \
161  const struct IDProperty *: (*(const float *)&(prop)->data.val))
162 # define IDP_Double(prop) \
163  _Generic((prop), \
164  struct IDProperty *: (*(double *)&(prop)->data.val), \
165  const struct IDProperty *: (*(const double *)&(prop)->data.val))
166 # define IDP_String(prop) \
167  _Generic((prop), \
168  struct IDProperty *: ((char *) (prop)->data.pointer), \
169  const struct IDProperty *: ((const char *) (prop)->data.pointer))
170 # define IDP_IDPArray(prop) \
171  _Generic((prop), \
172  struct IDProperty *: ((struct IDProperty *) (prop)->data.pointer), \
173  const struct IDProperty *: ((const struct IDProperty *) (prop)->data.pointer))
174 # define IDP_Id(prop) \
175  _Generic((prop), \
176  struct IDProperty *: ((ID *) (prop)->data.pointer), \
177  const struct IDProperty *: ((const ID *) (prop)->data.pointer))
178 #else
179 # define IDP_Float(prop) (*(float *)&(prop)->data.val)
180 # define IDP_Double(prop) (*(double *)&(prop)->data.val)
181 # define IDP_String(prop) ((char *)(prop)->data.pointer)
182 # define IDP_IDPArray(prop) ((struct IDProperty *)(prop)->data.pointer)
183 # define IDP_Id(prop) ((ID *)(prop)->data.pointer)
184 #endif
185 
190 typedef void (*IDPForeachPropertyCallback)(struct IDProperty *id_property, void *user_data);
191 
192 void IDP_foreach_property(struct IDProperty *id_property_root,
193  const int type_filter,
195  void *user_data);
196 
197 /* Format IDProperty as strings */
198 char *IDP_reprN(const struct IDProperty *prop, uint *r_len);
199 void IDP_repr_fn(const struct IDProperty *prop,
200  void (*str_append_fn)(void *user_data, const char *str, uint str_len),
201  void *user_data);
202 void IDP_print(const struct IDProperty *prop);
203 
204 void IDP_BlendWrite(struct BlendWriter *writer, const struct IDProperty *prop);
205 void IDP_BlendReadData_impl(struct BlendDataReader *reader,
206  struct IDProperty **prop,
207  const char *caller_func_id);
208 #define IDP_BlendDataRead(reader, prop) IDP_BlendReadData_impl(reader, prop, __func__)
209 void IDP_BlendReadLib(struct BlendLibReader *reader, struct IDProperty *prop);
210 void IDP_BlendReadExpand(struct BlendExpander *expander, struct IDProperty *prop);
211 
212 #ifdef __cplusplus
213 }
214 #endif
void IDP_BlendReadExpand(struct BlendExpander *expander, struct IDProperty *prop)
Definition: idprop.c:1336
bool IDP_EqualsProperties(struct IDProperty *prop1, struct IDProperty *prop2) ATTR_WARN_UNUSED_RESULT
Definition: idprop.c:875
void IDP_AppendArray(struct IDProperty *prop, struct IDProperty *item)
Definition: idprop.c:153
void IDP_FreePropertyContent(struct IDProperty *prop)
Definition: idprop.c:1029
void IDP_FreeProperty_ex(struct IDProperty *prop, const bool do_id_user)
Definition: idprop.c:1034
void(* IDPWalkFunc)(void *userData, struct IDProperty *idp)
Definition: BKE_idprop.h:87
void IDP_BlendWrite(struct BlendWriter *writer, const struct IDProperty *prop)
struct IDProperty * IDP_GetPropertyTypeFromGroup(const struct IDProperty *prop, const char *name, const char type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void IDP_SetIndexArray(struct IDProperty *prop, int index, struct IDProperty *item) ATTR_NONNULL()
Definition: idprop.c:130
void IDP_CopyPropertyContent(struct IDProperty *dst, struct IDProperty *src) ATTR_NONNULL()
Definition: idprop.c:755
void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:572
void IDP_AssignID(struct IDProperty *prop, struct ID *id, const int flag)
Definition: idprop.c:437
void(* IDPForeachPropertyCallback)(struct IDProperty *id_property, void *user_data)
Definition: BKE_idprop.h:190
struct IDProperty * IDP_GetIndexArray(struct IDProperty *prop, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:146
void IDP_MergeGroup_ex(struct IDProperty *dest, const struct IDProperty *src, const bool do_overwrite, const int flag) ATTR_NONNULL()
void IDP_BlendReadLib(struct BlendLibReader *reader, struct IDProperty *prop)
Definition: idprop.c:1300
void IDP_ConcatString(struct IDProperty *str1, struct IDProperty *append) ATTR_NONNULL()
Definition: idprop.c:399
void IDP_print(const struct IDProperty *prop)
char * IDP_reprN(const struct IDProperty *prop, uint *r_len)
struct IDProperty * IDP_GetProperties(struct ID *id, const bool create_if_needed) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:769
void IDP_FreePropertyContent_ex(struct IDProperty *prop, const bool do_id_user)
Definition: idprop.c:1006
void IDP_ConcatStringC(struct IDProperty *prop, const char *st) ATTR_NONNULL()
Definition: idprop.c:388
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:82
struct IDProperty * IDP_CopyIDPArray(const struct IDProperty *array, const int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool void IDP_RemoveFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:679
void IDP_ReplaceInGroup_ex(struct IDProperty *group, struct IDProperty *prop, struct IDProperty *prop_exist)
Definition: idprop.c:557
struct IDProperty * IDP_NewString(const char *st, const char *name, int maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition: idprop.c:325
void IDP_ResizeIDPArray(struct IDProperty *prop, int len)
Definition: idprop.c:161
void IDP_foreach_property(struct IDProperty *id_property_root, const int type_filter, IDPForeachPropertyCallback callback, void *user_data)
Definition: idprop.c:1072
void IDP_FreeString(struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:410
union IDPropertyTemplate IDPropertyTemplate
void IDP_BlendReadData_impl(struct BlendDataReader *reader, struct IDProperty **prop, const char *caller_func_id)
Definition: idprop.c:1284
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(struct IDProperty *prop)
Definition: idprop.c:1040
void IDP_SyncGroupValues(struct IDProperty *dest, const struct IDProperty *src) ATTR_NONNULL()
void IDP_SyncGroupTypes(struct IDProperty *dest, const struct IDProperty *src, const bool do_arraylen) ATTR_NONNULL()
void IDP_ResizeArray(struct IDProperty *prop, int newlen)
Definition: idprop.c:232
bool IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:643
struct IDProperty * IDP_GetPropertyFromGroup(const struct IDProperty *prop, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool IDP_EqualsProperties_ex(struct IDProperty *prop1, struct IDProperty *prop2, const bool is_strict) ATTR_WARN_UNUSED_RESULT
Definition: idprop.c:788
void IDP_Reset(struct IDProperty *prop, const struct IDProperty *reference)
void IDP_MergeGroup(struct IDProperty *dest, const struct IDProperty *src, const bool do_overwrite) ATTR_NONNULL()
struct IDProperty * IDP_New(const char type, const IDPropertyTemplate *val, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:907
struct IDProperty * IDP_CopyProperty_ex(const struct IDProperty *prop, const int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void IDP_AssignString(struct IDProperty *prop, const char *st, int maxlen) ATTR_NONNULL()
Definition: idprop.c:369
void IDP_FreeArray(struct IDProperty *prop)
Definition: idprop.c:269
void IDP_FreeFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:690
void IDP_ClearProperty(struct IDProperty *prop)
Definition: idprop.c:1046
struct IDProperty * IDP_CopyProperty(const struct IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
#define ATTR_NONNULL(...)
void BLI_kdtree_nd_() int BLI_kdtree_nd_() int BLI_kdtree_nd_() int BLI_kdtree_nd_() ATTR_WARN_UNUSED_RESULT
unsigned int uint
Definition: BLI_sys_types.h:83
_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
#define str(s)
short flag
Definition: DNA_ID.h:72
char name[64]
Definition: DNA_ID.h:74
Definition: DNA_ID.h:273
struct IDPropertyTemplate::@29 matrix_or_vector
const float * example
Definition: BKE_idprop.h:52
const char * str
Definition: BKE_idprop.h:41
struct IDPropertyTemplate::@28 array
struct ID * id
Definition: BKE_idprop.h:45
struct IDPropertyTemplate::@27 string
uint len