diff options
author | Hans Goudey <h.goudey@me.com> | 2022-06-07 19:00:18 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-06-07 19:00:30 +0300 |
commit | 7974d2bff6f363b75c8317cf1dad3e943fd85df6 (patch) | |
tree | 9579c2eb5b472bdb15582f5994a2218f4989f5fb /source | |
parent | 9c029a3eb0fa15d7e45e6153af24d7d0fcade201 (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')
-rw-r--r-- | source/blender/blenkernel/BKE_customdata.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/customdata.cc | 15 |
2 files changed, 16 insertions, 0 deletions
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); |