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.
This commit is contained in:
parent
9c029a3eb0
commit
7974d2bff6
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue