[Bf-blender-cvs] [790cb287668] master: Curve: Add functions to retrieve const access to spline list

Hans Goudey noreply at git.blender.org
Mon Jun 28 21:16:05 CEST 2021


Commit: 790cb28766813c94733637e46a6527eaf9a04a6b
Author: Hans Goudey
Date:   Mon Jun 28 14:15:58 2021 -0500
Branches: master
https://developer.blender.org/rB790cb28766813c94733637e46a6527eaf9a04a6b

Curve: Add functions to retrieve const access to spline list

While the const correctness of `ListBase` is quite limited, it's helpful
to have a way to retrieve the `Nurb` list from curve object data without
casting away const from the curve.

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

M	source/blender/blenkernel/BKE_curve.h
M	source/blender/blenkernel/intern/curve.c

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

diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index 76a0468df03..c7c5f59cab2 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -121,6 +121,7 @@ void BKE_curve_material_remap(struct Curve *cu, const unsigned int *remap, unsig
 void BKE_curve_smooth_flag_set(struct Curve *cu, const bool use_smooth);
 
 ListBase *BKE_curve_nurbs_get(struct Curve *cu);
+const ListBase *BKE_curve_nurbs_get_for_read(const struct Curve *cu);
 
 int BKE_curve_nurb_vert_index_get(const struct Nurb *nu, const void *vert);
 void BKE_curve_nurb_active_set(struct Curve *cu, const struct Nurb *nu);
@@ -153,6 +154,7 @@ void BKE_curve_editNurb_keyIndex_delCV(struct GHash *keyindex, const void *cv);
 void BKE_curve_editNurb_keyIndex_free(struct GHash **keyindex);
 void BKE_curve_editNurb_free(struct Curve *cu);
 struct ListBase *BKE_curve_editNurbs_get(struct Curve *cu);
+const struct ListBase *BKE_curve_editNurbs_get_for_read(const struct Curve *cu);
 
 void BKE_curve_bevelList_free(struct ListBase *bev);
 void BKE_curve_bevelList_make(struct Object *ob, const struct ListBase *nurbs, bool for_render);
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 341a2b555d8..aaf61e41894 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -442,6 +442,15 @@ ListBase *BKE_curve_editNurbs_get(Curve *cu)
   return NULL;
 }
 
+const ListBase *BKE_curve_editNurbs_get_for_read(const Curve *cu)
+{
+  if (cu->editnurb) {
+    return &cu->editnurb->nurbs;
+  }
+
+  return NULL;
+}
+
 short BKE_curve_type_get(const Curve *cu)
 {
   int type = cu->type;
@@ -2691,7 +2700,7 @@ void BKE_curve_bevelList_make(Object *ob, const ListBase *nurbs, const bool for_
     is_editmode = 1;
   }
 
-  LISTBASE_FOREACH (Nurb *, nu, nurbs) {
+  LISTBASE_FOREACH (const Nurb *, nu, nurbs) {
     if (nu->hide && is_editmode) {
       continue;
     }
@@ -5078,6 +5087,15 @@ ListBase *BKE_curve_nurbs_get(Curve *cu)
   return &cu->nurb;
 }
 
+const ListBase *BKE_curve_nurbs_get_for_read(const Curve *cu)
+{
+  if (cu->editnurb) {
+    return BKE_curve_editNurbs_get_for_read(cu);
+  }
+
+  return &cu->nurb;
+}
+
 void BKE_curve_nurb_active_set(Curve *cu, const Nurb *nu)
 {
   if (nu == NULL) {



More information about the Bf-blender-cvs mailing list