Blender V5.0
BKE_lib_remap.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#pragma once
5
22
23#include "BLI_compiler_attrs.h"
24#include "BLI_function_ref.hh"
25#include "BLI_map.hh"
26#include "BLI_set.hh"
27#include "BLI_span.hh"
28#include "BLI_utildefines.h"
29
30struct ID;
31struct Main;
32
33namespace blender::bke::id {
34class IDRemapper;
35}
36
37/* BKE_libblock_free, delete are declared in BKE_lib_id.hh for convenience. */
38
39/* Also IDRemap->flag. */
40enum {
91
98
128};
129
137
145 const int remap_flags);
146
149 const int remap_flags);
150
162 const int remap_flags);
170void BKE_libblock_remap_locked(Main *bmain, void *old_idv, void *new_idv, int remap_flags)
171 ATTR_NONNULL(1, 2);
172void BKE_libblock_remap(Main *bmain, void *old_idv, void *new_idv, int remap_flags)
173 ATTR_NONNULL(1, 2);
174
179void BKE_libblock_unlink(Main *bmain, void *idv, bool do_skip_indirect) ATTR_NONNULL();
180
190void BKE_libblock_relink_ex(Main *bmain, void *idv, void *old_idv, void *new_idv, int remap_flags)
191 ATTR_NONNULL(2);
197 const blender::Span<ID *> ids,
198 eIDRemapType remap_type,
199 blender::bke::id::IDRemapper &id_remapper,
200 int remap_flags);
201
211void BKE_libblock_relink_to_newid(Main *bmain, ID *id, int remap_flag) ATTR_NONNULL();
212
213using BKE_library_free_notifier_reference_cb = void (*)(const void *);
215 void (*)(const blender::bke::id::IDRemapper &mappings);
216
220
221/* IDRemapper */
232
264
265using IDRemapperIterFunction = void (*)(ID *old_id, ID *new_id, void *user_data);
267
268namespace blender::bke::id {
269
271 Map<ID *, ID *> mappings_;
272 IDTypeFilter source_types_ = 0;
273
278 Set<ID *> never_null_users_;
279
280 public:
286
287 void clear()
288 {
289 mappings_.clear();
290 never_null_users_.clear();
291 source_types_ = 0;
292 }
293
294 bool is_empty() const
295 {
296 return mappings_.is_empty();
297 }
298
300 {
301 return (source_types_ & filter) != 0;
302 }
303
305 void add(ID *old_id, ID *new_id);
307 void add_overwrite(ID *old_id, ID *new_id);
308
310 IDRemapperApplyResult get_mapping_result(ID *id,
312 const ID *id_self) const;
313
322 IDRemapperApplyResult apply(ID **r_id_ptr,
324 ID *id_self = nullptr) const;
325
327 {
328 never_null_users_.add(id);
329 }
330
332 {
333 return never_null_users_;
334 }
335
337 void iter(FunctionRef<void(ID *old_id, ID *new_id)> func) const
338 {
339 for (auto item : mappings_.items()) {
340 func(item.key, item.value);
341 }
342 }
343
345 static StringRefNull result_to_string(const IDRemapperApplyResult result);
346
348 void print() const;
349};
350
351} // namespace blender::bke::id
void BKE_libblock_remap_multiple_raw(Main *bmain, blender::bke::id::IDRemapper &mappings, const int remap_flags)
Definition lib_remap.cc:679
void BKE_libblock_remap_multiple_locked(Main *bmain, blender::bke::id::IDRemapper &mappings, const int remap_flags)
Definition lib_remap.cc:655
void BKE_library_callback_remap_editor_id_reference_set(BKE_library_remap_editor_id_reference_cb func)
Definition lib_remap.cc:53
void BKE_libblock_relink_to_newid(Main *bmain, ID *id, int remap_flag) ATTR_NONNULL()
Definition lib_remap.cc:931
IDRemapperApplyResult
@ ID_REMAP_RESULT_SOURCE_REMAPPED
@ ID_REMAP_RESULT_SOURCE_UNASSIGNED
@ ID_REMAP_RESULT_SOURCE_NOT_MAPPABLE
@ ID_REMAP_RESULT_SOURCE_UNAVAILABLE
void BKE_libblock_relink_multiple(Main *bmain, const blender::Span< ID * > ids, eIDRemapType remap_type, blender::bke::id::IDRemapper &id_remapper, int remap_flags)
Definition lib_remap.cc:792
uint64_t IDTypeFilter
IDRemapperApplyOptions
@ ID_REMAP_APPLY_UPDATE_REFCOUNT
@ ID_REMAP_APPLY_UNMAP_WHEN_REMAPPING_TO_SELF
@ ID_REMAP_APPLY_ENSURE_REAL
@ ID_REMAP_APPLY_DEFAULT
void BKE_library_callback_free_notifier_reference_set(BKE_library_free_notifier_reference_cb func)
Definition lib_remap.cc:46
eIDRemapType
@ ID_REMAP_TYPE_REMAP
@ ID_REMAP_TYPE_CLEANUP
void(*)(const blender::bke::id::IDRemapper &mappings) BKE_library_remap_editor_id_reference_cb
void BKE_libblock_remap_multiple(Main *bmain, blender::bke::id::IDRemapper &mappings, const int remap_flags)
Definition lib_remap.cc:711
void void void BKE_libblock_unlink(Main *bmain, void *idv, bool do_skip_indirect) ATTR_NONNULL()
Definition lib_remap.cc:720
void(*)(const void *) BKE_library_free_notifier_reference_cb
void BKE_libblock_remap_locked(Main *bmain, void *old_idv, void *new_idv, int remap_flags) ATTR_NONNULL(1
void BKE_libblock_relink_ex(Main *bmain, void *idv, void *old_idv, void *new_idv, int remap_flags) ATTR_NONNULL(2)
Definition lib_remap.cc:854
void void BKE_libblock_remap(Main *bmain, void *old_idv, void *new_idv, int remap_flags) ATTR_NONNULL(1
void(*)(ID *old_id, ID *new_id, void *user_data) IDRemapperIterFunction
@ ID_REMAP_SKIP_USER_CLEAR
@ ID_REMAP_SKIP_USER_REFCOUNT
@ ID_REMAP_FORCE_INTERNAL_RUNTIME_POINTERS
@ ID_REMAP_SKIP_OVERRIDE_LIBRARY
@ ID_REMAP_FORCE_USER_REFCOUNT
@ ID_REMAP_SKIP_NEVER_NULL_USAGE
@ ID_REMAP_DO_LIBRARY_POINTERS
@ ID_REMAP_FORCE_OBDATA_IN_EDITMODE
@ ID_REMAP_FORCE_UI_POINTERS
@ ID_REMAP_SKIP_INDIRECT_USAGE
@ ID_REMAP_FORCE_NEVER_NULL_USAGE
@ ID_REMAP_STORE_NEVER_NULL_USAGE
@ ID_REMAP_ALLOW_IDTYPE_MISMATCH
@ ID_REMAP_SKIP_UPDATE_TAGGING
@ ID_REMAP_NO_ORIG_POINTERS_ACCESS
#define ATTR_NONNULL(...)
#define ENUM_OPERATORS(_type, _max)
unsigned long long int uint64_t
void iter(FunctionRef< void(ID *old_id, ID *new_id)> func) const
bool contains_mappings_for_any(IDTypeFilter filter) const
const Set< ID * > & never_null_users() const
CCL_NAMESPACE_BEGIN struct Options options
#define filter
static void add(blender::Map< std::string, std::string > &messages, Message &msg)
Definition msgfmt.cc:222
Definition DNA_ID.h:414