Browse Source

{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.
pull/557/head
Vladimír Vondruš 4 years ago
parent
commit
e881f197e8
  1. 50
      src/Magnum/SceneTools/sceneconverter.cpp
  2. 2
      src/Magnum/TextureTools/distancefieldconverter.cpp
  3. 2
      src/Magnum/Trade/Implementation/converterUtilities.h
  4. 16
      src/Magnum/Trade/imageconverter.cpp

50
src/Magnum/SceneTools/sceneconverter.cpp

@ -30,7 +30,7 @@
#include <Corrade/Containers/Reference.h> #include <Corrade/Containers/Reference.h>
#include <Corrade/Containers/Triple.h> #include <Corrade/Containers/Triple.h>
#include <Corrade/Utility/Arguments.h> #include <Corrade/Utility/Arguments.h>
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h> /** @todo remove once Arguments is std::string-free */
#include <Corrade/Utility/Format.h> #include <Corrade/Utility/Format.h>
#include <Corrade/Utility/Path.h> #include <Corrade/Utility/Path.h>
@ -205,7 +205,7 @@ using namespace Containers::Literals;
namespace { namespace {
/** @todo const Array& doesn't work, minmax() would fail to match */ /** @todo const Array& doesn't work, minmax() would fail to match */
template<class T> std::string calculateBounds(Containers::Array<T>&& attribute) { template<class T> Containers::String calculateBounds(Containers::Array<T>&& attribute) {
/** @todo clean up when Debug::toString() exists */ /** @todo clean up when Debug::toString() exists */
std::ostringstream out; std::ostringstream out;
Debug{&out, Debug::Flag::NoNewlineAtTheEnd} << Math::minmax(attribute); 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 { struct AnimationInfo {
UnsignedInt animation; UnsignedInt animation;
Trade::AnimationData data{{}, {}}; Trade::AnimationData data{{}, {}};
std::string name; Containers::String name;
}; };
struct SkinInfo { struct SkinInfo {
UnsignedInt skin; UnsignedInt skin;
Trade::SkinData3D data{{}, {}}; Trade::SkinData3D data{{}, {}};
std::string name; Containers::String name;
}; };
struct LightInfo { struct LightInfo {
UnsignedInt light; UnsignedInt light;
Trade::LightData data{{}, {}, {}}; Trade::LightData data{{}, {}, {}};
std::string name; Containers::String name;
}; };
struct MaterialInfo { struct MaterialInfo {
UnsignedInt material; UnsignedInt material;
Trade::MaterialData data{{}, {}}; Trade::MaterialData data{{}, {}};
std::string name; Containers::String name;
}; };
struct TextureInfo { struct TextureInfo {
UnsignedInt texture; UnsignedInt texture;
Trade::TextureData data{{}, {}, {}, {}, {}, {}}; Trade::TextureData data{{}, {}, {}, {}, {}, {}};
std::string name; Containers::String name;
}; };
struct MeshAttributeInfo { struct MeshAttributeInfo {
@ -384,9 +384,9 @@ is specified as well, the IDs reference attributes of the first mesh.)")
Int stride; Int stride;
UnsignedInt arraySize; UnsignedInt arraySize;
Trade::MeshAttribute name; Trade::MeshAttribute name;
std::string customName; Containers::String customName;
VertexFormat format; VertexFormat format;
std::string bounds; Containers::String bounds;
}; };
struct MeshInfo { struct MeshInfo {
@ -395,17 +395,17 @@ is specified as well, the IDs reference attributes of the first mesh.)")
UnsignedInt indexCount, vertexCount; UnsignedInt indexCount, vertexCount;
std::size_t indexOffset; std::size_t indexOffset;
Int indexStride; Int indexStride;
std::string indexBounds; Containers::String indexBounds;
MeshIndexType indexType; MeshIndexType indexType;
Containers::Array<MeshAttributeInfo> attributes; Containers::Array<MeshAttributeInfo> attributes;
std::size_t indexDataSize, vertexDataSize; std::size_t indexDataSize, vertexDataSize;
Trade::DataFlags indexDataFlags, vertexDataFlags; Trade::DataFlags indexDataFlags, vertexDataFlags;
std::string name; Containers::String name;
}; };
struct SceneFieldInfo { struct SceneFieldInfo {
Trade::SceneField name; Trade::SceneField name;
std::string customName; Containers::String customName;
Trade::SceneFieldFlags flags; Trade::SceneFieldFlags flags;
Trade::SceneFieldType type; Trade::SceneFieldType type;
UnsignedInt arraySize; UnsignedInt arraySize;
@ -419,7 +419,7 @@ is specified as well, the IDs reference attributes of the first mesh.)")
Containers::Array<SceneFieldInfo> fields; Containers::Array<SceneFieldInfo> fields;
std::size_t dataSize; std::size_t dataSize;
Trade::DataFlags dataFlags; Trade::DataFlags dataFlags;
std::string name; Containers::String name;
/** @todo object names? */ /** @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 /* Calculate bounds, if requested and this is not an
implementation-specific format */ implementation-specific format */
std::string bounds; Containers::String bounds;
if(args.isSet("bounds") && !isVertexFormatImplementationSpecific(mesh->attributeFormat(k))) switch(name) { if(args.isSet("bounds") && !isVertexFormatImplementationSpecific(mesh->attributeFormat(k))) switch(name) {
case Trade::MeshAttribute::Position: case Trade::MeshAttribute::Position:
bounds = calculateBounds(mesh->positions3DAsArray(namedAttributeId(*mesh, k))); 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) { for(const SceneInfo& info: sceneInfos) {
Debug d{useColor}; Debug d{useColor};
d << Debug::boldColor(Debug::Color::White) << "Scene" << info.scene << Debug::nospace << ":" << Debug::resetColor; 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 << Debug::newline;
d << " Bound:" << info.mappingBound << "objects" d << " Bound:" << info.mappingBound << "objects"
<< Debug::color(Debug::Color::Blue) << "@" << Debug::packed << 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) { for(const AnimationInfo& info: animationInfos) {
Debug d{useColor}; Debug d{useColor};
d << Debug::boldColor(Debug::Color::White) << "Animation" << info.animation << Debug::nospace << ":" << Debug::resetColor; 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() d << Debug::newline << " Duration:" << info.data.duration()
<< "(" << Debug::nospace << Utility::format("{:.1f}", info.data.data().size()/1024.0f) << "kB"; << "(" << 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 << ":" d << Debug::boldColor(Debug::Color::White) << Debug::nospace << ":"
<< Debug::resetColor; << 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; << info.name << Debug::resetColor;
d << Debug::newline << " " << info.data.joints().size() << "joints"; 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 << ":" d << Debug::boldColor(Debug::Color::White) << Debug::nospace << ":"
<< Debug::resetColor; << 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; << info.name << Debug::resetColor;
d << Debug::newline << " Type:" << Debug::packed 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 << ":" d << Debug::boldColor(Debug::Color::White) << Debug::nospace << ":"
<< Debug::resetColor; << 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; 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 << ":" d << Debug::boldColor(Debug::Color::White) << Debug::nospace << ":"
<< Debug::resetColor; << 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 << Debug::newline;
} }
d << " Level" << info.level << Debug::nospace << ":" 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 << ", offset" << attribute.offset;
d << Debug::nospace << ", stride" d << Debug::nospace << ", stride"
<< attribute.stride; << attribute.stride;
if(!attribute.bounds.empty()) if(attribute.bounds)
d << Debug::newline << " bounds:" << 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 d << Debug::nospace << ", flags:" << Debug::packed
<< Debug::color(Debug::Color::Green) << info.indexDataFlags << Debug::resetColor; << Debug::color(Debug::Color::Green) << info.indexDataFlags << Debug::resetColor;
d << Debug::nospace << ")"; d << Debug::nospace << ")";
if(!info.indexBounds.empty()) if(info.indexBounds)
d << Debug::newline << " bounds:" << 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 << ":" d << Debug::boldColor(Debug::Color::White) << Debug::nospace << ":"
<< Debug::resetColor; << 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; << info.name << Debug::resetColor;
d << Debug::newline; d << Debug::newline;
d << " Type:" 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 other. If the last converter supports ConvertMeshToFile instead of
ConvertMesh, it's used instead of the last implicit AnySceneConverter. */ ConvertMesh, it's used instead of the last implicit AnySceneConverter. */
for(std::size_t i = 0, converterCount = args.arrayValueCount("converter"); i <= converterCount; ++i) { for(std::size_t i = 0, converterCount = args.arrayValueCount("converter"); i <= converterCount; ++i) {
const std::string converterName = i == converterCount ? const Containers::StringView converterName = i == converterCount ?
"AnySceneConverter" : args.arrayValue("converter", i); "AnySceneConverter"_s : args.arrayValue<Containers::StringView>("converter", i);
Containers::Pointer<Trade::AbstractSceneConverter> converter = converterManager.loadAndInstantiate(converterName); Containers::Pointer<Trade::AbstractSceneConverter> converter = converterManager.loadAndInstantiate(converterName);
if(!converter) { if(!converter) {
Debug{} << "Available converter plugins:" << ", "_s.join(converterManager.aliasList()); Debug{} << "Available converter plugins:" << ", "_s.join(converterManager.aliasList());

2
src/Magnum/TextureTools/distancefieldconverter.cpp

@ -25,7 +25,7 @@
#include <Corrade/Containers/Optional.h> #include <Corrade/Containers/Optional.h>
#include <Corrade/Utility/Arguments.h> #include <Corrade/Utility/Arguments.h>
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h> /** @todo remove once Arguments is std::string-free */
#include <Corrade/Utility/Path.h> #include <Corrade/Utility/Path.h>
#include <Corrade/PluginManager/Manager.h> #include <Corrade/PluginManager/Manager.h>

2
src/Magnum/Trade/Implementation/converterUtilities.h

@ -56,7 +56,7 @@ struct ImageInfo {
Vector3i size; Vector3i size;
std::size_t dataSize; std::size_t dataSize;
Trade::DataFlags dataFlags; Trade::DataFlags dataFlags;
std::string name; Containers::String name;
}; };
Containers::Array<ImageInfo> imageInfo(AbstractImporter& importer, bool& error, std::chrono::high_resolution_clock::duration& importTime) { Containers::Array<ImageInfo> imageInfo(AbstractImporter& importer, bool& error, std::chrono::high_resolution_clock::duration& importTime) {

16
src/Magnum/Trade/imageconverter.cpp

@ -31,7 +31,7 @@
#include <Corrade/Utility/Arguments.h> #include <Corrade/Utility/Arguments.h>
#include <Corrade/Utility/Algorithms.h> #include <Corrade/Utility/Algorithms.h>
#include <Corrade/Utility/ConfigurationGroup.h> #include <Corrade/Utility/ConfigurationGroup.h>
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h> /** @todo remove once Arguments is std::string-free */
#include <Corrade/Utility/Format.h> #include <Corrade/Utility/Format.h>
#include <Corrade/Utility/Path.h> #include <Corrade/Utility/Path.h>
@ -245,7 +245,7 @@ template<UnsignedInt dimensions> bool checkCommonFormatAndSize(const Utility::Ar
return true; return true;
} }
template<template<UnsignedInt, class> class View, UnsignedInt dimensions> bool convertOneOrMoreImages(Trade::AbstractImageConverter& converter, const Containers::Array<Trade::ImageData<dimensions>>& outputImages, const std::string& output) { template<template<UnsignedInt, class> class View, UnsignedInt dimensions> bool convertOneOrMoreImages(Trade::AbstractImageConverter& converter, const Containers::Array<Trade::ImageData<dimensions>>& outputImages, const Containers::StringView output) {
Containers::Array<View<dimensions, const char>> views; Containers::Array<View<dimensions, const char>> views;
arrayReserve(views, outputImages.size()); arrayReserve(views, outputImages.size());
for(const Trade::ImageData<dimensions>& outputImage: outputImages) for(const Trade::ImageData<dimensions>& outputImage: outputImages)
@ -253,7 +253,7 @@ template<template<UnsignedInt, class> class View, UnsignedInt dimensions> bool c
return converter.convertToFile(views, output); return converter.convertToFile(views, output);
} }
template<UnsignedInt dimensions> bool convertOneOrMoreImages(Trade::AbstractImageConverter& converter, const Containers::Array<Trade::ImageData<dimensions>>& outputImages, const std::string& output) { template<UnsignedInt dimensions> bool convertOneOrMoreImages(Trade::AbstractImageConverter& converter, const Containers::Array<Trade::ImageData<dimensions>>& outputImages, const Containers::StringView output) {
/* If there's just one image, convert it using the single-level API. /* If there's just one image, convert it using the single-level API.
Otherwise the multi-level entrypoint would require the plugin to support Otherwise the multi-level entrypoint would require the plugin to support
multi-level conversion, and only some file formats have that. */ 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{}; std::chrono::high_resolution_clock::duration importTime{};
for(std::size_t i = 0, max = args.arrayValueCount("input"); i != max; ++i) { 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<Containers::StringView>("input", i);
/* Load raw data, if requested; assume it's a tightly-packed square of /* Load raw data, if requested; assume it's a tightly-packed square of
given format */ given format */
@ -523,7 +523,7 @@ key=true; configuration subgroups are delimited with /.)")
else d << "1D image"; else d << "1D image";
d << info.image << Debug::nospace << ":" d << info.image << Debug::nospace << ":"
<< Debug::resetColor; << 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; << info.name << Debug::resetColor;
d << Debug::newline; d << Debug::newline;
} }
@ -693,12 +693,12 @@ key=true; configuration subgroups are delimited with /.)")
/* Wow, C++, you suck. This implicitly initializes to random shit?! */ /* Wow, C++, you suck. This implicitly initializes to random shit?! */
std::chrono::high_resolution_clock::duration conversionTime{}; std::chrono::high_resolution_clock::duration conversionTime{};
std::string output; Containers::StringView output;
if(args.isSet("in-place")) { if(args.isSet("in-place")) {
/* Should have been checked in a graceful way above */ /* Should have been checked in a graceful way above */
CORRADE_INTERNAL_ASSERT(args.arrayValueCount("input") == 1); CORRADE_INTERNAL_ASSERT(args.arrayValueCount("input") == 1);
output = args.arrayValue("input", 0); output = args.arrayValue<Containers::StringView>("input", 0);
} else output = args.value("output"); } else output = args.value<Containers::StringView>("output");
Int outputDimensions; Int outputDimensions;
Containers::Array<Trade::ImageData1D> outputImages1D; Containers::Array<Trade::ImageData1D> outputImages1D;

Loading…
Cancel
Save