Browse Source

Trade: why am I returning naked pointer from a function?!

pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
ad2b26c0b2
  1. 12
      src/Magnum/Trade/AbstractImageConverter.cpp
  2. 7
      src/Magnum/Trade/AbstractImageConverter.h

12
src/Magnum/Trade/AbstractImageConverter.cpp

@ -29,22 +29,24 @@
#include <Corrade/Utility/Assert.h> #include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/Directory.h> #include <Corrade/Utility/Directory.h>
#include "Magnum/Image.h"
namespace Magnum { namespace Trade { namespace Magnum { namespace Trade {
AbstractImageConverter::AbstractImageConverter() = default; AbstractImageConverter::AbstractImageConverter() = default;
AbstractImageConverter::AbstractImageConverter(PluginManager::AbstractManager& manager, std::string plugin): AbstractPlugin(manager, std::move(plugin)) {} AbstractImageConverter::AbstractImageConverter(PluginManager::AbstractManager& manager, std::string plugin): AbstractPlugin(manager, std::move(plugin)) {}
Image2D* AbstractImageConverter::exportToImage(const ImageReference2D& image) const { std::optional<Image2D> AbstractImageConverter::exportToImage(const ImageReference2D& image) const {
CORRADE_ASSERT(features() & Feature::ConvertImage, CORRADE_ASSERT(features() & Feature::ConvertImage,
"Trade::AbstractImageConverter::exportToImage(): feature not supported", nullptr); "Trade::AbstractImageConverter::exportToImage(): feature not supported", {});
return doExportToImage(image); return doExportToImage(image);
} }
Image2D* AbstractImageConverter::doExportToImage(const ImageReference2D&) const { std::optional<Image2D> AbstractImageConverter::doExportToImage(const ImageReference2D&) const {
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToImage(): feature advertised but not implemented", nullptr); CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToImage(): feature advertised but not implemented", {});
return nullptr; return std::nullopt;
} }
Containers::Array<char> AbstractImageConverter::exportToData(const ImageReference2D& image) const { Containers::Array<char> AbstractImageConverter::exportToData(const ImageReference2D& image) const {

7
src/Magnum/Trade/AbstractImageConverter.h

@ -34,6 +34,7 @@
#include "Magnum/Magnum.h" #include "Magnum/Magnum.h"
#include "Magnum/visibility.h" #include "Magnum/visibility.h"
#include "Magnum/Text/Text.h" #include "Magnum/Text/Text.h"
#include "MagnumExternal/Optional/optional.hpp"
namespace Magnum { namespace Trade { namespace Magnum { namespace Trade {
@ -95,10 +96,10 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
* @brief Convert image to different format * @brief Convert image to different format
* *
* Available only if @ref Feature::ConvertImage is supported. Returns * Available only if @ref Feature::ConvertImage is supported. Returns
* converted image on success, `nullptr` otherwise. * converted image on success, `std::nullopt` otherwise.
* @see @ref features(), @ref exportToData(), @ref exportToFile() * @see @ref features(), @ref exportToData(), @ref exportToFile()
*/ */
Image2D* exportToImage(const ImageReference2D& image) const; std::optional<Image2D> exportToImage(const ImageReference2D& image) const;
/** /**
* @brief Export image to raw data * @brief Export image to raw data
@ -126,7 +127,7 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
virtual Features doFeatures() const = 0; virtual Features doFeatures() const = 0;
/** @brief Implementation of @ref exportToImage() */ /** @brief Implementation of @ref exportToImage() */
virtual Image2D* doExportToImage(const ImageReference2D& image) const; virtual std::optional<Image2D> doExportToImage(const ImageReference2D& image) const;
/** @brief Implementation of @ref exportToData() */ /** @brief Implementation of @ref exportToData() */
virtual Containers::Array<char> doExportToData(const ImageReference2D& image) const; virtual Containers::Array<char> doExportToData(const ImageReference2D& image) const;

Loading…
Cancel
Save