Blender V5.3
lib_id_remapper.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_ID.h"
10
11#include "BKE_idtype.hh"
12#include "BKE_lib_id.hh"
13#include "BKE_lib_remap.hh"
14
15namespace blender::bke::id {
16
17void IDRemapper::add(ID *old_id, ID *new_id)
18{
19 BLI_assert(old_id != nullptr);
20 BLI_assert(new_id == nullptr || this->allow_idtype_mismatch ||
21 (GS(old_id->name) == GS(new_id->name)));
23
24 mappings_.add(old_id, new_id);
25 source_types_ |= BKE_idtype_idcode_to_idfilter(GS(old_id->name));
26}
27
28void IDRemapper::add_overwrite(ID *old_id, ID *new_id)
29{
30 BLI_assert(old_id != nullptr);
31 BLI_assert(new_id == nullptr || this->allow_idtype_mismatch ||
32 (GS(old_id->name) == GS(new_id->name)));
34
35 mappings_.add_overwrite(old_id, new_id);
36 source_types_ |= BKE_idtype_idcode_to_idfilter(GS(old_id->name));
37}
38
41 const ID *id_self) const
42{
43 if (!mappings_.contains(id)) {
45 }
46 const ID *new_id = mappings_.lookup(id);
47 if ((options & ID_REMAP_APPLY_UNMAP_WHEN_REMAPPING_TO_SELF) != 0 && id_self == new_id) {
48 new_id = nullptr;
49 }
50 if (new_id == nullptr) {
52 }
53
55}
56
59 ID *id_self) const
60{
61 BLI_assert(r_id_ptr != nullptr);
63 ((options & ID_REMAP_APPLY_UNMAP_WHEN_REMAPPING_TO_SELF) == 0 || id_self != nullptr),
64 "ID_REMAP_APPLY_WHEN_REMAPPING_TO_SELF requires a non-null `id_self` parameter.");
65
66 if (*r_id_ptr == nullptr) {
68 }
69
70 ID *const *new_id = mappings_.lookup_ptr(*r_id_ptr);
71 if (new_id == nullptr) {
73 }
74
76 id_us_min(*r_id_ptr);
77 }
78
79 *r_id_ptr = *new_id;
80 if (options & ID_REMAP_APPLY_UNMAP_WHEN_REMAPPING_TO_SELF && *r_id_ptr == id_self) {
81 *r_id_ptr = nullptr;
82 }
83 if (*r_id_ptr == nullptr) {
85 }
86
88 /* Do not handle ID_TAG_INDIRECT/ID_TAG_EXTERN here. */
89 id_us_plus_no_lib(*r_id_ptr);
90 }
91
93 id_us_ensure_real(*r_id_ptr);
94 }
96}
97
99{
100 switch (result) {
102 return "not_mappable";
104 return "unavailable";
106 return "unassigned";
108 return "remapped";
109 }
111 return "";
112}
113
115{
116 this->iter([](ID *old_id, ID *new_id) {
117 if (old_id != nullptr && new_id != nullptr) {
118 printf("Remap %s(%p) to %s(%p)\n", old_id->name, old_id, new_id->name, new_id);
119 }
120 if (old_id != nullptr && new_id == nullptr) {
121 printf("Unassign %s(%p)\n", old_id->name, old_id);
122 }
123 });
124}
125
126} // namespace blender::bke::id
ID and Library types, which are fundamental for SDNA.
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
IDRemapperApplyResult get_mapping_result(ID *id, IDRemapperApplyOptions options, const ID *id_self) const
IDRemapperApplyResult apply(ID **r_id_ptr, IDRemapperApplyOptions options, ID *id_self=nullptr) const
static StringRefNull result_to_string(const IDRemapperApplyResult result)
void iter(FunctionRef< void(ID *old_id, ID *new_id)> func) const
void add(ID *old_id, ID *new_id)
void add_overwrite(ID *old_id, ID *new_id)
CCL_NAMESPACE_BEGIN struct Options options
@ ID_REMAP_RESULT_SOURCE_UNASSIGNED
@ ID_REMAP_RESULT_SOURCE_UNAVAILABLE
@ ID_REMAP_RESULT_SOURCE_REMAPPED
@ ID_REMAP_RESULT_SOURCE_NOT_MAPPABLE
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
uint64_t BKE_idtype_idcode_to_idfilter(short idcode)
Definition idtype.cc:473
void id_us_ensure_real(ID *id)
Definition lib_id.cc:388
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ ID_REMAP_APPLY_ENSURE_REAL
@ ID_REMAP_APPLY_UNMAP_WHEN_REMAPPING_TO_SELF
@ ID_REMAP_APPLY_UPDATE_REFCOUNT
void id_us_plus_no_lib(ID *id)
Definition lib_id.cc:417
void id_us_min(ID *id)
Definition lib_id.cc:441
char name[258]
Definition DNA_ID.h:433