Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-06-07 19:00:18 +0300
committerHans Goudey <h.goudey@me.com>2022-06-07 19:00:30 +0300
commit7974d2bff6f363b75c8317cf1dad3e943fd85df6 (patch)
tree9579c2eb5b472bdb15582f5994a2218f4989f5fb /source/blender/blenkernel/intern/customdata.cc
parent9c029a3eb0fa15d7e45e6153af24d7d0fcade201 (diff)
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.
Diffstat (limited to 'source/blender/blenkernel/intern/customdata.cc')
-rw-r--r--source/blender/blenkernel/intern/customdata.cc15
1 files changed, 15 insertions, 0 deletions
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);