[Bf-blender-cvs] [7974d2bff6f] master: CustomData: Add function to free a named layer

Hans Goudey noreply at git.blender.org
Tue Jun 7 18:00:45 CEST 2022


Commit: 7974d2bff6f363b75c8317cf1dad3e943fd85df6
Author: Hans Goudey
Date:   Tue Jun 7 18:00:18 2022 +0200
Branches: master
https://developer.blender.org/rB7974d2bff6f363b75c8317cf1dad3e943fd85df6

CustomData: Add function to free a named layer

This can be useful to avoid unnecessary boilerplate in various users
of the CustomData API. Split from D14685 and D14769.

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

M	source/blender/blenkernel/BKE_customdata.h
M	source/blender/blenkernel/intern/customdata.cc

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

diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index 993ab476830..a1101c1df44 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -225,6 +225,7 @@ void *CustomData_add_layer_anonymous(struct CustomData *data,
  * In edit-mode, use #EDBM_data_layer_free instead of this function.
  */
 bool CustomData_free_layer(struct CustomData *data, int type, int totelem, int index);
+bool CustomData_free_layer_named(struct CustomData *data, const char *name, const int totelem);
 
 /**
  * Frees the layer index with the give type.
diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index aed570235aa..bb5b2ee0836 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -20,6 +20,7 @@
 #include "BLI_bitmap.h"
 #include "BLI_color.hh"
 #include "BLI_endian_switch.h"
+#include "BLI_index_range.hh"
 #include "BLI_math.h"
 #include "BLI_math_color_blend.h"
 #include "BLI_math_vector.hh"
@@ -27,6 +28,7 @@
 #include "BLI_path_util.h"
 #include "BLI_span.hh"
 #include "BLI_string.h"
+#include "BLI_string_ref.hh"
 #include "BLI_string_utils.h"
 #include "BLI_utildefines.h"
 
@@ -57,6 +59,7 @@
 
 using blender::IndexRange;
 using blender::Span;
+using blender::StringRef;
 using blender::Vector;
 
 /* number of layers to add when growing a CustomData object */
@@ -2899,6 +2902,18 @@ bool CustomData_free_layer(CustomData *data, int type, int totelem, int index)
   return true;
 }
 
+bool CustomData_free_layer_named(CustomData *data, const char *name, const int totelem)
+{
+  for (const int i : IndexRange(data->totlayer)) {
+    const CustomDataLayer &layer = data->layers[i];
+    if (StringRef(layer.name) == name) {
+      CustomData_free_layer(data, layer.type, totelem, i);
+      return true;
+    }
+  }
+  return false;
+}
+
 bool CustomData_free_layer_active(CustomData *data, int type, int totelem)
 {
   const int index = CustomData_get_active_layer_index(data, type);



More information about the Bf-blender-cvs mailing list