File indexing completed on 2024-12-01 10:29:53
0001 /* 0002 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #ifndef OSM_IOPLUGIN_H 0007 #define OSM_IOPLUGIN_H 0008 0009 #include "kosm_export.h" 0010 #include "abstractwriter.h" 0011 0012 #include <QtPlugin> 0013 0014 #include <memory> 0015 0016 namespace OSM { 0017 0018 class AbstractReader; 0019 class AbstractWriter; 0020 class DataSet; 0021 0022 /** Plugin interface for OSM file/data readers. */ 0023 class KOSM_EXPORT IOPluginInterface 0024 { 0025 public: 0026 virtual ~IOPluginInterface(); 0027 0028 /** Create a new reader instance. */ 0029 virtual std::unique_ptr<AbstractReader> createReader(OSM::DataSet *dataSet) = 0; 0030 /** Create a new writer instance. */ 0031 virtual std::unique_ptr<AbstractWriter> createWriter() = 0; 0032 }; 0033 0034 template <typename ReaderT, typename WriterT = std::nullptr_t> 0035 class IOPlugin : public IOPluginInterface 0036 { 0037 public: 0038 inline std::unique_ptr<AbstractReader> createReader(OSM::DataSet *dataSet) override 0039 { 0040 return std::make_unique<ReaderT>(dataSet); 0041 } 0042 inline std::unique_ptr<AbstractWriter> createWriter() override 0043 { 0044 if constexpr(!std::is_same_v<WriterT, std::nullptr_t>) { 0045 return std::make_unique<WriterT>(); 0046 } 0047 return {}; 0048 } 0049 }; 0050 0051 } 0052 0053 #define OSMIOPluginInteraface_iid "org.kde.kosm.IOPluginInterface/1.0" 0054 Q_DECLARE_INTERFACE(OSM::IOPluginInterface, OSMIOPluginInteraface_iid) 0055 0056 #endif // OSM_IOPLUGIN_H 0057