From 21fc790632bb733df53e2b50a250ef75e8ba6468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 7 Sep 2015 20:29:32 +0200 Subject: [PATCH] Trade: make AbstractImageConverter API non-const. In the particular case of AnyImageConverter the function needs to access manager and load/instantiate plugin using it, which is non-const operation. More generally, it puts unnecessary restrictions on what the plugin can and cannot do. --- src/Magnum/Trade/AbstractImageConverter.cpp | 24 ++++---- src/Magnum/Trade/AbstractImageConverter.h | 60 +++++++++---------- .../Trade/Test/AbstractImageConverterTest.cpp | 2 +- .../TgaImageConverter/TgaImageConverter.cpp | 2 +- .../TgaImageConverter/TgaImageConverter.h | 2 +- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/Magnum/Trade/AbstractImageConverter.cpp b/src/Magnum/Trade/AbstractImageConverter.cpp index a3430c206..c3341a78a 100644 --- a/src/Magnum/Trade/AbstractImageConverter.cpp +++ b/src/Magnum/Trade/AbstractImageConverter.cpp @@ -39,62 +39,62 @@ AbstractImageConverter::AbstractImageConverter(PluginManager::Manager{manager, std::move(plugin)} {} -std::optional AbstractImageConverter::exportToImage(const ImageView2D& image) const { +std::optional AbstractImageConverter::exportToImage(const ImageView2D& image) { CORRADE_ASSERT(features() & Feature::ConvertImage, "Trade::AbstractImageConverter::exportToImage(): feature not supported", {}); return doExportToImage(image); } -std::optional AbstractImageConverter::doExportToImage(const ImageView2D&) const { +std::optional AbstractImageConverter::doExportToImage(const ImageView2D&) { CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToImage(): feature advertised but not implemented", {}); return std::nullopt; } -std::optional AbstractImageConverter::exportToCompressedImage(const ImageView2D& image) const { +std::optional AbstractImageConverter::exportToCompressedImage(const ImageView2D& image) { CORRADE_ASSERT(features() & Feature::ConvertCompressedImage, "Trade::AbstractImageConverter::exportToCompressedImage(): feature not supported", {}); return doExportToCompressedImage(image); } -std::optional AbstractImageConverter::doExportToCompressedImage(const ImageView2D&) const { +std::optional AbstractImageConverter::doExportToCompressedImage(const ImageView2D&) { CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToCompressedImage(): feature advertised but not implemented", {}); return std::nullopt; } -Containers::Array AbstractImageConverter::exportToData(const ImageView2D& image) const { +Containers::Array AbstractImageConverter::exportToData(const ImageView2D& image) { CORRADE_ASSERT(features() & Feature::ConvertData, "Trade::AbstractImageConverter::exportToData(): feature not supported", nullptr); return doExportToData(image); } -Containers::Array AbstractImageConverter::doExportToData(const ImageView2D&) const { +Containers::Array AbstractImageConverter::doExportToData(const ImageView2D&) { CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToData(): feature advertised but not implemented", nullptr); return nullptr; } -Containers::Array AbstractImageConverter::exportToData(const CompressedImageView2D& image) const { +Containers::Array AbstractImageConverter::exportToData(const CompressedImageView2D& image) { CORRADE_ASSERT(features() & Feature::ConvertCompressedData, "Trade::AbstractImageConverter::exportToData(): feature not supported", nullptr); return doExportToData(image); } -Containers::Array AbstractImageConverter::doExportToData(const CompressedImageView2D&) const { +Containers::Array AbstractImageConverter::doExportToData(const CompressedImageView2D&) { CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToData(): feature advertised but not implemented", nullptr); return nullptr; } -bool AbstractImageConverter::exportToFile(const ImageView2D& image, const std::string& filename) const { +bool AbstractImageConverter::exportToFile(const ImageView2D& image, const std::string& filename) { CORRADE_ASSERT(features() & Feature::ConvertFile, "Trade::AbstractImageConverter::exportToFile(): feature not supported", {}); return doExportToFile(image, filename); } -bool AbstractImageConverter::doExportToFile(const ImageView2D& image, const std::string& filename) const { +bool AbstractImageConverter::doExportToFile(const ImageView2D& image, const std::string& filename) { CORRADE_ASSERT(features() & Feature::ConvertData, "Trade::AbstractImageConverter::exportToFile(): not implemented", false); const auto data = doExportToData(image); @@ -109,14 +109,14 @@ bool AbstractImageConverter::doExportToFile(const ImageView2D& image, const std: return true; } -bool AbstractImageConverter::exportToFile(const CompressedImageView2D& image, const std::string& filename) const { +bool AbstractImageConverter::exportToFile(const CompressedImageView2D& image, const std::string& filename) { CORRADE_ASSERT(features() & Feature::ConvertCompressedFile, "Trade::AbstractImageConverter::exportToFile(): feature not supported", {}); return doExportToFile(image, filename); } -bool AbstractImageConverter::doExportToFile(const CompressedImageView2D& image, const std::string& filename) const { +bool AbstractImageConverter::doExportToFile(const CompressedImageView2D& image, const std::string& filename) { CORRADE_ASSERT(features() & Feature::ConvertCompressedData, "Trade::AbstractImageConverter::exportToFile(): not implemented", false); const auto data = doExportToData(image); diff --git a/src/Magnum/Trade/AbstractImageConverter.h b/src/Magnum/Trade/AbstractImageConverter.h index 65bb37dfb..8879d272a 100644 --- a/src/Magnum/Trade/AbstractImageConverter.h +++ b/src/Magnum/Trade/AbstractImageConverter.h @@ -57,10 +57,10 @@ checked by the implementation: is supported. - Function @ref doExportToCompressedImage() is called only if @ref Feature::ConvertCompressedImage is supported. -- Function @ref doExportToData(const ImageView2D&) const is called only if +- Function @ref doExportToData(const ImageView2D&) is called only if @ref Feature::ConvertData is supported. -- Function @ref doExportToData(const CompressedImageView2D&) const is called - only if @ref Feature::ConvertCompressedData is supported. +- Function @ref doExportToData(const CompressedImageView2D&) is called only + if @ref Feature::ConvertCompressedData is supported. Plugin interface string is `"cz.mosra.magnum.Trade.AbstractImageConverter/0.2.1"`. */ @@ -80,21 +80,21 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractManagi /** Conversion to compressed image with @ref exportToCompressedImage() */ ConvertCompressedImage = 1 << 1, - /** Exporting to file with @ref exportToFile(const ImageView2D&, const std::string&) const */ + /** Exporting to file with @ref exportToFile(const ImageView2D&, const std::string&) */ ConvertFile = 1 << 2, - /** Exporting to file with @ref exportToFile(const CompressedImageView2D&, const std::string&) const */ + /** Exporting to file with @ref exportToFile(const CompressedImageView2D&, const std::string&) */ ConvertCompressedFile = 1 << 3, /** - * Exporting to raw data with @ref exportToData(const ImageView2D&) const. + * Exporting to raw data with @ref exportToData(const ImageView2D&). * Implies @ref Feature::ConvertFile. */ ConvertData = ConvertFile|(1 << 4), /** * Exporting compressed image to raw data with - * @ref exportToData(const CompressedImageView2D&) const. Implies + * @ref exportToData(const CompressedImageView2D&). Implies * @ref Feature::ConvertCompressedFile. */ ConvertCompressedData = ConvertCompressedFile|(1 << 4) @@ -126,7 +126,7 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractManagi * converted image on success, `std::nullopt` otherwise. * @see @ref features(), @ref exportToData(), @ref exportToFile() */ - std::optional exportToImage(const ImageView2D& image) const; + std::optional exportToImage(const ImageView2D& image); /** * @brief Convert image to compressed format @@ -135,7 +135,7 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractManagi * Returns converted image on success, `std::nullopt` otherwise. * @see @ref features(), @ref exportToData(), @ref exportToFile() */ - std::optional exportToCompressedImage(const ImageView2D& image) const; + std::optional exportToCompressedImage(const ImageView2D& image); /** * @brief Export image to raw data @@ -143,9 +143,9 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractManagi * Available only if @ref Feature::ConvertData is supported. Returns * data on success, zero-sized array otherwise. * @see @ref features(), @ref exportToImage(), - * @ref exportToFile(const ImageView2D&, const std::string&) const + * @ref exportToFile(const ImageView2D&, const std::string&) */ - Containers::Array exportToData(const ImageView2D& image) const; + Containers::Array exportToData(const ImageView2D& image); /** * @brief Export compressed image to raw data @@ -153,9 +153,9 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractManagi * Available only if @ref Feature::ConvertCompressedData is supported. * Returns data on success, zero-sized array otherwise. * @see @ref features(), @ref exportToCompressedImage(), - * @ref exportToFile(const CompressedImageView2D&, const std::string&) const + * @ref exportToFile(const CompressedImageView2D&, const std::string&) */ - Containers::Array exportToData(const CompressedImageView2D& image) const; + Containers::Array exportToData(const CompressedImageView2D& image); /** * @brief Export image to file @@ -164,9 +164,9 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractManagi * @ref Feature::ConvertData is supported. Returns `true` on success, * `false` otherwise. * @see @ref features(), @ref exportToImage(), - * @ref exportToData(const ImageView2D&) const + * @ref exportToData(const ImageView2D&) */ - bool exportToFile(const ImageView2D& image, const std::string& filename) const; + bool exportToFile(const ImageView2D& image, const std::string& filename); /** * @brief Export compressed image to file @@ -175,9 +175,9 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractManagi * @ref Feature::ConvertCompressedData is supported. Returns `true` on * success, `false` otherwise. * @see @ref features(), @ref exportToCompressedImage(), - * @ref exportToData(const CompressedImageView2D&) const + * @ref exportToData(const CompressedImageView2D&) */ - bool exportToFile(const CompressedImageView2D& image, const std::string& filename) const; + bool exportToFile(const CompressedImageView2D& image, const std::string& filename); #ifndef DOXYGEN_GENERATING_OUTPUT private: @@ -188,34 +188,34 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractManagi virtual Features doFeatures() const = 0; /** @brief Implementation of @ref exportToImage() */ - virtual std::optional doExportToImage(const ImageView2D& image) const; + virtual std::optional doExportToImage(const ImageView2D& image); /** @brief Implementation of @ref exportToCompressedImage() */ - virtual std::optional doExportToCompressedImage(const ImageView2D& image) const; + virtual std::optional doExportToCompressedImage(const ImageView2D& image); - /** @brief Implementation of @ref exportToData(const ImageView2D&) const */ - virtual Containers::Array doExportToData(const ImageView2D& image) const; + /** @brief Implementation of @ref exportToData(const ImageView2D&) */ + virtual Containers::Array doExportToData(const ImageView2D& image); - /** @brief Implementation of @ref exportToData(const CompressedImageView2D&) const */ - virtual Containers::Array doExportToData(const CompressedImageView2D& image) const; + /** @brief Implementation of @ref exportToData(const CompressedImageView2D&) */ + virtual Containers::Array doExportToData(const CompressedImageView2D& image); /** - * @brief Implementation of @ref exportToFile(const ImageView2D&, const std::string&) const + * @brief Implementation of @ref exportToFile(const ImageView2D&, const std::string&) * * If @ref Feature::ConvertData is supported, default implementation - * calls @ref doExportToData(const ImageView2D&) const and saves the - * result to given file. + * calls @ref doExportToData(const ImageView2D&) and saves the result + * to given file. */ - virtual bool doExportToFile(const ImageView2D& image, const std::string& filename) const; + virtual bool doExportToFile(const ImageView2D& image, const std::string& filename); /** - * @brief Implementation of @ref exportToFile(const CompressedImageView2D&, const std::string&) const + * @brief Implementation of @ref exportToFile(const CompressedImageView2D&, const std::string&) * * If @ref Feature::ConvertCompressedData is supported, default - * implementation calls @ref doExportToData(const CompressedImageView2D&) const + * implementation calls @ref doExportToData(const CompressedImageView2D&) * and saves the result to given file. */ - virtual bool doExportToFile(const CompressedImageView2D& image, const std::string& filename) const; + virtual bool doExportToFile(const CompressedImageView2D& image, const std::string& filename); }; CORRADE_ENUMSET_OPERATORS(AbstractImageConverter::Features) diff --git a/src/Magnum/Trade/Test/AbstractImageConverterTest.cpp b/src/Magnum/Trade/Test/AbstractImageConverterTest.cpp index 644e330da..439e1c621 100644 --- a/src/Magnum/Trade/Test/AbstractImageConverterTest.cpp +++ b/src/Magnum/Trade/Test/AbstractImageConverterTest.cpp @@ -52,7 +52,7 @@ void AbstractImageConverterTest::exportToFile() { private: Features doFeatures() const override { return Feature::ConvertData; } - Containers::Array doExportToData(const ImageView2D& image) const override { + Containers::Array doExportToData(const ImageView2D& image) override { return Containers::Array::from(char(image.size().x()), char(image.size().y())); }; }; diff --git a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp index 13e6a486d..752efccfa 100644 --- a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp @@ -45,7 +45,7 @@ TgaImageConverter::TgaImageConverter(PluginManager::AbstractManager& manager, st auto TgaImageConverter::doFeatures() const -> Features { return Feature::ConvertData; } -Containers::Array TgaImageConverter::doExportToData(const ImageView2D& image) const { +Containers::Array TgaImageConverter::doExportToData(const ImageView2D& image) { #ifndef MAGNUM_TARGET_GLES if(image.storage().swapBytes()) { Error() << "Trade::TgaImageConverter::exportToData(): pixel byte swap is not supported"; diff --git a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h index 082035afb..62965f476 100644 --- a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h +++ b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h @@ -74,7 +74,7 @@ class MAGNUM_TGAIMAGECONVERTER_EXPORT TgaImageConverter: public AbstractImageCon private: Features MAGNUM_TGAIMAGECONVERTER_LOCAL doFeatures() const override; - Containers::Array MAGNUM_TGAIMAGECONVERTER_LOCAL doExportToData(const ImageView2D& image) const override; + Containers::Array MAGNUM_TGAIMAGECONVERTER_LOCAL doExportToData(const ImageView2D& image) override; }; }}