From df664fa6d54ff2bd0d8f218466985986ce522718 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 8 May 2013 12:57:18 +0000 Subject: use bool for customdata functions. --- source/blender/blenkernel/BKE_customdata.h | 26 +++++----- source/blender/blenkernel/intern/customdata.c | 73 ++++++++++++++------------- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index a51de2d4ae1..ffab95ea3f5 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -80,14 +80,14 @@ void customData_mask_layers__print(CustomDataMask mask); * Checks if the layer at physical offset \a layer_n (in data->layers) support math * the below operations. */ -int CustomData_layer_has_math(struct CustomData *data, int layer_n); -int CustomData_layer_has_interp(struct CustomData *data, int layer_n); +bool CustomData_layer_has_math(struct CustomData *data, int layer_n); +bool CustomData_layer_has_interp(struct CustomData *data, int layer_n); /** * Checks if any of the customdata layers has math. */ -int CustomData_has_math(struct CustomData *data); -int CustomData_has_interp(struct CustomData *data); +bool CustomData_has_math(struct CustomData *data); +bool CustomData_has_interp(struct CustomData *data); /* copies the "value" (e.g. mloopuv uv or mloopcol colors) from one block to * another, while not overwriting anything else (e.g. flags). probably only @@ -97,7 +97,7 @@ void CustomData_data_copy_value(int type, void *source, void *dest); /* compares if data1 is equal to data2. type is a valid CustomData type * enum (e.g. CD_MLOOPUV). the layer type's equal function is used to compare * the data, if it exists, otherwise memcmp is used.*/ -int CustomData_data_equals(int type, void *data1, void *data2); +bool CustomData_data_equals(int type, void *data1, void *data2); void CustomData_data_initminmax(int type, void *min, void *max); void CustomData_data_dominmax(int type, void *data, void *min, void *max); void CustomData_data_multiply(int type, void *data, float fac); @@ -149,20 +149,20 @@ void *CustomData_add_layer_named(struct CustomData *data, int type, int alloctyp * * in editmode, use EDBM_data_layer_free instead of this function */ -int CustomData_free_layer(struct CustomData *data, int type, int totelem, int index); +bool CustomData_free_layer(struct CustomData *data, int type, int totelem, int index); /* frees the layer index with the give type. * returns 1 on succes, 0 if no layer with the given type is found * * in editmode, use EDBM_data_layer_free instead of this function */ -int CustomData_free_layer_active(struct CustomData *data, int type, int totelem); +bool CustomData_free_layer_active(struct CustomData *data, int type, int totelem); /* same as above, but free all layers with type */ void CustomData_free_layers(struct CustomData *data, int type, int totelem); /* returns 1 if a layer with the specified type exists */ -int CustomData_has_layer(const struct CustomData *data, int type); +bool CustomData_has_layer(const struct CustomData *data, int type); /* returns the number of layers with this type */ int CustomData_number_of_layers(const struct CustomData *data, int type); @@ -172,7 +172,7 @@ int CustomData_number_of_layers(const struct CustomData *data, int type); void *CustomData_duplicate_referenced_layer(struct CustomData *data, const int type, const int totelem); void *CustomData_duplicate_referenced_layer_named(struct CustomData *data, const int type, const char *name, const int totelem); -int CustomData_is_referenced_layer(struct CustomData *data, int type); +bool CustomData_is_referenced_layer(struct CustomData *data, int type); /* set the CD_FLAG_NOCOPY flag in custom data layers where the mask is * zero for the layer type, so only layer types specified by the mask @@ -240,7 +240,7 @@ void *CustomData_bmesh_get_n(const struct CustomData *data, void *block, int typ */ void *CustomData_bmesh_get_layer_n(const struct CustomData *data, void *block, int n); -int CustomData_set_layer_name(const struct CustomData *data, int type, int n, const char *name); +bool CustomData_set_layer_name(const struct CustomData *data, int type, int n, const char *name); /* gets a pointer to the active or first layer of type * returns NULL if there is no layer of type @@ -321,7 +321,7 @@ int CustomData_sizeof(int type); /* get the name of a layer type */ const char *CustomData_layertype_name(int type); -int CustomData_layertype_is_singleton(int type); +bool CustomData_layertype_is_singleton(int type); /* make sure the name of layer at index is unique */ void CustomData_set_layer_unique_name(struct CustomData *data, int index); @@ -330,7 +330,7 @@ void CustomData_validate_layer_name(const struct CustomData *data, int type, con /* for file reading compatibility, returns false if the layer was freed, * only after this test passes, layer->data should be assigned */ -int CustomData_verify_versions(struct CustomData *data, int index); +bool CustomData_verify_versions(struct CustomData *data, int index); /*BMesh specific customdata stuff*/ void CustomData_to_bmeshpoly(struct CustomData *fdata, struct CustomData *pdata, @@ -346,7 +346,7 @@ void CustomData_external_add(struct CustomData *data, struct ID *id, int type, int totelem, const char *filename); void CustomData_external_remove(struct CustomData *data, struct ID *id, int type, int totelem); -int CustomData_external_test(struct CustomData *data, int type); +bool CustomData_external_test(struct CustomData *data, int type); void CustomData_external_write(struct CustomData *data, struct ID *id, CustomDataMask mask, int totelem, int free); diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 2118bbcd42b..b0ecec21049 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -130,7 +130,7 @@ typedef struct LayerTypeInfo { void (*set_default)(void *data, int count); /** functions necessary for geometry collapse */ - int (*equal)(void *data1, void *data2); + bool (*equal)(void *data1, void *data2); void (*multiply)(void *data, float fac); void (*initminmax)(void *min, void *max); void (*add)(void *data1, void *data2); @@ -608,7 +608,7 @@ static void layerCopyValue_mloopcol(void *source, void *dest) m2->a = m1->a; } -static int layerEqual_mloopcol(void *data1, void *data2) +static bool layerEqual_mloopcol(void *data1, void *data2) { MLoopCol *m1 = data1, *m2 = data2; float r, g, b, a; @@ -736,7 +736,7 @@ static void layerCopyValue_mloopuv(void *source, void *dest) copy_v2_v2(luv2->uv, luv1->uv); } -static int layerEqual_mloopuv(void *data1, void *data2) +static bool layerEqual_mloopuv(void *data1, void *data2) { MLoopUV *luv1 = data1, *luv2 = data2; @@ -808,7 +808,7 @@ static void layerCopyValue_mloop_origspace(void *source, void *dest) copy_v2_v2(luv2->uv, luv1->uv); } -static int layerEqual_mloop_origspace(void *data1, void *data2) +static bool layerEqual_mloop_origspace(void *data1, void *data2) { OrigSpaceLoop *luv1 = data1, *luv2 = data2; @@ -1714,7 +1714,7 @@ void *CustomData_add_layer_named(CustomData *data, int type, int alloctype, } -int CustomData_free_layer(CustomData *data, int type, int totelem, int index) +bool CustomData_free_layer(CustomData *data, int type, int totelem, int index) { int i; @@ -1748,7 +1748,7 @@ int CustomData_free_layer(CustomData *data, int type, int totelem, int index) return 1; } -int CustomData_free_layer_active(CustomData *data, int type, int totelem) +bool CustomData_free_layer_active(CustomData *data, int type, int totelem) { int index = 0; index = CustomData_get_active_layer_index(data, type); @@ -1763,7 +1763,7 @@ void CustomData_free_layers(CustomData *data, int type, int totelem) CustomData_free_layer_active(data, type, totelem); } -int CustomData_has_layer(const CustomData *data, int type) +bool CustomData_has_layer(const CustomData *data, int type) { return (CustomData_get_layer_index(data, type) != -1); } @@ -1844,7 +1844,7 @@ void *CustomData_duplicate_referenced_layer_named(struct CustomData *data, return layer->data; } -int CustomData_is_referenced_layer(struct CustomData *data, int type) +bool CustomData_is_referenced_layer(struct CustomData *data, int type) { CustomDataLayer *layer; int layer_index; @@ -2129,17 +2129,17 @@ int CustomData_get_n_offset(const CustomData *data, int type, int n) return data->layers[layer_index].offset; } -int CustomData_set_layer_name(const CustomData *data, int type, int n, const char *name) +bool CustomData_set_layer_name(const CustomData *data, int type, int n, const char *name) { /* get the layer index of the first layer of type */ int layer_index = CustomData_get_layer_index_n(data, type, n); - if (layer_index < 0) return 0; - if (!name) return 0; + if (layer_index < 0) return false; + if (!name) return false; BLI_strncpy(data->layers[layer_index].name, name, sizeof(data->layers[layer_index].name)); - return 1; + return true; } void *CustomData_set_layer(const CustomData *data, int type, void *ptr) @@ -2514,56 +2514,56 @@ void *CustomData_bmesh_get_layer_n(const CustomData *data, void *block, int n) return (char *)block + data->layers[n].offset; } -int CustomData_layer_has_math(struct CustomData *data, int layer_n) +bool CustomData_layer_has_math(struct CustomData *data, int layer_n) { const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[layer_n].type); if (typeInfo->equal && typeInfo->add && typeInfo->multiply && typeInfo->initminmax && typeInfo->dominmax) { - return TRUE; + return true; } - return FALSE; + return false; } -int CustomData_layer_has_interp(struct CustomData *data, int layer_n) +bool CustomData_layer_has_interp(struct CustomData *data, int layer_n) { const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[layer_n].type); if (typeInfo->interp) { - return TRUE; + return true; } - return FALSE; + return false; } -int CustomData_has_math(struct CustomData *data) +bool CustomData_has_math(struct CustomData *data) { int i; /* interpolates a layer at a time */ for (i = 0; i < data->totlayer; ++i) { if (CustomData_layer_has_math(data, i)) { - return TRUE; + return true; } } - return FALSE; + return false; } -int CustomData_has_interp(struct CustomData *data) +bool CustomData_has_interp(struct CustomData *data) { int i; /* interpolates a layer at a time */ for (i = 0; i < data->totlayer; ++i) { if (CustomData_layer_has_interp(data, i)) { - return TRUE; + return true; } } - return FALSE; + return false; } /* copies the "value" (e.g. mloopuv uv or mloopcol colors) from one block to @@ -2580,7 +2580,7 @@ void CustomData_data_copy_value(int type, void *source, void *dest) memcpy(dest, source, typeInfo->size); } -int CustomData_data_equals(int type, void *data1, void *data2) +bool CustomData_data_equals(int type, void *data1, void *data2) { const LayerTypeInfo *typeInfo = layerType_getInfo(type); @@ -2861,17 +2861,17 @@ const char *CustomData_layertype_name(int type) /** * Can only ever be one of these. */ -int CustomData_layertype_is_singleton(int type) +bool CustomData_layertype_is_singleton(int type) { const LayerTypeInfo *typeInfo = layerType_getInfo(type); return typeInfo->defaultname == NULL; } -static int CustomData_is_property_layer(int type) +static bool CustomData_is_property_layer(int type) { if ((type == CD_PROP_FLT) || (type == CD_PROP_INT) || (type == CD_PROP_STR)) - return 1; - return 0; + return true; + return false; } static bool cd_layer_find_dupe(CustomData *data, const char *name, int type, int index) @@ -2941,14 +2941,15 @@ void CustomData_validate_layer_name(const CustomData *data, int type, const char } } -int CustomData_verify_versions(struct CustomData *data, int index) +bool CustomData_verify_versions(struct CustomData *data, int index) { const LayerTypeInfo *typeInfo; CustomDataLayer *layer = &data->layers[index]; - int i, keeplayer = 1; + bool keeplayer = true; + int i; if (layer->type >= CD_NUMTYPES) { - keeplayer = 0; /* unknown layer type from future version */ + keeplayer = false; /* unknown layer type from future version */ } else { typeInfo = layerType_getInfo(layer->type); @@ -2956,7 +2957,7 @@ int CustomData_verify_versions(struct CustomData *data, int index) if (!typeInfo->defaultname && (index > 0) && data->layers[index - 1].type == layer->type) { - keeplayer = 0; /* multiple layers of which we only support one */ + keeplayer = false; /* multiple layers of which we only support one */ } } @@ -3229,16 +3230,16 @@ void CustomData_external_remove(CustomData *data, ID *id, int type, int totelem) } } -int CustomData_external_test(CustomData *data, int type) +bool CustomData_external_test(CustomData *data, int type) { CustomDataLayer *layer; int layer_index; layer_index = CustomData_get_active_layer_index(data, type); - if (layer_index < 0) return 0; + if (layer_index < 0) return false; layer = &data->layers[layer_index]; - return (layer->flag & CD_FLAG_EXTERNAL); + return (layer->flag & CD_FLAG_EXTERNAL) != 0; } #if 0 -- cgit v1.2.3