From 440ece15fb93304da9a5451e7bcda543b9dde569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 23 Oct 2021 20:47:40 +0200 Subject: [PATCH] Audio,Text,Trade: accept void ArrayViews in importer plugins. This makes it much less annoying to pass arbitrarily typed data, such as std::uint8_t or char8_t and what not. It was already done like this for the new shader converter plugins, where the input is often 32-bit ints for SPIR-V. OTOH the internal virtual API is kept with ArrayView, as that makes it easier to operate on by the implementations. --- doc/changelog.dox | 2 +- src/Magnum/Audio/AbstractImporter.cpp | 4 ++-- src/Magnum/Audio/AbstractImporter.h | 2 +- src/Magnum/Text/AbstractFont.cpp | 4 ++-- src/Magnum/Text/AbstractFont.h | 10 +++++----- src/Magnum/Trade/AbstractImporter.cpp | 4 ++-- src/Magnum/Trade/AbstractImporter.h | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 5840aa5d2..8179ab6ae 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -2305,7 +2305,7 @@ Released 2019-10-24, tagged as - @cpp Text::AbstractFont::openSingleData() @ce and @cpp Text::AbstractFont::openData() @ce taking a list of files are deprecated in favor of - @ref Text::AbstractFont::openData(Containers::ArrayView, Float) + @ref Text::AbstractFont::openData(Containers::ArrayView, Float) and @ref Text::AbstractFont::setFileCallback() - @ref GL::Buffer::setData() and @ref GL::Buffer::setSubData() no longer has overloads taking @ref std::vector / @ref std::array, but instead relies on diff --git a/src/Magnum/Audio/AbstractImporter.cpp b/src/Magnum/Audio/AbstractImporter.cpp index eed7b40d5..0f7159c79 100644 --- a/src/Magnum/Audio/AbstractImporter.cpp +++ b/src/Magnum/Audio/AbstractImporter.cpp @@ -73,12 +73,12 @@ AbstractImporter::AbstractImporter(PluginManager::Manager& man AbstractImporter::AbstractImporter(PluginManager::AbstractManager& manager, const std::string& plugin): PluginManager::AbstractManagingPlugin{manager, plugin} {} -bool AbstractImporter::openData(Containers::ArrayView data) { +bool AbstractImporter::openData(Containers::ArrayView data) { CORRADE_ASSERT(features() & ImporterFeature::OpenData, "Audio::AbstractImporter::openData(): feature not supported", {}); close(); - doOpenData(data); + doOpenData(Containers::arrayCast(data)); return isOpened(); } diff --git a/src/Magnum/Audio/AbstractImporter.h b/src/Magnum/Audio/AbstractImporter.h index 3c033bcb1..1d4f8489d 100644 --- a/src/Magnum/Audio/AbstractImporter.h +++ b/src/Magnum/Audio/AbstractImporter.h @@ -167,7 +167,7 @@ class MAGNUM_AUDIO_EXPORT AbstractImporter: public PluginManager::AbstractManagi * Returns @cpp true @ce on success, @cpp false @ce otherwise. * @see @ref features(), @ref openFile() */ - bool openData(Containers::ArrayView data); + bool openData(Containers::ArrayView data); /** * @brief Open file diff --git a/src/Magnum/Text/AbstractFont.cpp b/src/Magnum/Text/AbstractFont.cpp index 5b3539c1f..5dcab8277 100644 --- a/src/Magnum/Text/AbstractFont.cpp +++ b/src/Magnum/Text/AbstractFont.cpp @@ -87,7 +87,7 @@ void AbstractFont::setFileCallback(Containers::Optional>(*)(const std::string&, InputFileCallbackPolicy, void*), void*) {} -bool AbstractFont::openData(Containers::ArrayView data, const Float size) { +bool AbstractFont::openData(Containers::ArrayView data, const Float size) { CORRADE_ASSERT(features() & FontFeature::OpenData, "Text::AbstractFont::openData(): feature not supported", false); @@ -95,7 +95,7 @@ bool AbstractFont::openData(Containers::ArrayView data, const Float the check doesn't be done on the plugin side) because for some file formats it could be valid (MagnumFont in particular). */ close(); - const Metrics metrics = doOpenData(data, size); + const Metrics metrics = doOpenData(Containers::arrayCast(data), size); _size = metrics.size; _ascent = metrics.ascent; _descent = metrics.descent; diff --git a/src/Magnum/Text/AbstractFont.h b/src/Magnum/Text/AbstractFont.h index 65b0ab721..37a3443c6 100644 --- a/src/Magnum/Text/AbstractFont.h +++ b/src/Magnum/Text/AbstractFont.h @@ -318,20 +318,20 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin { * Returns @cpp true @ce on success, @cpp false @ce otherwise. * @see @ref features(), @ref openFile() */ - bool openData(Containers::ArrayView data, Float size); + bool openData(Containers::ArrayView data, Float size); #ifdef MAGNUM_BUILD_DEPRECATED - /** @brief @copybrief openData(Containers::ArrayView, Float) + /** @brief @copybrief openData(Containers::ArrayView, Float) * @m_deprecated_since{2019,10} Use @ref openFile() with * @ref setFileCallback() for opening multi-file fonts instead. */ CORRADE_DEPRECATED("use openFile() with setFileCallback() for opening multi-file fonts instead") bool openData(const std::vector>>& data, Float size); - /** @brief @copybrief openData(Containers::ArrayView, Float) - * @m_deprecated_since{2019,10} Use @ref openData(Containers::ArrayView, Float) + /** @brief @copybrief openData(Containers::ArrayView, Float) + * @m_deprecated_since{2019,10} Use @ref openData(Containers::ArrayView, Float) * instead. */ - CORRADE_DEPRECATED("use openData(Containers::ArrayView, Float) instead") bool openSingleData(Containers::ArrayView data, Float size); + CORRADE_DEPRECATED("use openData(Containers::ArrayView, Float) instead") bool openSingleData(Containers::ArrayView data, Float size); #endif /** diff --git a/src/Magnum/Trade/AbstractImporter.cpp b/src/Magnum/Trade/AbstractImporter.cpp index d76761c4d..ec82f5e53 100644 --- a/src/Magnum/Trade/AbstractImporter.cpp +++ b/src/Magnum/Trade/AbstractImporter.cpp @@ -123,7 +123,7 @@ void AbstractImporter::setFileCallback(Containers::Optional>(*)(const std::string&, InputFileCallbackPolicy, void*), void*) {} -bool AbstractImporter::openData(Containers::ArrayView data) { +bool AbstractImporter::openData(Containers::ArrayView data) { CORRADE_ASSERT(features() & ImporterFeature::OpenData, "Trade::AbstractImporter::openData(): feature not supported", {}); @@ -131,7 +131,7 @@ bool AbstractImporter::openData(Containers::ArrayView data) { the check doesn't be done on the plugin side) because for some file formats it could be valid (e.g. OBJ or JSON-based formats). */ close(); - doOpenData(Containers::Array{const_cast(data.data()), data.size(), Implementation::nonOwnedArrayDeleter}, {}); + doOpenData(Containers::Array{const_cast(static_cast(data.data())), data.size(), Implementation::nonOwnedArrayDeleter}, {}); return isOpened(); } diff --git a/src/Magnum/Trade/AbstractImporter.h b/src/Magnum/Trade/AbstractImporter.h index cd2690a00..a34628e83 100644 --- a/src/Magnum/Trade/AbstractImporter.h +++ b/src/Magnum/Trade/AbstractImporter.h @@ -633,7 +633,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi * @p data is not expected to be alive after the function exits. * @see @ref features(), @ref openFile() */ - bool openData(Containers::ArrayView data); + bool openData(Containers::ArrayView data); /** * @brief Open already loaded state