diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2019-08-07 07:47:31 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2019-08-07 07:47:31 +0200 |
commit | 8af94d9a048f7d26a8137c3c51dcf47605fcf4b6 (patch) | |
tree | e5ef1654a217bf82f0bb3549d1c8f1762f1a9f25 /src/plugins/sceneparsers/assimp/assimphelpers.cpp | |
parent | 44470868450c440ca874ba585e2b71dfc8e89f1d (diff) | |
parent | 7be8029d4c2cd0ce24f0277d6ee87041161edab4 (diff) |
Merge remote-tracking branch 'qt-gerrit/dev' into wip/refactor
Change-Id: I61324b258ed28d420c96acafd4e624655ffb40e1
Diffstat (limited to 'src/plugins/sceneparsers/assimp/assimphelpers.cpp')
-rw-r--r-- | src/plugins/sceneparsers/assimp/assimphelpers.cpp | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/src/plugins/sceneparsers/assimp/assimphelpers.cpp b/src/plugins/sceneparsers/assimp/assimphelpers.cpp index ce6619541..77209a7a9 100644 --- a/src/plugins/sceneparsers/assimp/assimphelpers.cpp +++ b/src/plugins/sceneparsers/assimp/assimphelpers.cpp @@ -157,29 +157,29 @@ void AssimpIOStream::Flush() * */ -/*! - * Builds a new instance of AssimpIOSystem. - */ -AssimpIOSystem::AssimpIOSystem() : - Assimp::IOSystem() -{ - m_openModeMaps[QByteArrayLiteral("r")] = QIODevice::ReadOnly; - m_openModeMaps[QByteArrayLiteral("r+")] = QIODevice::ReadWrite; - m_openModeMaps[QByteArrayLiteral("w")] = QIODevice::WriteOnly | QIODevice::Truncate; - m_openModeMaps[QByteArrayLiteral("w+")] = QIODevice::ReadWrite | QIODevice::Truncate; - m_openModeMaps[QByteArrayLiteral("a")] = QIODevice::WriteOnly | QIODevice::Append; - m_openModeMaps[QByteArrayLiteral("a+")] = QIODevice::ReadWrite | QIODevice::Append; - m_openModeMaps[QByteArrayLiteral("wb")] = QIODevice::WriteOnly; - m_openModeMaps[QByteArrayLiteral("wt")] = QIODevice::WriteOnly | QIODevice::Text; - m_openModeMaps[QByteArrayLiteral("rb")] = QIODevice::ReadOnly; - m_openModeMaps[QByteArrayLiteral("rt")] = QIODevice::ReadOnly | QIODevice::Text; -} - -/*! - * Clears an AssimpIOSystem instance before deletion. - */ -AssimpIOSystem::~AssimpIOSystem() +static QIODevice::OpenMode openModeFromText(const char *name) noexcept { + static const struct OpenModeMapping { + char name[2]; + ushort mode; + } openModeMapping[] = { + { { 'r', 0 }, QIODevice::ReadOnly }, + { { 'r', '+' }, QIODevice::ReadWrite }, + { { 'w', 0 }, QIODevice::WriteOnly | QIODevice::Truncate }, + { { 'w', '+' }, QIODevice::ReadWrite | QIODevice::Truncate }, + { { 'a', 0 }, QIODevice::WriteOnly | QIODevice::Append }, + { { 'a', '+' }, QIODevice::ReadWrite | QIODevice::Append }, + { { 'w', 'b' }, QIODevice::WriteOnly }, + { { 'w', 't' }, QIODevice::WriteOnly | QIODevice::Text }, + { { 'r', 'b' }, QIODevice::ReadOnly }, + { { 'r', 't' }, QIODevice::ReadOnly | QIODevice::Text }, + }; + + for (auto e : openModeMapping) { + if (qstrncmp(e.name, name, sizeof(OpenModeMapping::name)) == 0) + return static_cast<QIODevice::OpenMode>(e.mode); + } + return QIODevice::NotOpen; } /*! @@ -205,14 +205,13 @@ char AssimpIOSystem::getOsSeparator() const Assimp::IOStream *AssimpIOSystem::Open(const char *pFile, const char *pMode) { const QString fileName(QString::fromUtf8(pFile)); - const QByteArray cleanedMode(QByteArray(pMode).trimmed()); - - const QIODevice::OpenMode openMode = m_openModeMaps.value(cleanedMode, QIODevice::NotOpen); - - QScopedPointer<QFile> file(new QFile(fileName)); - if (file->open(openMode)) - return new AssimpIOStream(file.take()); + const QLatin1String cleanedMode = QLatin1String{pMode}.trimmed(); + if (const QIODevice::OpenMode openMode = openModeFromText(cleanedMode.data())) { + QScopedPointer<QFile> file(new QFile(fileName)); + if (file->open(openMode)) + return new AssimpIOStream(file.take()); + } return nullptr; } |