From 6275541df7e02c40e8c8650bba3104b5df8d34ef Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 26 Sep 2022 13:58:49 +1000 Subject: Cleanup: use ELEM/STR_ELEM/STREQ macros --- source/blender/blenlib/tests/BLI_listbase_test.cc | 4 ++-- source/blender/blenlib/tests/BLI_path_util_test.cc | 2 +- source/blender/editors/render/render_shading.cc | 2 +- source/blender/io/collada/AnimationImporter.cpp | 18 +++++++++++------- source/blender/io/collada/BCAnimationCurve.cpp | 3 +-- source/blender/io/collada/BCSampleData.cpp | 2 +- source/blender/io/collada/MeshImporter.cpp | 14 ++++++++------ source/blender/io/usd/intern/usd_reader_material.cc | 2 +- source/blender/io/usd/intern/usd_writer_material.cc | 4 ++-- .../io/wavefront_obj/tests/obj_importer_tests.cc | 2 +- .../nodes/composite/nodes/node_composite_image.cc | 2 +- 11 files changed, 30 insertions(+), 25 deletions(-) (limited to 'source') diff --git a/source/blender/blenlib/tests/BLI_listbase_test.cc b/source/blender/blenlib/tests/BLI_listbase_test.cc index aa2f885e39d..abdd4f90221 100644 --- a/source/blender/blenlib/tests/BLI_listbase_test.cc +++ b/source/blender/blenlib/tests/BLI_listbase_test.cc @@ -222,7 +222,7 @@ static bool testsort_listbase_array_str_cmp(ListBase *lb, char **arr, int arr_nu link_step = (LinkData *)lb->first; for (i = 0; i < arr_num; i++) { - if (strcmp(arr[i], (char *)link_step->data) != 0) { + if (!STREQ(arr[i], (char *)link_step->data)) { return false; } link_step = link_step->next; @@ -241,7 +241,7 @@ static bool testsort_listbase_sort_is_stable(ListBase *lb, bool forward) link_step = (LinkData *)lb->first; while (link_step && link_step->next) { - if (strcmp((const char *)link_step->data, (const char *)link_step->next->data) == 0) { + if (STREQ((const char *)link_step->data, (const char *)link_step->next->data)) { if ((link_step < link_step->next) != forward) { return false; } diff --git a/source/blender/blenlib/tests/BLI_path_util_test.cc b/source/blender/blenlib/tests/BLI_path_util_test.cc index 5ea6524f835..2d415534693 100644 --- a/source/blender/blenlib/tests/BLI_path_util_test.cc +++ b/source/blender/blenlib/tests/BLI_path_util_test.cc @@ -466,7 +466,7 @@ TEST(path_util, PathFrameStrip) #define PATH_EXTENSION_CHECK(input_path, input_ext, expect_ext) \ { \ const bool ret = BLI_path_extension_check(input_path, input_ext); \ - if (strcmp(input_ext, expect_ext) == 0) { \ + if (STREQ(input_ext, expect_ext)) { \ EXPECT_TRUE(ret); \ } \ else { \ diff --git a/source/blender/editors/render/render_shading.cc b/source/blender/editors/render/render_shading.cc index ba74541be73..6802798adb3 100644 --- a/source/blender/editors/render/render_shading.cc +++ b/source/blender/editors/render/render_shading.cc @@ -1131,7 +1131,7 @@ static int view_layer_add_lightgroup_exec(bContext *C, wmOperator *op) /* Ensure that there are no dots in the name. */ BLI_str_replace_char(name, '.', '_'); LISTBASE_FOREACH (ViewLayerLightgroup *, lightgroup, &view_layer->lightgroups) { - if (strcmp(lightgroup->name, name) == 0) { + if (STREQ(lightgroup->name, name)) { return OPERATOR_CANCELLED; } } diff --git a/source/blender/io/collada/AnimationImporter.cpp b/source/blender/io/collada/AnimationImporter.cpp index 2b56cf188f1..2d872377bbf 100644 --- a/source/blender/io/collada/AnimationImporter.cpp +++ b/source/blender/io/collada/AnimationImporter.cpp @@ -525,9 +525,9 @@ void AnimationImporter::Assign_transform_animations( bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE; /* to check if the no of curves are valid */ - bool xyz = ((tm_type == COLLADAFW::Transformation::TRANSLATE || - tm_type == COLLADAFW::Transformation::SCALE) && - binding->animationClass == COLLADAFW::AnimationList::POSITION_XYZ); + bool xyz = + (ELEM(tm_type, COLLADAFW::Transformation::TRANSLATE, COLLADAFW::Transformation::SCALE) && + binding->animationClass == COLLADAFW::AnimationList::POSITION_XYZ); if (!((!xyz && curves->size() == 1) || (xyz && curves->size() == 3) || is_matrix)) { fprintf(stderr, "expected %d curves, got %d\n", xyz ? 3 : 1, int(curves->size())); @@ -1510,8 +1510,9 @@ void AnimationImporter::find_frames_old(std::vector *frames, /* for each AnimationBinding get the fcurves which animate the transform */ for (uint j = 0; j < bindings.getCount(); j++) { std::vector &curves = curve_map[bindings[j].animation]; - bool xyz = ((nodeTmType == COLLADAFW::Transformation::TRANSLATE || - nodeTmType == COLLADAFW::Transformation::SCALE) && + bool xyz = (ELEM(nodeTmType, + COLLADAFW::Transformation::TRANSLATE, + COLLADAFW::Transformation::SCALE) && bindings[j].animationClass == COLLADAFW::AnimationList::POSITION_XYZ); if ((!xyz && curves.size() == 1) || (xyz && curves.size() == 3) || is_matrix) { @@ -1883,8 +1884,11 @@ bool AnimationImporter::evaluate_animation(COLLADAFW::Transformation *tm, const COLLADAFW::UniqueId &listid = tm->getAnimationList(); COLLADAFW::Transformation::TransformationType type = tm->getTransformationType(); - if (type != COLLADAFW::Transformation::ROTATE && type != COLLADAFW::Transformation::SCALE && - type != COLLADAFW::Transformation::TRANSLATE && type != COLLADAFW::Transformation::MATRIX) { + if (!ELEM(type, + COLLADAFW::Transformation::ROTATE, + COLLADAFW::Transformation::SCALE, + COLLADAFW::Transformation::TRANSLATE, + COLLADAFW::Transformation::MATRIX)) { fprintf(stderr, "animation of transformation %d is not supported yet\n", type); return false; } diff --git a/source/blender/io/collada/BCAnimationCurve.cpp b/source/blender/io/collada/BCAnimationCurve.cpp index 710758bd77b..ac7fa81883a 100644 --- a/source/blender/io/collada/BCAnimationCurve.cpp +++ b/source/blender/io/collada/BCAnimationCurve.cpp @@ -329,8 +329,7 @@ bool BCAnimationCurve::is_transform_curve() const bool BCAnimationCurve::is_rotation_curve() const { std::string channel_type = this->get_channel_type(); - return (channel_type == "rotation" || channel_type == "rotation_euler" || - channel_type == "rotation_quaternion"); + return ELEM(channel_type, "rotation", "rotation_euler", "rotation_quaternion"); } float BCAnimationCurve::get_value(const float frame) diff --git a/source/blender/io/collada/BCSampleData.cpp b/source/blender/io/collada/BCSampleData.cpp index 42b436ec6fb..422ecdc598f 100644 --- a/source/blender/io/collada/BCSampleData.cpp +++ b/source/blender/io/collada/BCSampleData.cpp @@ -51,7 +51,7 @@ bool BCSample::get_value(std::string channel_target, const int array_index, floa else if (channel_type == "scale") { *val = matrix->scale()[array_index]; } - else if (channel_type == "rotation" || channel_type == "rotation_euler") { + else if (ELEM(channel_type, "rotation", "rotation_euler")) { *val = matrix->rotation()[array_index]; } else if (channel_type == "rotation_quaternion") { diff --git a/source/blender/io/collada/MeshImporter.cpp b/source/blender/io/collada/MeshImporter.cpp index ce7eada84d6..6d7593afb8b 100644 --- a/source/blender/io/collada/MeshImporter.cpp +++ b/source/blender/io/collada/MeshImporter.cpp @@ -284,7 +284,7 @@ bool MeshImporter::is_nice_mesh(COLLADAFW::Mesh *mesh) const char *type_str = bc_primTypeToStr(type); /* OpenCollada passes POLYGONS type for */ - if (type == COLLADAFW::MeshPrimitive::POLYLIST || type == COLLADAFW::MeshPrimitive::POLYGONS) { + if (ELEM(type, COLLADAFW::MeshPrimitive::POLYLIST, COLLADAFW::MeshPrimitive::POLYGONS)) { COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons *)mp; COLLADAFW::Polygons::VertexCountArray &vca = mpvc->getGroupedVerticesVertexCountArray(); @@ -324,8 +324,9 @@ bool MeshImporter::is_nice_mesh(COLLADAFW::Mesh *mesh) /* TODO: Add Checker for line syntax here */ } - else if (type != COLLADAFW::MeshPrimitive::TRIANGLES && - type != COLLADAFW::MeshPrimitive::TRIANGLE_FANS) { + else if (!ELEM(type, + COLLADAFW::MeshPrimitive::TRIANGLES, + COLLADAFW::MeshPrimitive::TRIANGLE_FANS)) { fprintf(stderr, "ERROR: Primitive type %s is not supported.\n", type_str); return false; } @@ -688,9 +689,10 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, } } - if (collada_meshtype == COLLADAFW::MeshPrimitive::POLYLIST || - collada_meshtype == COLLADAFW::MeshPrimitive::POLYGONS || - collada_meshtype == COLLADAFW::MeshPrimitive::TRIANGLES) { + if (ELEM(collada_meshtype, + COLLADAFW::MeshPrimitive::POLYLIST, + COLLADAFW::MeshPrimitive::POLYGONS, + COLLADAFW::MeshPrimitive::TRIANGLES)) { COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons *)mp; uint start_index = 0; diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index 3546beb022c..d1af4553083 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -562,7 +562,7 @@ void USDMaterialReader::follow_connection(const pxr::UsdShadeInput &usd_input, /* For now, only convert UsdUVTexture and UsdPrimvarReader_float2 inputs. */ if (shader_id == usdtokens::UsdUVTexture) { - if (strcmp(dest_socket_name, "Normal") == 0) { + if (STREQ(dest_socket_name, "Normal")) { /* The normal texture input requires creating a normal map node. */ float locx = 0.0f; diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index 6862f3835cf..c195bf0e0bd 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -455,7 +455,7 @@ static bNode *traverse_channel(bNodeSocket *input, const short target_type) static bNode *find_bsdf_node(Material *material) { LISTBASE_FOREACH (bNode *, node, &material->nodetree->nodes) { - if (node->type == SH_NODE_BSDF_PRINCIPLED || node->type == SH_NODE_BSDF_DIFFUSE) { + if (ELEM(node->type, SH_NODE_BSDF_PRINCIPLED, SH_NODE_BSDF_DIFFUSE)) { return node; } } @@ -707,7 +707,7 @@ static void export_texture(bNode *node, const pxr::UsdStageRefPtr stage, const bool allow_overwrite) { - if (node->type != SH_NODE_TEX_IMAGE && node->type != SH_NODE_TEX_ENVIRONMENT) { + if (!ELEM(node->type, SH_NODE_TEX_IMAGE, SH_NODE_TEX_ENVIRONMENT)) { return; } diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc index e40f7db0b1f..cd97d5fb485 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -87,7 +87,7 @@ class obj_importer_test : public BlendfileLoadingBaseTest { ASSERT_STREQ(object->id.name, exp.name.c_str()); EXPECT_EQ(object->type, exp.type); EXPECT_V3_NEAR(object->loc, float3(0, 0, 0), 0.0001f); - if (strcmp(object->id.name, "OBCube") != 0) { + if (!STREQ(object->id.name, "OBCube")) { EXPECT_V3_NEAR(object->rot, float3(M_PI_2, 0, 0), 0.0001f); } EXPECT_V3_NEAR(object->scale, float3(1, 1, 1), 0.0001f); diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc index 18be416b735..4b73c1a62fb 100644 --- a/source/blender/nodes/composite/nodes/node_composite_image.cc +++ b/source/blender/nodes/composite/nodes/node_composite_image.cc @@ -851,7 +851,7 @@ class RenderLayerOperation : public NodeOperation { /* Other output passes are not supported for now, so allocate them as invalid. */ for (const bNodeSocket *output : this->node()->output_sockets()) { - if (!STREQ(output->identifier, "Image") && !STREQ(output->identifier, "Alpha")) { + if (!STR_ELEM(output->identifier, "Image", "Alpha")) { get_result(output->identifier).allocate_invalid(); } } -- cgit v1.2.3