[Bf-blender-cvs] [b8b30196301] cleanup-id-override-const: Cleanup: Improve const correctness of ID functions
Hans Goudey
noreply at git.blender.org
Tue May 31 14:45:51 CEST 2022
Commit: b8b301963018c8dc374cfd4df2d2387199d93fbb
Author: Hans Goudey
Date: Fri May 13 16:47:37 2022 +0200
Branches: cleanup-id-override-const
https://developer.blender.org/rBb8b301963018c8dc374cfd4df2d2387199d93fbb
Cleanup: Improve const correctness of ID functions
These functions don't change their inputs, so they can be const,
which is a bit more intuitive and clean to use for callers.
===================================================================
M source/blender/blenkernel/BKE_lib_id.h
M source/blender/blenkernel/BKE_lib_override.h
M source/blender/blenkernel/intern/lib_id.c
M source/blender/blenkernel/intern/lib_override.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_lib_id.h b/source/blender/blenkernel/BKE_lib_id.h
index 504ab47c1c5..beac608a138 100644
--- a/source/blender/blenkernel/BKE_lib_id.h
+++ b/source/blender/blenkernel/BKE_lib_id.h
@@ -603,7 +603,7 @@ bool BKE_id_can_be_asset(const struct ID *id);
* we should either cache that status info also in virtual override IDs, or address the
* long-standing TODO of getting an efficient 'owner_id' access for all embedded ID types.
*/
-bool BKE_id_is_editable(struct Main *bmain, struct ID *id);
+bool BKE_id_is_editable(const struct Main *bmain, const struct ID *id);
/**
* Returns ordered list of data-blocks for display in the UI.
diff --git a/source/blender/blenkernel/BKE_lib_override.h b/source/blender/blenkernel/BKE_lib_override.h
index dfb2b900b10..f8d98154947 100644
--- a/source/blender/blenkernel/BKE_lib_override.h
+++ b/source/blender/blenkernel/BKE_lib_override.h
@@ -62,12 +62,12 @@ void BKE_lib_override_library_free(struct IDOverrideLibrary **override, bool do_
/**
* Check if given ID has some override rules that actually indicate the user edited it.
*/
-bool BKE_lib_override_library_is_user_edited(struct ID *id);
+bool BKE_lib_override_library_is_user_edited(const struct ID *id);
/**
* Check if given ID is a system override.
*/
-bool BKE_lib_override_library_is_system_defined(struct Main *bmain, struct ID *id);
+bool BKE_lib_override_library_is_system_defined(const struct Main *bmain, const struct ID *id);
/**
* Check if given ID is a leaf in its liboverride hierarchy (i.e. if it does not use any other
@@ -75,7 +75,7 @@ bool BKE_lib_override_library_is_system_defined(struct Main *bmain, struct ID *i
*
* NOTE: Embedded IDs of override IDs are not considered as leaves.
*/
-bool BKE_lib_override_library_is_hierarchy_leaf(struct Main *bmain, struct ID *id);
+bool BKE_lib_override_library_is_hierarchy_leaf(const struct Main *bmain, const struct ID *id);
/**
* Create an overridden local copy of linked reference.
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 27427b1fb44..2bc2a3e42be 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -2165,7 +2165,7 @@ bool BKE_id_can_be_asset(const ID *id)
BKE_idtype_idcode_is_linkable(GS(id->name));
}
-bool BKE_id_is_editable(Main *bmain, ID *id)
+bool BKE_id_is_editable(const Main *bmain, const ID *id)
{
return !(ID_IS_LINKED(id) || BKE_lib_override_library_is_system_defined(bmain, id));
}
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index 9dc64365f0c..4acf5f67d51 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -249,7 +249,7 @@ static ID *lib_override_library_create_from(Main *bmain,
/* TODO: This could be simplified by storing a flag in #IDOverrideLibrary
* during the diffing process? */
-bool BKE_lib_override_library_is_user_edited(struct ID *id)
+bool BKE_lib_override_library_is_user_edited(const ID *id)
{
if (!ID_IS_OVERRIDE_LIBRARY(id)) {
@@ -263,8 +263,8 @@ bool BKE_lib_override_library_is_user_edited(struct ID *id)
return false;
}
- LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &id->override_library->properties) {
- LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &op->operations) {
+ LISTBASE_FOREACH (const IDOverrideLibraryProperty *, op, &id->override_library->properties) {
+ LISTBASE_FOREACH (const IDOverrideLibraryPropertyOperation *, opop, &op->operations) {
if ((opop->flag & IDOVERRIDE_LIBRARY_FLAG_IDPOINTER_MATCH_REFERENCE) != 0) {
continue;
}
@@ -279,12 +279,13 @@ bool BKE_lib_override_library_is_user_edited(struct ID *id)
return false;
}
-bool BKE_lib_override_library_is_system_defined(Main *bmain, ID *id)
+bool BKE_lib_override_library_is_system_defined(const Main *bmain, const ID *id)
{
if (ID_IS_OVERRIDE_LIBRARY(id)) {
ID *override_owner_id;
- lib_override_get(bmain, id, &override_owner_id);
+ /* Cast away const, since the data is not changed. */
+ lib_override_get((Main *)bmain, (ID *)id, &override_owner_id);
return (override_owner_id->override_library->flag & IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED) !=
0;
}
@@ -305,7 +306,7 @@ static int foreachid_is_hierarchy_leaf_fn(LibraryIDLinkCallbackData *cb_data)
return IDWALK_RET_NOP;
}
-bool BKE_lib_override_library_is_hierarchy_leaf(Main *bmain, ID *id)
+bool BKE_lib_override_library_is_hierarchy_leaf(const Main *bmain, const ID *id)
{
if (ID_IS_OVERRIDE_LIBRARY_REAL(id)) {
bool is_leaf = true;
More information about the Bf-blender-cvs
mailing list