[Bf-blender-cvs] [faafe6e6bc5] blender2.8: Add helper to BKE_library to generate unique string key for an ID.
Bastien Montagne
noreply at git.blender.org
Thu Aug 23 08:51:21 CEST 2018
Commit: faafe6e6bc505c91324e84abf49eadd463a77afe
Author: Bastien Montagne
Date: Thu Aug 23 08:37:32 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBfaafe6e6bc505c91324e84abf49eadd463a77afe
Add helper to BKE_library to generate unique string key for an ID.
Basically just concatenates ID's name (including its IDtype code) and
that library's name, if any. This must give unique string in a given
Main database, suitable for GHash keys e.g.
===================================================================
M source/blender/blenkernel/BKE_library.h
M source/blender/blenkernel/intern/library.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 16e05cd136a..50447e02fe5 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -201,6 +201,8 @@ void BKE_main_lib_objects_recalc_all(struct Main *bmain);
/* (MAX_ID_NAME - 2) + 3 */
void BKE_id_ui_prefix(char name[66 + 1], const struct ID *id);
+char *BKE_id_to_unique_string_key(const struct ID *id);
+
void BKE_library_free(struct Library *lib);
void BKE_library_make_local(
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 08d68f4a480..06207eabe31 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -2535,6 +2535,25 @@ void BKE_id_ui_prefix(char name[MAX_ID_NAME + 1], const ID *id)
strcpy(name + 3, id->name + 2);
}
+/**
+ * Returns an allocated string concatenating ID name (including two-chars type code) and its lib name if any,
+ * which is expected to be unique in a given Main database..
+ */
+char *BKE_id_to_unique_string_key(const struct ID *id)
+{
+ const size_t key_len_base = strlen(id->name) + 1;
+ const size_t key_len_ext = ((id->lib != NULL) ? strlen(id->lib->name) : 0) + 1;
+ const size_t key_len = key_len_base + key_len_ext - 1;
+ char *key = MEM_mallocN(key_len, __func__);
+
+ BLI_strncpy(key, id->name, key_len_base);
+ if (id->lib != NULL) {
+ BLI_strncpy(key + key_len_base - 1, id->lib->name, key_len_ext);
+ }
+
+ return key;
+}
+
void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath)
{
/* in some cases this is used to update the absolute path from the
More information about the Bf-blender-cvs
mailing list