[Bf-blender-cvs] [bd128551101] master: Cleanup: Move curve.c to C++

Hans Goudey noreply at git.blender.org
Thu Dec 16 18:23:07 CET 2021


Commit: bd128551101f2c7b815f047695f931e295ed1060
Author: Hans Goudey
Date:   Thu Dec 16 11:22:48 2021 -0600
Branches: master
https://developer.blender.org/rBbd128551101f2c7b815f047695f931e295ed1060

Cleanup: Move curve.c to C++

I need this for a refactor I'm looking into for bounding boxes.
It may be helpful in the future when using `CurveEval` in more places.

Differential Revision: https://developer.blender.org/D13596

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

M	source/blender/blenkernel/CMakeLists.txt
R092	source/blender/blenkernel/intern/curve.c	source/blender/blenkernel/intern/curve.cc

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

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 5a9b5735838..f6e7f1c2473 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -118,7 +118,7 @@ set(SRC
   intern/context.c
   intern/crazyspace.c
   intern/cryptomatte.cc
-  intern/curve.c
+  intern/curve.cc
   intern/curve_bevel.c
   intern/curve_convert.c
   intern/curve_decimate.c
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.cc
similarity index 92%
rename from source/blender/blenkernel/intern/curve.c
rename to source/blender/blenkernel/intern/curve.cc
index 2f1b01316a1..50b7c15774d 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.cc
@@ -21,9 +21,9 @@
  * \ingroup bke
  */
 
-#include <math.h> /* floor */
-#include <stdlib.h>
-#include <string.h>
+#include <cmath> /* floor */
+#include <cstdlib>
+#include <cstring>
 
 #include "MEM_guardedalloc.h"
 
@@ -89,12 +89,12 @@ static void curve_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int
   BLI_listbase_clear(&curve_dst->nurb);
   BKE_nurbList_duplicate(&(curve_dst->nurb), &(curve_src->nurb));
 
-  curve_dst->mat = MEM_dupallocN(curve_src->mat);
+  curve_dst->mat = (Material **)MEM_dupallocN(curve_src->mat);
 
-  curve_dst->str = MEM_dupallocN(curve_src->str);
-  curve_dst->strinfo = MEM_dupallocN(curve_src->strinfo);
-  curve_dst->tb = MEM_dupallocN(curve_src->tb);
-  curve_dst->batch_cache = NULL;
+  curve_dst->str = (char *)MEM_dupallocN(curve_src->str);
+  curve_dst->strinfo = (CharInfo *)MEM_dupallocN(curve_src->strinfo);
+  curve_dst->tb = (TextBox *)MEM_dupallocN(curve_src->tb);
+  curve_dst->batch_cache = nullptr;
 
   curve_dst->bevel_profile = BKE_curveprofile_copy(curve_src->bevel_profile);
 
@@ -104,8 +104,8 @@ static void curve_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int
     curve_dst->key->from = &curve_dst->id;
   }
 
-  curve_dst->editnurb = NULL;
-  curve_dst->editfont = NULL;
+  curve_dst->editnurb = nullptr;
+  curve_dst->editfont = nullptr;
 }
 
 static void curve_free_data(ID *id)
@@ -148,9 +148,9 @@ static void curve_blend_write(BlendWriter *writer, ID *id, const void *id_addres
   Curve *cu = (Curve *)id;
 
   /* Clean up, important in undo case to reduce false detection of changed datablocks. */
-  cu->editnurb = NULL;
-  cu->editfont = NULL;
-  cu->batch_cache = NULL;
+  cu->editnurb = nullptr;
+  cu->editfont = nullptr;
+  cu->batch_cache = nullptr;
 
   /* write LibData */
   BLO_write_id_struct(writer, Curve, id_address, &cu->id);
@@ -188,7 +188,7 @@ static void curve_blend_write(BlendWriter *writer, ID *id, const void *id_addres
     }
   }
 
-  if (cu->bevel_profile != NULL) {
+  if (cu->bevel_profile != nullptr) {
     BKE_curveprofile_blend_write(writer, cu->bevel_profile);
   }
 }
@@ -218,13 +218,13 @@ static void curve_blend_read_data(BlendDataReader *reader, ID *id)
   BLO_read_data_address(reader, &cu->strinfo);
   BLO_read_data_address(reader, &cu->tb);
 
-  if (cu->vfont == NULL) {
+  if (cu->vfont == nullptr) {
     BLO_read_list(reader, &(cu->nurb));
   }
   else {
-    cu->nurb.first = cu->nurb.last = NULL;
+    cu->nurb.first = cu->nurb.last = nullptr;
 
-    TextBox *tb = MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), "TextBoxread");
+    TextBox *tb = (TextBox *)MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), "TextBoxread");
     if (cu->tb) {
       memcpy(tb, cu->tb, cu->totbox * sizeof(TextBox));
       MEM_freeN(cu->tb);
@@ -241,16 +241,16 @@ static void curve_blend_read_data(BlendDataReader *reader, ID *id)
     }
   }
 
