1
1

Compare commits

...

3 Commits

Author SHA1 Message Date
9e6ff34f33 Add C++ mockup 2022-05-31 14:44:34 +02:00
69fd9dca67 Merge branch 'master' into cleanup-id-override-const 2022-05-31 14:35:20 +02:00
b8b3019630 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.
2022-05-13 16:47:37 +02:00
4 changed files with 24 additions and 15 deletions

View File

@@ -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.

View File

@@ -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.

View File

@@ -2161,7 +2161,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));
}

View File

@@ -88,7 +88,9 @@ BLI_INLINE void lib_override_object_posemode_transfer(ID *id_dst, ID *id_src)
}
/** Get override data for a given ID. Needed because of our beloved shape keys snowflake. */
BLI_INLINE IDOverrideLibrary *lib_override_get(Main *bmain, ID *id, ID **r_owner_id)
BLI_INLINE const IDOverrideLibrary *lib_override_get(const Main *bmain,
const ID *id,
const ID **r_owner_id)
{
if (r_owner_id != NULL) {
*r_owner_id = id;
@@ -107,6 +109,12 @@ BLI_INLINE IDOverrideLibrary *lib_override_get(Main *bmain, ID *id, ID **r_owner
return id->override_library;
}
BLI_INLINE IDOverrideLibrary *lib_override_get(Main *bmain, ID *id, ID **r_owner_id)
{
return const_cast<IDOverrideLibrary *>(
lib_override_get(bmain, id, const_cast<ID **>(r_owner_id)));
}
IDOverrideLibrary *BKE_lib_override_library_init(ID *local_id, ID *reference_id)
{
/* If reference_id is NULL, we are creating an override template for purely local data.
@@ -264,7 +272,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)) {
@@ -278,8 +286,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;
}
@@ -294,11 +302,12 @@ 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;
const ID *override_owner_id;
/* Cast away const, since the data is not changed. */
lib_override_get(bmain, id, &override_owner_id);
return (override_owner_id->override_library->flag & IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED) !=
0;
@@ -320,7 +329,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;
@@ -949,8 +958,8 @@ static void lib_override_overrides_group_tag_recursive(LibOverrideGroupTagData *
continue;
}
Library *reference_lib = lib_override_get(bmain, id_owner, NULL)->reference->lib;
ID *to_id_reference = lib_override_get(bmain, to_id, NULL)->reference;
const Library *reference_lib = lib_override_get(bmain, id_owner, NULL)->reference->lib;
const ID *to_id_reference = lib_override_get(bmain, to_id, NULL)->reference;
if (to_id_reference->lib != reference_lib) {
/* We do not override data-blocks from other libraries, nor do we process them. */
continue;
@@ -1273,7 +1282,7 @@ static ID *lib_override_root_find(Main *bmain, ID *id, const int curr_level, int
}
BLI_assert(id->flag & LIB_EMBEDDED_DATA_LIB_OVERRIDE);
ID *id_owner;
const ID *id_owner;
int best_level_placeholder = 0;
lib_override_get(bmain, id, &id_owner);
return lib_override_root_find(bmain, id_owner, curr_level + 1, &best_level_placeholder);