From e881f197e88b5c92177a81e8fdd5ec270e5a61ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 1 Apr 2022 13:13:33 +0200 Subject: [PATCH] {distancefield,scene,image}converter: port away from std::string. Now it's just Arguments and Configuration using std::string by default, will clean up the rest once those are ported as well. --- src/Magnum/SceneTools/sceneconverter.cpp | 50 +++++++++---------- .../TextureTools/distancefieldconverter.cpp | 2 +- .../Trade/Implementation/converterUtilities.h | 2 +- src/Magnum/Trade/imageconverter.cpp | 16 +++--- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Magnum/SceneTools/sceneconverter.cpp b/src/Magnum/SceneTools/sceneconverter.cpp index de9294d9d..dae8e7a20 100644 --- a/src/Magnum/SceneTools/sceneconverter.cpp +++ b/src/Magnum/SceneTools/sceneconverter.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include /** @todo remove once Arguments is std::string-free */ #include #include @@ -205,7 +205,7 @@ using namespace Containers::Literals; namespace { /** @todo const Array& doesn't work, minmax() would fail to match */ -template std::string calculateBounds(Containers::Array&& attribute) { +template Containers::String calculateBounds(Containers::Array&& attribute) { /** @todo clean up when Debug::toString() exists */ std::ostringstream out; Debug{&out, Debug::Flag::NoNewlineAtTheEnd} << Math::minmax(attribute); @@ -352,31 +352,31 @@ is specified as well, the IDs reference attributes of the first mesh.)") struct AnimationInfo { UnsignedInt animation; Trade::AnimationData data{{}, {}}; - std::string name; + Containers::String name; }; struct SkinInfo { UnsignedInt skin; Trade::SkinData3D data{{}, {}}; - std::string name; + Containers::String name; }; struct LightInfo { UnsignedInt light; Trade::LightData data{{}, {}, {}}; - std::string name; + Containers::String name; }; struct MaterialInfo { UnsignedInt material; Trade::MaterialData data{{}, {}}; - std::string name; + Containers::String name; }; struct TextureInfo { UnsignedInt texture; Trade::TextureData data{{}, {}, {}, {}, {}, {}}; - std::string name; + Containers::String name; }; struct MeshAttributeInfo { @@ -384,9 +384,9 @@ is specified as well, the IDs reference attributes of the first mesh.)") Int stride; UnsignedInt arraySize; Trade::MeshAttribute name; - std::string customName; + Containers::String customName; VertexFormat format; - std::string bounds; + Containers::String bounds; }; struct MeshInfo { @@ -395,17 +395,17 @@ is specified as well, the IDs reference attributes of the first mesh.)") UnsignedInt indexCount, vertexCount; std::size_t indexOffset; Int indexStride; - std::string indexBounds; + Containers::String indexBounds; MeshIndexType indexType; Containers::Array attributes; std::size_t indexDataSize, vertexDataSize; Trade::DataFlags indexDataFlags, vertexDataFlags; - std::string name; + Containers::String name; }; struct SceneFieldInfo { Trade::SceneField name; - std::string customName; + Containers::String customName; Trade::SceneFieldFlags flags; Trade::SceneFieldType type; UnsignedInt arraySize; @@ -419,7 +419,7 @@ is specified as well, the IDs reference attributes of the first mesh.)") Containers::Array fields; std::size_t dataSize; Trade::DataFlags dataFlags; - std::string name; + Containers::String name; /** @todo object names? */ }; @@ -632,7 +632,7 @@ is specified as well, the IDs reference attributes of the first mesh.)") /* Calculate bounds, if requested and this is not an implementation-specific format */ - std::string bounds; + Containers::String bounds; if(args.isSet("bounds") && !isVertexFormatImplementationSpecific(mesh->attributeFormat(k))) switch(name) { case Trade::MeshAttribute::Position: bounds = calculateBounds(mesh->positions3DAsArray(namedAttributeId(*mesh, k))); @@ -761,7 +761,7 @@ is specified as well, the IDs reference attributes of the first mesh.)") for(const SceneInfo& info: sceneInfos) { Debug d{useColor}; d << Debug::boldColor(Debug::Color::White) << "Scene" << info.scene << Debug::nospace << ":" << Debug::resetColor; - if(!info.name.empty()) d << Debug::boldColor(Debug::Color::Yellow) << info.name << Debug::resetColor; + if(info.name) d << Debug::boldColor(Debug::Color::Yellow) << info.name << Debug::resetColor; d << Debug::newline; d << " Bound:" << info.mappingBound << "objects" << Debug::color(Debug::Color::Blue) << "@" << Debug::packed @@ -795,7 +795,7 @@ is specified as well, the IDs reference attributes of the first mesh.)") for(const AnimationInfo& info: animationInfos) { Debug d{useColor}; d << Debug::boldColor(Debug::Color::White) << "Animation" << info.animation << Debug::nospace << ":" << Debug::resetColor; - if(!info.name.empty()) d << Debug::boldColor(Debug::Color::Yellow) << info.name << Debug::resetColor; + if(info.name) d << Debug::boldColor(Debug::Color::Yellow) << info.name << Debug::resetColor; d << Debug::newline << " Duration:" << info.data.duration() << "(" << Debug::nospace << Utility::format("{:.1f}", info.data.data().size()/1024.0f) << "kB"; @@ -846,7 +846,7 @@ is specified as well, the IDs reference attributes of the first mesh.)") d << Debug::boldColor(Debug::Color::White) << Debug::nospace << ":" << Debug::resetColor; - if(!info.name.empty()) d << Debug::boldColor(Debug::Color::Yellow) + if(info.name) d << Debug::boldColor(Debug::Color::Yellow) << info.name << Debug::resetColor; d << Debug::newline << " " << info.data.joints().size() << "joints"; @@ -863,7 +863,7 @@ is specified as well, the IDs reference attributes of the first mesh.)") d << Debug::boldColor(Debug::Color::White) << Debug::nospace << ":" << Debug::resetColor; - if(!info.name.empty()) d << Debug::boldColor(Debug::Color::Yellow) + if(info.name) d << Debug::boldColor(Debug::Color::Yellow) << info.name << Debug::resetColor; d << Debug::newline << " Type:" << Debug::packed @@ -898,7 +898,7 @@ is specified as well, the IDs reference attributes of the first mesh.)") d << Debug::boldColor(Debug::Color::White) << Debug::nospace << ":" << Debug::resetColor; - if(!info.name.empty()) d << Debug::boldColor(Debug::Color::Yellow) << info.name << Debug::resetColor; + if(info.name) d << Debug::boldColor(Debug::Color::Yellow) << info.name << Debug::resetColor; d << Debug::newline << " Type:" << Debug::packed << Debug::color(Debug::Color::Cyan) << info.data.types() << Debug::resetColor; @@ -1010,7 +1010,7 @@ is specified as well, the IDs reference attributes of the first mesh.)") d << Debug::boldColor(Debug::Color::White) << Debug::nospace << ":" << Debug::resetColor; - if(!info.name.empty()) d << Debug::boldColor(Debug::Color::Yellow) << info.name << Debug::resetColor; + if(info.name) d << Debug::boldColor(Debug::Color::Yellow) << info.name << Debug::resetColor; d << Debug::newline; } d << " Level" << info.level << Debug::nospace << ":" @@ -1035,7 +1035,7 @@ is specified as well, the IDs reference attributes of the first mesh.)") d << Debug::nospace << ", offset" << attribute.offset; d << Debug::nospace << ", stride" << attribute.stride; - if(!attribute.bounds.empty()) + if(attribute.bounds) d << Debug::newline << " bounds:" << attribute.bounds; } @@ -1048,7 +1048,7 @@ is specified as well, the IDs reference attributes of the first mesh.)") d << Debug::nospace << ", flags:" << Debug::packed << Debug::color(Debug::Color::Green) << info.indexDataFlags << Debug::resetColor; d << Debug::nospace << ")"; - if(!info.indexBounds.empty()) + if(info.indexBounds) d << Debug::newline << " bounds:" << info.indexBounds; } } @@ -1064,7 +1064,7 @@ is specified as well, the IDs reference attributes of the first mesh.)") d << Debug::boldColor(Debug::Color::White) << Debug::nospace << ":" << Debug::resetColor; - if(!info.name.empty()) d << Debug::boldColor(Debug::Color::Yellow) + if(info.name) d << Debug::boldColor(Debug::Color::Yellow) << info.name << Debug::resetColor; d << Debug::newline; d << " Type:" @@ -1247,8 +1247,8 @@ is specified as well, the IDs reference attributes of the first mesh.)") other. If the last converter supports ConvertMeshToFile instead of ConvertMesh, it's used instead of the last implicit AnySceneConverter. */ for(std::size_t i = 0, converterCount = args.arrayValueCount("converter"); i <= converterCount; ++i) { - const std::string converterName = i == converterCount ? - "AnySceneConverter" : args.arrayValue("converter", i); + const Containers::StringView converterName = i == converterCount ? + "AnySceneConverter"_s : args.arrayValue("converter", i); Containers::Pointer converter = converterManager.loadAndInstantiate(converterName); if(!converter) { Debug{} << "Available converter plugins:" << ", "_s.join(converterManager.aliasList()); diff --git a/src/Magnum/TextureTools/distancefieldconverter.cpp b/src/Magnum/TextureTools/distancefieldconverter.cpp index 0c5c92ea4..5aad73f6a 100644 --- a/src/Magnum/TextureTools/distancefieldconverter.cpp +++ b/src/Magnum/TextureTools/distancefieldconverter.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include /** @todo remove once Arguments is std::string-free */ #include #include diff --git a/src/Magnum/Trade/Implementation/converterUtilities.h b/src/Magnum/Trade/Implementation/converterUtilities.h index 9adbc2c2d..d936a081b 100644 --- a/src/Magnum/Trade/Implementation/converterUtilities.h +++ b/src/Magnum/Trade/Implementation/converterUtilities.h @@ -56,7 +56,7 @@ struct ImageInfo { Vector3i size; std::size_t dataSize; Trade::DataFlags dataFlags; - std::string name; + Containers::String name; }; Containers::Array imageInfo(AbstractImporter& importer, bool& error, std::chrono::high_resolution_clock::duration& importTime) { diff --git a/src/Magnum/Trade/imageconverter.cpp b/src/Magnum/Trade/imageconverter.cpp index 5de830ffe..d2688f196 100644 --- a/src/Magnum/Trade/imageconverter.cpp +++ b/src/Magnum/Trade/imageconverter.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include /** @todo remove once Arguments is std::string-free */ #include #include @@ -245,7 +245,7 @@ template bool checkCommonFormatAndSize(const Utility::Ar return true; } -template class View, UnsignedInt dimensions> bool convertOneOrMoreImages(Trade::AbstractImageConverter& converter, const Containers::Array>& outputImages, const std::string& output) { +template class View, UnsignedInt dimensions> bool convertOneOrMoreImages(Trade::AbstractImageConverter& converter, const Containers::Array>& outputImages, const Containers::StringView output) { Containers::Array> views; arrayReserve(views, outputImages.size()); for(const Trade::ImageData& outputImage: outputImages) @@ -253,7 +253,7 @@ template class View, UnsignedInt dimensions> bool c return converter.convertToFile(views, output); } -template bool convertOneOrMoreImages(Trade::AbstractImageConverter& converter, const Containers::Array>& outputImages, const std::string& output) { +template bool convertOneOrMoreImages(Trade::AbstractImageConverter& converter, const Containers::Array>& outputImages, const Containers::StringView output) { /* If there's just one image, convert it using the single-level API. Otherwise the multi-level entrypoint would require the plugin to support multi-level conversion, and only some file formats have that. */ @@ -384,7 +384,7 @@ key=true; configuration subgroups are delimited with /.)") std::chrono::high_resolution_clock::duration importTime{}; for(std::size_t i = 0, max = args.arrayValueCount("input"); i != max; ++i) { - const std::string input = args.arrayValue("input", i); + const Containers::StringView input = args.arrayValue("input", i); /* Load raw data, if requested; assume it's a tightly-packed square of given format */ @@ -523,7 +523,7 @@ key=true; configuration subgroups are delimited with /.)") else d << "1D image"; d << info.image << Debug::nospace << ":" << Debug::resetColor; - if(!info.name.empty()) d << Debug::boldColor(Debug::Color::Yellow) + if(info.name) d << Debug::boldColor(Debug::Color::Yellow) << info.name << Debug::resetColor; d << Debug::newline; } @@ -693,12 +693,12 @@ key=true; configuration subgroups are delimited with /.)") /* Wow, C++, you suck. This implicitly initializes to random shit?! */ std::chrono::high_resolution_clock::duration conversionTime{}; - std::string output; + Containers::StringView output; if(args.isSet("in-place")) { /* Should have been checked in a graceful way above */ CORRADE_INTERNAL_ASSERT(args.arrayValueCount("input") == 1); - output = args.arrayValue("input", 0); - } else output = args.value("output"); + output = args.arrayValue("input", 0); + } else output = args.value("output"); Int outputDimensions; Containers::Array outputImages1D;