-  cu->editnurb = NULL;
-  cu->editfont = NULL;
-  cu->batch_cache = NULL;
+  cu->editnurb = nullptr;
+  cu->editfont = nullptr;
+  cu->batch_cache = nullptr;
 
   LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
     BLO_read_data_address(reader, &nu->bezt);
     BLO_read_data_address(reader, &nu->bp);
     BLO_read_data_address(reader, &nu->knotsu);
     BLO_read_data_address(reader, &nu->knotsv);
-    if (cu->vfont == NULL) {
+    if (cu->vfont == nullptr) {
       nu->charidx = 0;
     }
 
@@ -261,7 +261,7 @@ static void curve_blend_read_data(BlendDataReader *reader, ID *id)
   cu->texflag &= ~CU_AUTOSPACE_EVALUATED;
 
   BLO_read_data_address(reader, &cu->bevel_profile);
-  if (cu->bevel_profile != NULL) {
+  if (cu->bevel_profile != nullptr) {
     BKE_curveprofile_blend_read(reader, cu->bevel_profile);
   }
 }
@@ -304,33 +304,33 @@ static void curve_blend_read_expand(BlendExpander *expander, ID *id)
 }
 
 IDTypeInfo IDType_ID_CU = {
-    .id_code = ID_CU,
-    .id_filter = FILTER_ID_CU,
-    .main_listbase_index = INDEX_ID_CU,
-    .struct_size = sizeof(Curve),
-    .name = "Curve",
-    .name_plural = "curves",
-    .translation_context = BLT_I18NCONTEXT_ID_CURVE,
-    .flags = IDTYPE_FLAGS_APPEND_IS_REUSABLE,
-    .asset_type_info = NULL,
-
-    .init_data = curve_init_data,
-    .copy_data = curve_copy_data,
-    .free_data = curve_free_data,
-    .make_local = NULL,
-    .foreach_id = curve_foreach_id,
-    .foreach_cache = NULL,
-    .foreach_path = NULL,
-    .owner_get = NULL,
-
-    .blend_write = curve_blend_write,
-    .blend_read_data = curve_blend_read_data,
-    .blend_read_lib = curve_blend_read_lib,
-    .blend_read_expand = curve_blend_read_expand,
-
-    .blend_read_undo_preserve = NULL,
-
-    .lib_override_apply_post = NULL,
+    /* id_code */ ID_CU,
+    /* id_filter */ FILTER_ID_CU,
+    /* main_listbase_index */ INDEX_ID_CU,
+    /* struct_size */ sizeof(Curve),
+    /* name */ "Curve",
+    /* name_plural */ "curves",
+    /* translation_context */ BLT_I18NCONTEXT_ID_CURVE,
+    /* flags */ IDTYPE_FLAGS_APPEND_IS_REUSABLE,
+    /* asset_type_info */ nullptr,
+
+    /* init_data */ curve_init_data,
+    /* copy_data */ curve_copy_data,
+    /* free_data */ curve_free_data,
+    /* make_local */ nullptr,
+    /* foreach_id */ curve_foreach_id,
+    /* foreach_cache */ nullptr,
+    /* foreach_path */ nullptr,
+    /* owner_get */ nullptr,
+
+    /* blend_write */ curve_blend_write,
+    /* blend_read_data */ curve_blend_read_data,
+    /* blend_read_lib */ curve_blend_read_lib,
+    /* blend_read_expand */ curve_blend_read_expand,
+
+    /* blend_read_undo_preserve */ nullptr,
+
+    /* lib_override_apply_post */ nullptr,
 };
 
 void BKE_curve_editfont_free(Curve *cu)
@@ -349,21 +349,21 @@ void BKE_curve_editfont_free(Curve *cu)
     }
 
     MEM_freeN(ef);
-    cu->editfont = NULL;
+    cu->editfont = nullptr;
   }
 }
 
 static void curve_editNurb_keyIndex_cv_free_cb(void *val)
 {
-  CVKeyIndex *index = val;
+  CVKeyIndex *index = (CVKeyIndex *)val;
   MEM_freeN(index->orig_cv);
   MEM_freeN(val);
 }
 
 void BKE_curve_editNurb_keyIndex_delCV(GHash *keyindex, const void *cv)
 {
-  BLI_assert(keyindex != NULL);
-  BLI_ghash_remove(keyindex, cv, NULL, curve_editNurb_keyIndex_cv_free_cb);
+  BLI_assert(keyindex != nullptr);
+  BLI_ghash_remove(keyindex, cv, nullptr, curve_editNurb_keyIndex_cv_free_cb);
 }
 
 void BKE_curve_editNurb_keyIndex_free(GHash **keyindex)
