Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2022-02-11 16:46:23 +0300
committerJeroen Bakker <jeroen@blender.org>2022-02-11 16:49:47 +0300
commit811cbb6c0a426243d957fa00f7ddec15b1d4ae62 (patch)
treed2b2fe96ec7e51c542f659e5e1e0bd01c927e5ee
parentf691d4553b3143c132edb665c0844349ee2f0975 (diff)
Helper functions for IDRemapper.
Adds helper functions to debug IDRemapper data structure. `BKE_id_remapper_result_string` converst a given IDRemapperApplyResult to a readable form for logging purposes. `BKE_id_remapper_print` prints out the rules inside a IDRemapper struct.
-rw-r--r--source/blender/blenkernel/BKE_lib_remap.h5
-rw-r--r--source/blender/blenkernel/intern/lib_id_remapper.cc32
2 files changed, 37 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_lib_remap.h b/source/blender/blenkernel/BKE_lib_remap.h
index 5fa524e3fc6..f4136ed5cda 100644
--- a/source/blender/blenkernel/BKE_lib_remap.h
+++ b/source/blender/blenkernel/BKE_lib_remap.h
@@ -204,6 +204,11 @@ void BKE_id_remapper_iter(const struct IDRemapper *id_remapper,
IDRemapperIterFunction func,
void *user_data);
+/** Returns a readable string for the given result. Can be used for debugging purposes. */
+const char *BKE_id_remapper_result_string(const IDRemapperApplyResult result);
+/** Prints out the rules inside the given id_remapper. Can be used for debugging purposes. */
+void BKE_id_remapper_print(const struct IDRemapper *id_remapper);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/intern/lib_id_remapper.cc b/source/blender/blenkernel/intern/lib_id_remapper.cc
index 7347ccc258d..5af482ac088 100644
--- a/source/blender/blenkernel/intern/lib_id_remapper.cc
+++ b/source/blender/blenkernel/intern/lib_id_remapper.cc
@@ -157,4 +157,36 @@ void BKE_id_remapper_iter(const struct IDRemapper *id_remapper,
const blender::bke::id::remapper::IDRemapper *remapper = unwrap(id_remapper);
remapper->iter(func, user_data);
}
+
+const char *BKE_id_remapper_result_string(const IDRemapperApplyResult result)
+{
+ switch (result) {
+ case ID_REMAP_RESULT_SOURCE_NOT_MAPPABLE:
+ return "not_mappable";
+ case ID_REMAP_RESULT_SOURCE_UNAVAILABLE:
+ return "unavailable";
+ case ID_REMAP_RESULT_SOURCE_UNASSIGNED:
+ return "unassigned";
+ case ID_REMAP_RESULT_SOURCE_REMAPPED:
+ return "remapped";
+ default:
+ BLI_assert_unreachable();
+ }
+ return "";
+}
+
+static void id_remapper_print_item_cb(ID *old_id, ID *new_id, void *UNUSED(user_data))
+{
+ if (old_id != nullptr && new_id != nullptr) {
+ printf("Remap %s(%p) to %s(%p)\n", old_id->name, old_id, new_id->name, new_id);
+ }
+ if (old_id != nullptr && new_id == nullptr) {
+ printf("Unassign %s(%p)\n", old_id->name, old_id);
+ }
+}
+
+void BKE_id_remapper_print(const struct IDRemapper *id_remapper)
+{
+ BKE_id_remapper_iter(id_remapper, id_remapper_print_item_cb, nullptr);
+}
}