[Bf-blender-cvs] [699b2d98553] master: Code quality: Port recently added utility file to C++

Julian Eisel noreply at git.blender.org
Sat Feb 6 19:32:14 CET 2021


Commit: 699b2d98553f2b0c4bb74dc263d3251600fadd25
Author: Julian Eisel
Date:   Sat Feb 6 19:25:11 2021 +0100
Branches: master
https://developer.blender.org/rB699b2d98553f2b0c4bb74dc263d3251600fadd25

Code quality: Port recently added utility file to C++

It seems generally preferred to have new files be created with C++.
The only reason I didn't do that when I initially created the files is that I
was unsure about some C-API aspect.

Also use nullptr instead of NULL.

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

M	source/blender/editors/util/CMakeLists.txt
R091	source/blender/editors/util/ed_util_ops.c	source/blender/editors/util/ed_util_ops.cc

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

diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt
index 0aab3810254..38655b8490e 100644
--- a/source/blender/editors/util/CMakeLists.txt
+++ b/source/blender/editors/util/CMakeLists.txt
@@ -39,7 +39,7 @@ set(SRC
   ed_transverts.c
   ed_util.c
   ed_util_imbuf.c
-  ed_util_ops.c
+  ed_util_ops.cc
   gizmo_utils.c
   numinput.c
   select_utils.c
diff --git a/source/blender/editors/util/ed_util_ops.c b/source/blender/editors/util/ed_util_ops.cc
similarity index 91%
rename from source/blender/editors/util/ed_util_ops.c
rename to source/blender/editors/util/ed_util_ops.cc
index bb531b11b12..cb7ff9f3a63 100644
--- a/source/blender/editors/util/ed_util_ops.c
+++ b/source/blender/editors/util/ed_util_ops.cc
@@ -22,6 +22,9 @@
 
 #include <string.h>
 
+#include "DNA_space_types.h"
+#include "DNA_windowmanager_types.h"
+
 #include "BLI_fileops.h"
 #include "BLI_utildefines.h"
 
@@ -33,9 +36,6 @@
 
 #include "BLT_translation.h"
 
-#include "DNA_space_types.h"
-#include "DNA_windowmanager_types.h"
-
 #include "ED_render.h"
 #include "ED_undo.h"
 #include "ED_util.h"
@@ -56,7 +56,7 @@ static bool lib_id_preview_editing_poll(bContext *C)
   const PointerRNA idptr = CTX_data_pointer_get(C, "id");
   BLI_assert(!idptr.data || RNA_struct_is_ID(idptr.type));
 
-  const ID *id = idptr.data;
+  const ID *id = (ID *)idptr.data;
   if (!id) {
     return false;
   }
@@ -88,11 +88,11 @@ static int lib_id_load_custom_preview_exec(bContext *C, wmOperator *op)
   }
 
   PointerRNA idptr = CTX_data_pointer_get(C, "id");
-  ID *id = idptr.data;
+  ID *id = (ID *)idptr.data;
 
   BKE_previewimg_id_custom_set(id, path);
 
-  WM_event_add_notifier(C, NC_ASSET, NULL);
+  WM_event_add_notifier(C, NC_ASSET, nullptr);
 
   return OPERATOR_FINISHED;
 }
@@ -123,7 +123,7 @@ static void ED_OT_lib_id_load_custom_preview(wmOperatorType *ot)
 static int lib_id_generate_preview_exec(bContext *C, wmOperator *UNUSED(op))
 {
   PointerRNA idptr = CTX_data_pointer_get(C, "id");
-  ID *id = idptr.data;
+  ID *id = (ID *)idptr.data;
 
   ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
 
@@ -131,9 +131,9 @@ static int lib_id_generate_preview_exec(bContext *C, wmOperator *UNUSED(op))
   if (preview) {
     BKE_previewimg_clear(preview);
   }
-  UI_icon_render_id(C, NULL, id, ICON_SIZE_PREVIEW, true);
+  UI_icon_render_id(C, nullptr, id, ICON_SIZE_PREVIEW, true);
 
-  WM_event_add_notifier(C, NC_ASSET, NULL);
+  WM_event_add_notifier(C, NC_ASSET, nullptr);
 
   return OPERATOR_FINISHED;
 }
@@ -169,15 +169,15 @@ static int lib_id_fake_user_toggle_exec(bContext *C, wmOperator *op)
     idptr = RNA_property_pointer_get(&pprop.ptr, pprop.prop);
   }
 
-  if ((pprop.prop == NULL) || RNA_pointer_is_null(&idptr) || !RNA_struct_is_ID(idptr.type)) {
+  if ((pprop.prop == nullptr) || RNA_pointer_is_null(&idptr) || !RNA_struct_is_ID(idptr.type)) {
     BKE_report(
         op->reports, RPT_ERROR, "Incorrect context for running data-block fake user toggling");
     return OPERATOR_CANCELLED;
   }
 
-  ID *id = idptr.data;
+  ID *id = (ID *)idptr.data;
 
-  if ((id->lib != NULL) || (ELEM(GS(id->name), ID_GR, ID_SCE, ID_SCR, ID_TXT, ID_OB, ID_WS))) {
+  if ((id->lib != nullptr) || (ELEM(GS(id->name), ID_GR, ID_SCE, ID_SCR, ID_TXT, ID_OB, ID_WS))) {
     BKE_report(op->reports, RPT_ERROR, "Data-block type does not support fake user");
     return OPERATOR_CANCELLED;
   }
@@ -217,14 +217,14 @@ static int lib_id_unlink_exec(bContext *C, wmOperator *op)
     idptr = RNA_property_pointer_get(&pprop.ptr, pprop.prop);
   }
 
-  if ((pprop.prop == NULL) || RNA_pointer_is_null(&idptr) || !RNA_struct_is_ID(idptr.type)) {
+  if ((pprop.prop == nullptr) || RNA_pointer_is_null(&idptr) || !RNA_struct_is_ID(idptr.type)) {
     BKE_report(
         op->reports, RPT_ERROR, "Incorrect context for running data-block fake user toggling");
     return OPERATOR_CANCELLED;
   }
 
   memset(&idptr, 0, sizeof(idptr));
-  RNA_property_pointer_set(&pprop.ptr, pprop.prop, idptr, NULL);
+  RNA_property_pointer_set(&pprop.ptr, pprop.prop, idptr, nullptr);
   RNA_property_update(C, &pprop.ptr, pprop.prop);
 
   return OPERATOR_FINISHED;



More information about the Bf-blender-cvs mailing list