KOSMIndoorMap

io.cpp
1/*
2 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "io.h"
7#include "ioplugin.h"
8
9#include <QJsonArray>
10#include <QJsonObject>
11#include <QPluginLoader>
12
13#include <optional>
14
15using namespace OSM;
16
17Q_IMPORT_PLUGIN(OSM_O5mIOPlugin)
18Q_IMPORT_PLUGIN(OSM_OscIOPlugin)
19Q_IMPORT_PLUGIN(OSM_XmlIOPlugin)
20
21IOPluginInterface::~IOPluginInterface() = default;
22
23static std::optional<QStaticPlugin> pluginForMetaData(QLatin1String key, QStringView value)
24{
25 const auto plugins = QPluginLoader::staticPlugins();
26 for (const auto &plugin : plugins) {
27 const auto md = plugin.metaData();
28 if (md.value(QLatin1String("IID")).toString() != QLatin1String(OSMIOPluginInteraface_iid)) {
29 continue;
30 }
31 const auto exts = md.value(QLatin1String("MetaData")).toObject().value(key).toArray();
32 for (const auto &ext : exts) {
33 if (value.endsWith(ext.toString(), Qt::CaseInsensitive)) {
34 return plugin;
35 }
36 }
37 }
38
39 return {};
40}
41
42std::unique_ptr<AbstractReader> IO::readerForFileName(QStringView fileName, OSM::DataSet *dataSet)
43{
44 const auto plugin = pluginForMetaData(QLatin1String("fileExtensions"), fileName);
45 if (plugin) {
46 return qobject_cast<IOPluginInterface*>(plugin->instance())->createReader(dataSet);
47 }
48 return {};
49}
50
51std::unique_ptr<AbstractReader> IO::readerForMimeType(QStringView mimeType, OSM::DataSet* dataSet)
52{
53 const auto plugin = pluginForMetaData(QLatin1String("mimetypes"), mimeType);
54 if (plugin) {
55 return qobject_cast<IOPluginInterface*>(plugin->instance())->createReader(dataSet);
56 }
57 return {};
58}
59
60std::unique_ptr<AbstractWriter> IO::writerForFileName(QStringView fileName)
61{
62 const auto plugin = pluginForMetaData(QLatin1String("fileExtensions"), fileName);
63 if (plugin) {
64 return qobject_cast<IOPluginInterface*>(plugin->instance())->createWriter();
65 }
66 return {};
67}
68
69std::unique_ptr<AbstractWriter> IO::writerForMimeType(QStringView mimeType)
70{
71 const auto plugin = pluginForMetaData(QLatin1String("mimeypes"), mimeType);
72 if (plugin) {
73 return qobject_cast<IOPluginInterface*>(plugin->instance())->createWriter();
74 }
75 return {};
76}
A set of nodes, ways and relations.
Definition datatypes.h:346
char * toString(const EngineQuery &query)
KOSM_EXPORT std::unique_ptr< AbstractReader > readerForMimeType(QStringView mimeType, OSM::DataSet *dataSet)
Returns a suitable reader for the given MIME type.
Definition io.cpp:51
KOSM_EXPORT std::unique_ptr< AbstractWriter > writerForMimeType(QStringView mimeType)
Returns a suitable writer for the given MIME type.
Definition io.cpp:69
KOSM_EXPORT std::unique_ptr< AbstractReader > readerForFileName(QStringView fileName, OSM::DataSet *dataSet)
Returns a suitable reader for the given file name.
Definition io.cpp:42
KOSM_EXPORT std::unique_ptr< AbstractWriter > writerForFileName(QStringView fileName)
Returns a suitable writer for the given file name.
Definition io.cpp:60
Low-level types and functions to work with raw OSM data as efficiently as possible.
QList< QStaticPlugin > staticPlugins()
bool endsWith(QChar ch) const const
CaseInsensitive
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:55:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.