[Bf-blender-cvs] [a746cef8252] master: Cleanup: Move lib_override.c to C++

Hans Goudey noreply at git.blender.org
Tue May 31 16:21:27 CEST 2022


Commit: a746cef82526528e6037ba205b49ad8c883a0b91
Author: Hans Goudey
Date:   Tue May 31 16:16:45 2022 +0200
Branches: master
https://developer.blender.org/rBa746cef82526528e6037ba205b49ad8c883a0b91

Cleanup: Move lib_override.c to C++

This will allow easier const correctness and use of
nicer data structures like `Vector` and `Map`.

===================================================================

M	source/blender/blenkernel/CMakeLists.txt
R084	source/blender/blenkernel/intern/lib_override.c	source/blender/blenkernel/intern/lib_override.cc

===================================================================

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 8399bc6c144..8dc6f711fae 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -174,7 +174,7 @@ set(SRC
   intern/lib_id_delete.c
   intern/lib_id_eval.c
   intern/lib_id_remapper.cc
-  intern/lib_override.c
+  intern/lib_override.cc
   intern/lib_override_proxy_conversion.c
   intern/lib_query.c
   intern/lib_remap.c
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.cc
similarity index 84%
rename from source/blender/blenkernel/intern/lib_override.c
rename to source/blender/blenkernel/intern/lib_override.cc
index 50c9514e810..fb538eea415 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.cc
@@ -5,8 +5,8 @@
  * \ingroup bke
  */
 
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
 
 #include "CLG_log.h"
 
@@ -90,14 +90,14 @@ 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)
 {
-  if (r_owner_id != NULL) {
+  if (r_owner_id != nullptr) {
     *r_owner_id = id;
   }
   if (id->flag & LIB_EMBEDDED_DATA_LIB_OVERRIDE) {
     const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);
-    if (id_type->owner_get != NULL) {
+    if (id_type->owner_get != nullptr) {
       ID *owner_id = id_type->owner_get(bmain, id);
-      if (r_owner_id != NULL) {
+      if (r_owner_id != nullptr) {
         *r_owner_id = owner_id;
       }
       return owner_id->override_library;
@@ -109,19 +109,20 @@ BLI_INLINE IDOverrideLibrary *lib_override_get(Main *bmain, ID *id, ID **r_owner
 
 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.
+  /* If reference_id is nullptr, we are creating an override template for purely local data.
    * Else, reference *must* be linked data. */
-  BLI_assert(reference_id == NULL || ID_IS_LINKED(reference_id));
-  BLI_assert(local_id->override_library == NULL);
+  BLI_assert(reference_id == nullptr || ID_IS_LINKED(reference_id));
+  BLI_assert(local_id->override_library == nullptr);
 
   ID *ancestor_id;
-  for (ancestor_id = reference_id; ancestor_id != NULL && ancestor_id->override_library != NULL &&
-                                   ancestor_id->override_library->reference != NULL;
+  for (ancestor_id = reference_id;
+       ancestor_id != nullptr && ancestor_id->override_library != nullptr &&
+       ancestor_id->override_library->reference != nullptr;
        ancestor_id = ancestor_id->override_library->reference) {
     /* pass */
   }
 
-  if (ancestor_id != NULL && ancestor_id->override_library != NULL) {
+  if (ancestor_id != nullptr && ancestor_id->override_library != nullptr) {
     /* Original ID has a template, use it! */
     BKE_lib_override_library_copy(local_id, ancestor_id, true);
     if (local_id->override_library->reference != reference_id) {
@@ -133,7 +134,7 @@ IDOverrideLibrary *BKE_lib_override_library_init(ID *local_id, ID *reference_id)
   }
 
   /* Else, generate new empty override. */
-  local_id->override_library = MEM_callocN(sizeof(*local_id->override_library), __func__);
+  local_id->override_library = MEM_cnew<IDOverrideLibrary>(__func__);
   local_id->override_library->reference = reference_id;
   id_us_plus(local_id->override_library->reference);
   local_id->tag &= ~LIB_TAG_OVERRIDE_LIBRARY_REFOK;
@@ -148,20 +149,20 @@ void BKE_lib_override_library_copy(ID *dst_id, const ID *src_id, const bool do_f
 {
   BLI_assert(ID_IS_OVERRIDE_LIBRARY(src_id) || ID_IS_OVERRIDE_LIBRARY_TEMPLATE(src_id));
 
-  if (dst_id->override_library != NULL) {
-    if (src_id->override_library == NULL) {
+  if (dst_id->override_library != nullptr) {
+    if (src_id->override_library == nullptr) {
       BKE_lib_override_library_free(&dst_id->override_library, true);
       return;
     }
 
     BKE_lib_override_library_clear(dst_id->override_library, true);
   }
-  else if (src_id->override_library == NULL) {
+  else if (src_id->override_library == nullptr) {
     /* Virtual overrides of embedded data does not require any extra work. */
     return;
   }
   else {
-    BKE_lib_override_library_init(dst_id, NULL);
+    BKE_lib_override_library_init(dst_id, nullptr);
   }
 
   /* If source is already overriding data, we copy it but reuse its reference for dest ID.
@@ -177,8 +178,10 @@ void BKE_lib_override_library_copy(ID *dst_id, const ID *src_id, const bool do_f
   if (do_full_copy) {
     BLI_duplicatelist(&dst_id->override_library->properties,
                       &src_id->override_library->properties);
-    for (IDOverrideLibraryProperty *op_dst = dst_id->override_library->properties.first,
-                                   *op_src = src_id->override_library->properties.first;
+    for (IDOverrideLibraryProperty *op_dst = static_cast<IDOverrideLibraryProperty *>(
+                                       dst_id->override_library->properties.first),
+                                   *op_src = static_cast<IDOverrideLibraryProperty *>(
+                                       src_id->override_library->properties.first);
          op_dst;
          op_dst = op_dst->next, op_src = op_src->next) {
       lib_override_library_property_copy(op_dst, op_src);
@@ -190,10 +193,10 @@ void BKE_lib_override_library_copy(ID *dst_id, const ID *src_id, const bool do_f
 
 void BKE_lib_override_library_clear(IDOverrideLibrary *override, const bool do_id_user)
 {
-  BLI_assert(override != NULL);
+  BLI_assert(override != nullptr);
 
-  if (!ELEM(NULL, override->runtime, override->runtime->rna_path_to_override_properties)) {
-    BLI_ghash_clear(override->runtime->rna_path_to_override_properties, NULL, NULL);
+  if (!ELEM(nullptr, override->runtime, override->runtime->rna_path_to_override_properties)) {
+    BLI_ghash_clear(override->runtime->rna_path_to_override_properties, nullptr, nullptr);
   }
 
   LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &override->properties) {
@@ -207,20 +210,20 @@ void BKE_lib_override_library_clear(IDOverrideLibrary *override, const bool do_i
   }
 }
 
-void BKE_lib_override_library_free(struct IDOverrideLibrary **override, const bool do_id_user)
+void BKE_lib_override_library_free(IDOverrideLibrary **override, const bool do_id_user)
 {
-  BLI_assert(*override != NULL);
+  BLI_assert(*override != nullptr);
 
-  if ((*override)->runtime != NULL) {
-    if ((*override)->runtime->rna_path_to_override_properties != NULL) {
-      BLI_ghash_free((*override)->runtime->rna_path_to_override_properties, NULL, NULL);
+  if ((*override)->runtime != nullptr) {
+    if ((*override)->runtime->rna_path_to_override_properties != nullptr) {
+      BLI_ghash_free((*override)->runtime->rna_path_to_override_properties, nullptr, nullptr);
     }
     MEM_SAFE_FREE((*override)->runtime);
   }
 
   BKE_lib_override_library_clear(*override, do_id_user);
   MEM_freeN(*override);
-  *override = NULL;
+  *override = nullptr;
 }
 
 static ID *lib_override_library_create_from(Main *bmain,
@@ -232,12 +235,12 @@ static ID *lib_override_library_create_from(Main *bmain,
    * override template, or already an override of some other ref data). */
   ID *local_id = BKE_id_copy_ex(bmain,
                                 reference_id,
-                                NULL,
+                                nullptr,
                                 LIB_ID_COPY_DEFAULT | LIB_ID_COPY_NO_LIB_OVERRIDE |
                                     lib_id_copy_flags);
 
-  if (local_id == NULL) {
-    return NULL;
+  if (local_id == nullptr) {
+    return nullptr;
   }
   id_us_min(local_id);
 
@@ -253,9 +256,9 @@ static ID *lib_override_library_create_from(Main *bmain,
    * data-blocks, just like root node trees or master collections. Therefore, we never need to
    * create overrides for them. We need a way to mark them as overrides though. */
   Key *reference_key;
-  if ((reference_key = BKE_key_from_id(reference_id)) != NULL) {
+  if ((reference_key = BKE_key_from_id(reference_id)) != nullptr) {
     Key *local_key = BKE_key_from_id(local_id);
-    BLI_assert(local_key != NULL);
+    BLI_assert(local_key != nullptr);
     local_key->id.flag |= LIB_EMBEDDED_DATA_LIB_OVERRIDE;
   }
 
@@ -264,7 +267,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(ID *id)
 {
 
   if (!ID_IS_OVERRIDE_LIBRARY(id)) {
@@ -310,9 +313,9 @@ static int foreachid_is_hierarchy_leaf_fn(LibraryIDLinkCallbackData *cb_data)
 {
   ID *id_owner = cb_data->id_owner;
   ID *id = *cb_data->id_pointer;
-  bool *is_leaf = cb_data->user_data;
+  bool *is_leaf = static_cast<bool *>(cb_data->user_data);
 
-  if (id != NULL && ID_IS_OVERRIDE_LIBRARY_REAL(id) &&
+  if (id != nullptr && ID_IS_OVERRIDE_LIBRARY_REAL(id) &&
       id->override_library->hierarchy_root == id_owner->override_library->hierarchy_root) {
     *is_leaf = false;
     return IDWALK_RET_STOP_ITER;
@@ -336,10 +339,10 @@ ID *BKE_lib_override_library_create_from_id(Main *bmain,
                                             ID *reference_id,
                                             const bool do_tagged_remap)
 {
-  BLI_assert(reference_id != NULL);
+  BLI_assert(reference_id != nullptr);
   BLI_assert(ID_IS_LINKED(reference_id));
 
-  ID *local_id = lib_override_library_create_from(bmain, NULL, reference_id, 0);
+  ID *local_id = lib_override_library_create_from(bmain, nullptr, reference_id, 0);
   /* We cannot allow automatic hierarchy resync on this ID, it is highly likely to generate a giant
    * mess in case there are a lot of hidden, non-instantiated, non-properly organized dependencies.
    * Ref T94650. */
@@ -348,10 +351,10 @@ ID *BKE_lib_override_library_create_fro

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list