From d823ec16079d0be731c1fac23da6fc1f97b07dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 7 Feb 2022 21:45:20 +0100 Subject: [PATCH] sceneconverter: use the fancy new Utility::String::parseNumberSequence(). We don't have a string-to-int API that can take non-null-terminated string views yet, but we have this. And that's a much better fit in this case. This stripped further 4 kB off the release binary size (178 kB before, 158 after). Fully inlined STL containers and algorithms are a very good idea, yes. --- src/Magnum/SceneTools/sceneconverter.cpp | 25 +++++++++++------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Magnum/SceneTools/sceneconverter.cpp b/src/Magnum/SceneTools/sceneconverter.cpp index 7bff74842..b67b7102f 100644 --- a/src/Magnum/SceneTools/sceneconverter.cpp +++ b/src/Magnum/SceneTools/sceneconverter.cpp @@ -23,7 +23,6 @@ DEALINGS IN THE SOFTWARE. */ -#include #include #include #include @@ -83,7 +82,8 @@ information. @code{.sh} magnum-sceneconverter [-h|--help] [-I|--importer IMPORTER] [-I|--converter CONVERTER]... [--plugin-dir DIR] [--map] - [--remove-duplicates] [--remove-duplicates-fuzzy EPSILON] + [--only-attributes N1,N2-N3…] [--remove-duplicates] + [--remove-duplicates-fuzzy EPSILON] [-i|--importer-options key=val,key2=val2,…] [-c|--converter-options key=val,key2=val2,…]... [--mesh MESH] [--level LEVEL] [--concatenate-meshes] [--info-animations] [--info-images] @@ -103,8 +103,9 @@ Arguments: - `--plugin-dir DIR` --- override base plugin dir - `--map` --- memory-map the input for zero-copy import (works only for standalone files) -- `--only-attributes "i j …"` --- include only attributes of given IDs in the - output +- `--only-attributes N1,N2-N3…` --- include only attributes of given IDs in + the output. See @ref Utility::String::parseNumberSequence() for syntax + description. - `--remove-duplicates` --- remove duplicate vertices using @ref MeshTools::removeDuplicates(const Trade::MeshData&) after import - `--remove-duplicates-fuzzy EPSILON` --- remove duplicate vertices using @@ -235,7 +236,7 @@ int main(int argc, char** argv) { #if defined(CORRADE_TARGET_UNIX) || (defined(CORRADE_TARGET_WINDOWS) && !defined(CORRADE_TARGET_WINDOWS_RT)) .addBooleanOption("map").setHelp("map", "memory-map the input for zero-copy import (works only for standalone files)") #endif - .addOption("only-attributes").setHelp("only-attributes", "include only attributes of given IDs in the output", "\"i j …\"") + .addOption("only-attributes").setHelp("only-attributes", "include only attributes of given IDs in the output", "N1,N2-N3…") .addBooleanOption("remove-duplicates").setHelp("remove-duplicates", "remove duplicate vertices in the mesh after import") .addOption("remove-duplicates-fuzzy").setHelp("remove-duplicates-fuzzy", "remove duplicate vertices with fuzzy comparison in the mesh after import", "EPSILON") .addOption('i', "importer-options").setHelp("importer-options", "configuration options to pass to the importer", "key=val,key2=val2,…") @@ -1040,19 +1041,15 @@ used.)") /* Filter attributes, if requested */ if(!args.value("only-attributes").empty()) { - std::set only; - /** @todo drop this awful STL mess once we have an string-to-int - API that can take non-null-terminated string views */ - for(const std::string& i: Utility::String::split(args.value("only-attributes"), ' ')) - only.insert(std::stoi(i)); + const Containers::Optional> only = Utility::String::parseNumberSequence(args.value("only-attributes"), 0, mesh->attributeCount()); + if(!only) return 2; /** @todo use MeshTools::filterOnlyAttributes() once it has a rvalue overload that transfers ownership */ Containers::Array attributes; - for(UnsignedInt i = 0; i != mesh->attributeCount(); ++i) { - if(only.find(i) != only.end()) - arrayAppend(attributes, mesh->attributeData(i)); - } + arrayReserve(attributes, only->size()); + for(UnsignedInt i: *only) + arrayAppend(attributes, mesh->attributeData(i)); const Trade::MeshIndexData indices{mesh->indices()}; const UnsignedInt vertexCount = mesh->vertexCount();