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/Triple.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/Path.h>
@ -205,7 +205,7 @@ using namespace Containers::Literals;
namespace {
/** @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 */
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<MeshAttributeInfo> 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<SceneFieldInfo> 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<Containers::StringView>("converter", i);
Containers::Pointer<Trade::AbstractSceneConverter> converter = converterManager.loadAndInstantiate(converterName);
if(!converter) {
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/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/PluginManager/Manager.h>

2
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> 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/Algorithms.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/Path.h>
@ -245,7 +245,7 @@ template<UnsignedInt dimensions> bool checkCommonFormatAndSize(const Utility::Ar
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;
arrayReserve(views, outputImages.size());
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);
}
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.
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<Containers::StringView>("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<Containers::StringView>("input", 0);
} else output = args.value<Containers::StringView>("output");
Int outputDimensions;
Containers::Array<Trade::ImageData1D> outputImages1D;

Loading…
Cancel
Save