@@ -371,8 +371,8 @@ void BKE_curve_editNurb_keyIndex_free(GHash **keyindex)
   if (!(*keyindex)) {
     return;
   }
-  BLI_ghash_free(*keyindex, NULL, curve_editNurb_keyIndex_cv_free_cb);
-  *keyindex = NULL;
+  BLI_ghash_free(*keyindex, nullptr, curve_editNurb_keyIndex_cv_free_cb);
+  *keyindex = nullptr;
 }
 
 void BKE_curve_editNurb_free(Curve *cu)
@@ -381,7 +381,7 @@ void BKE_curve_editNurb_free(Curve *cu)
     BKE_nurbList_free(&cu->editnurb->nurbs);
     BKE_curve_editNurb_keyIndex_free(&cu->editnurb->keyindex);
     MEM_freeN(cu->editnurb);
-    cu->editnurb = NULL;
+    cu->editnurb = nullptr;
   }
 }
 
@@ -395,12 +395,12 @@ void BKE_curve_init(Curve *cu, const short curve_type)
     cu->flag |= CU_FRONT | CU_BACK;
     cu->vfont = cu->vfontb = cu->vfonti = cu->vfontbi = BKE_vfont_builtin_get();
     cu->vfont->id.us += 4;
-    cu->str = MEM_malloc_arrayN(12, sizeof(unsigned char), "str");
+    cu->str = (char *)MEM_malloc_arrayN(12, sizeof(unsigned char), "str");
     BLI_strncpy(cu->str, "Text", 12);
     cu->len = cu->len_char32 = cu->pos = 4;
-    cu->strinfo = MEM_calloc_arrayN(12, sizeof(CharInfo), "strinfo new");
+    cu->strinfo = (CharInfo *)MEM_calloc_arrayN(12, sizeof(CharInfo), "strinfo new");
     cu->totbox = cu->actbox = 1;
-    cu->tb = MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), "textbox");
+    cu->tb = (TextBox *)MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), "textbox");
     cu->tb[0].w = cu->tb[0].h = 0.0;
   }
   else if (cu->type == OB_SURF) {
@@ -408,7 +408,7 @@ void BKE_curve_init(Curve *cu, const short curve_type)
     cu->resolu = 4;
     cu->resolv = 4;
   }
-  cu->bevel_profile = NULL;
+  cu->bevel_profile = nullptr;
 }
 
 Curve *BKE_curve_add(Main *bmain, const char *name, int type)
@@ -416,7 +416,7 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type)
   Curve *cu;
 
   /* We cannot use #BKE_id_new here as we need some custom initialization code. */
-  cu = BKE_libblock_alloc(bmain, ID_CU, name, 0);
+  cu = (Curve *)BKE_libblock_alloc(bmain, ID_CU, name, 0);
 
   BKE_curve_init(cu, type);
 
@@ -429,7 +429,7 @@ ListBase *BKE_curve_editNurbs_get(Curve *cu)
     return &cu->editnurb->nurbs;
   }
 
-  return NULL;
+  return nullptr;
 }
 
 const ListBase *BKE_curve_editNurbs_get_for_read(const Curve *cu)
@@ -438,7 +438,7 @@ const ListBase *BKE_curve_editNurbs_get_for_read(const Curve *cu)
     return &cu->editnurb->nurbs;
   }
 
-  return NULL;
+  return nullptr;
 }
 
 short BKE_curve_type_get(const Curve *cu)
@@ -481,10 +481,10 @@ void BKE_curve_dimension_update(Curve *cu)
 
 void BKE_curve_type_test(Object *ob)
 {
-  ob->type = BKE_curve_type_get(ob->data);
+  ob->type = BKE_curve_type_get((Curve *)ob->data);
 
   if (ob->type == OB_CURVE) {
-    Curve *cu = ob->data;
+    Curve *cu = (Curve *)ob->data;
     if (CU_IS_2D(cu)) {
       BKE_curve_dimension_update(cu);
     }
@@ -495,15 +495,15 @@ BoundBox *BKE_curve_boundbox_get(Object *ob)
 {
   /* This is Object-level data access,
    * DO NOT touch to Mesh's bb, would be totally thread-unsafe. */
-  if (ob->runtime.bb == NULL || ob->runtime.bb->flag & BOUNDBOX_DIRTY) {
-

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list