Blender  V2.93
BKE_lib_id.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  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 #pragma once
20 
48 #include "BLI_compiler_attrs.h"
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 struct BlendWriter;
55 struct GHash;
56 struct ID;
57 struct Library;
58 struct ListBase;
59 struct Main;
60 struct PointerRNA;
61 struct PropertyRNA;
62 struct bContext;
63 
64 size_t BKE_libblock_get_alloc_info(short type, const char **name);
66 void *BKE_libblock_alloc(struct Main *bmain, short type, const char *name, const int flag)
68 void BKE_libblock_init_empty(struct ID *id) ATTR_NONNULL(1);
69 
70 /* *** ID's session_uuid management. *** */
71 
72 /* When an ID's uuid is of that value, it is unset/invalid (e.g. for runtime IDs, etc.). */
73 #define MAIN_ID_SESSION_UUID_UNSET 0
74 
77 
78 void *BKE_id_new(struct Main *bmain, const short type, const char *name);
79 void *BKE_id_new_nomain(const short type, const char *name);
80 
84 enum {
85  /* *** Generic options (should be handled by all ID types copying, ID creation, etc.). *** */
97 
100 
106 
110 
111  /* *** Specific options to some ID types or usages. *** */
112  /* *** May be ignored by unrelated ID copying functions. *** */
114  /* LIB_ID_COPY_NO_PROXY_CLEAR = 1 << 16, */ /* UNUSED */
125 
126  /* *** XXX Hackish/not-so-nice specific behaviors needed for some corner cases. *** */
127  /* *** Ideally we should not have those, but we need them for now... *** */
136 
137  /* *** Helper 'defines' gathering most common flag sets. *** */
140 
147 };
148 
149 void BKE_libblock_copy_ex(struct Main *bmain,
150  const struct ID *id,
151  struct ID **r_newid,
152  const int orig_flag);
153 void *BKE_libblock_copy(struct Main *bmain, const struct ID *id) ATTR_WARN_UNUSED_RESULT
154  ATTR_NONNULL();
155 /* Special version: used by data-block localization. */
156 void *BKE_libblock_copy_for_localize(const struct ID *id);
157 
158 void BKE_libblock_rename(struct Main *bmain, struct ID *id, const char *name) ATTR_NONNULL();
159 void BLI_libblock_ensure_unique_name(struct Main *bmain, const char *name) ATTR_NONNULL();
160 
161 struct ID *BKE_libblock_find_name(struct Main *bmain,
162  const short type,
164 
169 typedef enum eLibIDDuplicateFlags {
180 
181 /* lib_remap.c (keep here since they're general functions) */
185 enum {
186  /* *** Generic options (should be handled by all ID types freeing). *** */
200 
205 };
206 
207 void BKE_libblock_free_datablock(struct ID *id, const int flag) ATTR_NONNULL();
208 void BKE_libblock_free_data(struct ID *id, const bool do_id_user) ATTR_NONNULL();
209 
210 void BKE_libblock_free_data_py(struct ID *id);
211 
212 void BKE_id_free_ex(struct Main *bmain, void *idv, int flag, const bool use_flag_from_idtag);
213 void BKE_id_free(struct Main *bmain, void *idv);
214 
215 void BKE_id_free_us(struct Main *bmain, void *idv) ATTR_NONNULL();
216 
217 void BKE_id_delete(struct Main *bmain, void *idv) ATTR_NONNULL();
218 size_t BKE_id_multi_tagged_delete(struct Main *bmain) ATTR_NONNULL();
219 
220 void BKE_libblock_management_main_add(struct Main *bmain, void *idv);
221 void BKE_libblock_management_main_remove(struct Main *bmain, void *idv);
222 
223 void BKE_libblock_management_usercounts_set(struct Main *bmain, void *idv);
224 void BKE_libblock_management_usercounts_clear(struct Main *bmain, void *idv);
225 
226 void id_lib_extern(struct ID *id);
227 void id_lib_indirect_weak_link(struct ID *id);
228 void id_us_ensure_real(struct ID *id);
229 void id_us_clear_real(struct ID *id);
230 void id_us_plus_no_lib(struct ID *id);
231 void id_us_plus(struct ID *id);
232 void id_us_min(struct ID *id);
233 void id_fake_user_set(struct ID *id);
234 void id_fake_user_clear(struct ID *id);
235 void BKE_id_clear_newpoin(struct ID *id);
236 
238 enum {
241 
242  /* Special type-specific options. */
245 };
246 
247 void BKE_lib_id_make_local_generic(struct Main *bmain, struct ID *id, const int flags);
248 bool BKE_lib_id_make_local(struct Main *bmain, struct ID *id, const bool test, const int flags);
249 bool id_single_user(struct bContext *C,
250  struct ID *id,
251  struct PointerRNA *ptr,
252  struct PropertyRNA *prop);
253 bool BKE_id_copy_is_allowed(const struct ID *id);
254 struct ID *BKE_id_copy(struct Main *bmain, const struct ID *id);
255 struct ID *BKE_id_copy_ex(struct Main *bmain,
256  const struct ID *id,
257  struct ID **r_newid,
258  const int flag);
259 struct ID *BKE_id_copy_for_duplicate(struct Main *bmain,
260  struct ID *id,
261  const uint duplicate_flags);
262 
263 void BKE_lib_id_swap(struct Main *bmain, struct ID *id_a, struct ID *id_b);
264 void BKE_lib_id_swap_full(struct Main *bmain, struct ID *id_a, struct ID *id_b);
265 
266 void id_sort_by_name(struct ListBase *lb, struct ID *id, struct ID *id_sorting_hint);
267 void BKE_lib_id_expand_local(struct Main *bmain, struct ID *id);
268 
269 bool BKE_id_new_name_validate(struct ListBase *lb, struct ID *id, const char *name)
270  ATTR_NONNULL(1, 2);
271 void BKE_lib_id_clear_library_data(struct Main *bmain, struct ID *id);
272 
273 /* Affect whole Main database. */
274 void BKE_main_id_tag_idcode(struct Main *mainvar,
275  const short type,
276  const int tag,
277  const bool value);
278 void BKE_main_id_tag_listbase(struct ListBase *lb, const int tag, const bool value);
279 void BKE_main_id_tag_all(struct Main *mainvar, const int tag, const bool value);
280 
281 void BKE_main_id_flag_listbase(struct ListBase *lb, const int flag, const bool value);
282 void BKE_main_id_flag_all(struct Main *bmain, const int flag, const bool value);
283 
284 void BKE_main_id_clear_newpoins(struct Main *bmain);
285 
286 void BKE_main_id_refcount_recompute(struct Main *bmain, const bool do_linked_only);
287 
288 void BKE_main_lib_objects_recalc_all(struct Main *bmain);
289 
290 /* Only for repairing files via versioning, avoid for general use. */
292 
293 #define MAX_ID_FULL_NAME (64 + 64 + 3 + 1) /* 64 is MAX_ID_NAME - 2 */
294 #define MAX_ID_FULL_NAME_UI (MAX_ID_FULL_NAME + 3) /* Adds 'keycode' two letters at beginning. */
295 void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const struct ID *id, char separator_char);
297  const struct ID *id,
298  const bool add_lib_hint,
299  char separator_char,
300  int *r_prefix_len);
301 
302 char *BKE_id_to_unique_string_key(const struct ID *id);
303 
304 void BKE_library_make_local(struct Main *bmain,
305  const struct Library *lib,
306  struct GHash *old_to_new_ids,
307  const bool untagged_only,
308  const bool set_fake);
309 
310 void BKE_id_tag_set_atomic(struct ID *id, int tag);
311 void BKE_id_tag_clear_atomic(struct ID *id, int tag);
312 
313 bool BKE_id_is_in_global_main(struct ID *id);
314 
315 bool BKE_id_can_be_asset(const struct ID *id);
316 
317 void BKE_id_ordered_list(struct ListBase *ordered_lb, const struct ListBase *lb);
318 void BKE_id_reorder(const struct ListBase *lb, struct ID *id, struct ID *relative, bool after);
319 
320 void BKE_id_blend_write(struct BlendWriter *writer, struct ID *id);
321 
322 #define IS_TAGGED(_id) ((_id) && (((ID *)_id)->tag & LIB_TAG_DOIT))
323 
324 #ifdef __cplusplus
325 }
326 #endif
void BKE_id_reorder(const struct ListBase *lb, struct ID *id, struct ID *relative, bool after)
struct ID * BKE_id_copy(struct Main *bmain, const struct ID *id)
void BKE_libblock_management_usercounts_set(struct Main *bmain, void *idv)
Definition: lib_id.c:863
void * BKE_libblock_copy(struct Main *bmain, const struct ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BKE_lib_libblock_session_uuid_ensure(struct ID *id)
Definition: lib_id.c:1145
void BKE_lib_libblock_session_uuid_renew(struct ID *id)
Definition: lib_id.c:1166
void BKE_lib_id_expand_local(struct Main *bmain, struct ID *id)
Definition: lib_id.c:393
void BKE_libblock_management_main_add(struct Main *bmain, void *idv)
Definition: lib_id.c:812
bool BKE_id_copy_is_allowed(const struct ID *id)
void BKE_libblock_rename(struct Main *bmain, struct ID *id, const char *name) ATTR_NONNULL()
Definition: lib_id.c:2187
void BKE_id_tag_clear_atomic(struct ID *id, int tag)
Definition: lib_id.c:2278
void id_us_min(struct ID *id)
Definition: lib_id.c:297
void BKE_libblock_free_data_py(struct ID *id)
void * BKE_id_new_nomain(const short type, const char *name)
Definition: lib_id.c:1196
void * BKE_libblock_copy_for_localize(const struct ID *id)
void BKE_main_id_repair_duplicate_names_listbase(struct ListBase *lb)
Definition: lib_id.c:966
void BKE_libblock_free_data(struct ID *id, const bool do_id_user) ATTR_NONNULL()
Definition: lib_id_delete.c:55
void BKE_main_id_flag_all(struct Main *bmain, const int flag, const bool value)
Definition: lib_id.c:956
void BKE_main_id_tag_all(struct Main *mainvar, const int tag, const bool value)
Definition: lib_id.c:923
void id_lib_extern(struct ID *id)
Definition: lib_id.c:207
void id_fake_user_set(struct ID *id)
Definition: lib_id.c:328
@ LIB_ID_CREATE_NO_ALLOCATE
Definition: BKE_lib_id.h:96
@ LIB_ID_CREATE_LOCALIZE
Definition: BKE_lib_id.h:142
@ LIB_ID_COPY_NODETREE_LOCALIZE
Definition: BKE_lib_id.h:135
@ LIB_ID_COPY_NO_PREVIEW
Definition: BKE_lib_id.h:116
@ LIB_ID_COPY_CD_REFERENCE
Definition: BKE_lib_id.h:122
@ LIB_ID_COPY_CACHES
Definition: BKE_lib_id.h:118
@ LIB_ID_COPY_NO_LIB_OVERRIDE
Definition: BKE_lib_id.h:124
@ LIB_ID_COPY_SET_COPIED_ON_WRITE
Definition: BKE_lib_id.h:109
@ LIB_ID_CREATE_LOCAL
Definition: BKE_lib_id.h:105
@ LIB_ID_COPY_ACTIONS
Definition: BKE_lib_id.h:129
@ LIB_ID_COPY_KEEP_LIB
Definition: BKE_lib_id.h:131
@ LIB_ID_COPY_LOCALIZE
Definition: BKE_lib_id.h:145
@ LIB_ID_CREATE_NO_USER_REFCOUNT
Definition: BKE_lib_id.h:92
@ LIB_ID_COPY_NO_ANIMDATA
Definition: BKE_lib_id.h:120
@ LIB_ID_COPY_SHAPEKEY
Definition: BKE_lib_id.h:133
@ LIB_ID_CREATE_NO_MAIN
Definition: BKE_lib_id.h:88
@ LIB_ID_COPY_DEFAULT
Definition: BKE_lib_id.h:139
@ LIB_ID_CREATE_NO_DEG_TAG
Definition: BKE_lib_id.h:99
char * BKE_id_to_unique_string_key(const struct ID *id)
Definition: lib_id.c:2260
size_t BKE_libblock_get_alloc_info(short type, const char **name)
Definition: lib_id.c:1024
@ LIB_ID_FREE_NO_UI_USER
Definition: BKE_lib_id.h:204
@ LIB_ID_FREE_NOT_ALLOCATED
Definition: BKE_lib_id.h:199
@ LIB_ID_FREE_NO_DEG_TAG
Definition: BKE_lib_id.h:202
@ LIB_ID_FREE_NO_USER_REFCOUNT
Definition: BKE_lib_id.h:193
@ LIB_ID_FREE_NO_MAIN
Definition: BKE_lib_id.h:188
void * BKE_libblock_alloc(struct Main *bmain, short type, const char *name, const int flag) ATTR_WARN_UNUSED_RESULT
Definition: lib_id.c:1062
#define MAX_ID_FULL_NAME_UI
Definition: BKE_lib_id.h:294
void * BKE_libblock_alloc_notest(short type) ATTR_WARN_UNUSED_RESULT
Definition: lib_id.c:1045
void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI], const struct ID *id, const bool add_lib_hint, char separator_char, int *r_prefix_len)
struct ID * BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag)
void BKE_lib_id_swap_full(struct Main *bmain, struct ID *id_a, struct ID *id_b)
Definition: lib_id.c:741
void BKE_main_id_clear_newpoins(struct Main *bmain)
Definition: lib_id.c:1738
bool BKE_lib_id_make_local(struct Main *bmain, struct ID *id, const bool test, const int flags)
Definition: lib_id.c:479
void BKE_lib_id_make_local_generic(struct Main *bmain, struct ID *id, const int flags)
Definition: lib_id.c:412
void BKE_main_lib_objects_recalc_all(struct Main *bmain)
Definition: lib_id.c:997
bool id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, struct PropertyRNA *prop)
Definition: lib_id.c:747
void BKE_id_free(struct Main *bmain, void *idv)
void BKE_libblock_init_empty(struct ID *id) ATTR_NONNULL(1)
Definition: lib_id.c:1122
void BKE_libblock_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int orig_flag)
void id_us_ensure_real(struct ID *id)
Definition: lib_id.c:238
void BKE_library_make_local(struct Main *bmain, const struct Library *lib, struct GHash *old_to_new_ids, const bool untagged_only, const bool set_fake)
void id_us_plus(struct ID *id)
Definition: lib_id.c:288
@ LIB_ID_MAKELOCAL_OBJECT_NO_PROXY_CLEARING
Definition: BKE_lib_id.h:244
@ LIB_ID_MAKELOCAL_FULL_LIBRARY
Definition: BKE_lib_id.h:240
struct ID * BKE_id_copy_for_duplicate(struct Main *bmain, struct ID *id, const uint duplicate_flags)
void BKE_id_blend_write(struct BlendWriter *writer, struct ID *id)
Definition: lib_id.c:2395
void id_us_clear_real(struct ID *id)
Definition: lib_id.c:257
void id_us_plus_no_lib(struct ID *id)
Definition: lib_id.c:272
bool void BKE_lib_id_clear_library_data(struct Main *bmain, struct ID *id)
Definition: lib_id.c:202
bool BKE_id_is_in_global_main(struct ID *id)
Definition: lib_id.c:2287
void BKE_main_id_tag_idcode(struct Main *mainvar, const short type, const int tag, const bool value)
Definition: lib_id.c:910
void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const struct ID *id, char separator_char)
void BKE_main_id_tag_listbase(struct ListBase *lb, const int tag, const bool value)
Definition: lib_id.c:891
struct ID * BKE_libblock_find_name(struct Main *bmain, const short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: lib_id.c:1333
void BKE_libblock_management_usercounts_clear(struct Main *bmain, void *idv)
Definition: lib_id.c:875
void BKE_id_tag_set_atomic(struct ID *id, int tag)
Definition: lib_id.c:2273
void BKE_id_clear_newpoin(struct ID *id)
Definition: lib_id.c:344
void BKE_id_ordered_list(struct ListBase *ordered_lb, const struct ListBase *lb)
bool BKE_id_can_be_asset(const struct ID *id)
bool BKE_id_new_name_validate(struct ListBase *lb, struct ID *id, const char *name) ATTR_NONNULL(1
void BKE_id_delete(struct Main *bmain, void *idv) ATTR_NONNULL()
void BLI_libblock_ensure_unique_name(struct Main *bmain, const char *name) ATTR_NONNULL()
Definition: lib_id.c:2165
void id_fake_user_clear(struct ID *id)
Definition: lib_id.c:336
size_t BKE_id_multi_tagged_delete(struct Main *bmain) ATTR_NONNULL()
eLibIDDuplicateFlags
Definition: BKE_lib_id.h:169
@ LIB_ID_DUPLICATE_IS_ROOT_ID
Definition: BKE_lib_id.h:178
@ LIB_ID_DUPLICATE_IS_SUBPROCESS
Definition: BKE_lib_id.h:175
void id_lib_indirect_weak_link(struct ID *id)
Definition: lib_id.c:220
void BKE_main_id_refcount_recompute(struct Main *bmain, const bool do_linked_only)
Definition: lib_id.c:1773
void id_sort_by_name(struct ListBase *lb, struct ID *id, struct ID *id_sorting_hint)
Definition: lib_id.c:1348
void BKE_id_free_ex(struct Main *bmain, void *idv, int flag, const bool use_flag_from_idtag)
void * BKE_id_new(struct Main *bmain, const short type, const char *name)
Definition: lib_id.c:1177
void BKE_lib_id_swap(struct Main *bmain, struct ID *id_a, struct ID *id_b)
Definition: lib_id.c:729
void BKE_libblock_free_datablock(struct ID *id, const int flag) ATTR_NONNULL()
#define MAX_ID_FULL_NAME
Definition: BKE_lib_id.h:293
void BKE_libblock_management_main_remove(struct Main *bmain, void *idv)
Definition: lib_id.c:844
void BKE_id_free_us(struct Main *bmain, void *idv) ATTR_NONNULL()
void BKE_main_id_flag_listbase(struct ListBase *lb, const int flag, const bool value)
Definition: lib_id.c:937
#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
#define C
Definition: RandGen.cpp:39
DRWShaderLibrary * lib
Definition: DNA_ID.h:273
int tag
Definition: DNA_ID.h:292
short flag
Definition: DNA_ID.h:288
char name[66]
Definition: DNA_ID.h:283
Definition: BKE_main.h:116
PointerRNA * ptr
Definition: wm_files.c:3157