File indexing completed on 2024-10-27 13:24:18
0001 /* 0002 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #ifndef OSM_ABSTRACTREADER_H 0007 #define OSM_ABSTRACTREADER_H 0008 0009 #include "kosm_export.h" 0010 0011 #include <QString> 0012 0013 #include <cstdint> 0014 #include <cstddef> 0015 0016 class QIODevice; 0017 0018 namespace OSM { 0019 0020 class DataSet; 0021 class DataSetMergeBuffer; 0022 class Node; 0023 class Relation; 0024 class Way; 0025 0026 /** Abstract base class for OSM file format readers. */ 0027 class KOSM_EXPORT AbstractReader 0028 { 0029 public: 0030 virtual ~AbstractReader(); 0031 0032 /** Sets a merge buffer. 0033 * When set, the parser will insert all elements into that buffer 0034 * rather than in the OSM::DataSet specified in the constructor. 0035 * It is then your responsibility to properly integrate those. 0036 * @note The OSM::DataSet is used for generating tag keys and for memory 0037 * managing strings in this case as well. So the generated elements are 0038 * tied to the OSM::DataSet in any case. 0039 */ 0040 void setMergeBuffer(OSM::DataSetMergeBuffer *buffer); 0041 0042 /** Read the given data. 0043 * Useful e.g. for working on memory-mapped data. 0044 */ 0045 void read(const uint8_t *data, std::size_t len); 0046 0047 /** Read data from the given QIODevice. */ 0048 void read(QIODevice *io); 0049 0050 /** Error message in case parsing failed for some reason. */ 0051 QString errorString() const; 0052 0053 protected: 0054 explicit AbstractReader(DataSet *dataSet); 0055 0056 /** Implement for actual parsing. 0057 * The default implementation convert into the respective other form, 0058 * so implementing one is enough. 0059 */ 0060 virtual void readFromData(const uint8_t *data, std::size_t len); 0061 virtual void readFromIODevice(QIODevice *io); 0062 0063 /** Add read elements to the merge buffer if set, or the dataset otherwise. */ 0064 void addNode(OSM::Node &&node); 0065 void addWay(OSM::Way &&way); 0066 void addRelation(OSM::Relation &&relation); 0067 0068 DataSet *m_dataSet = nullptr; 0069 QString m_error; 0070 0071 private: 0072 DataSetMergeBuffer *m_mergeBuffer = nullptr; 0073 }; 0074 0075 } 0076 0077 #endif // OSM_ABSTRACTREADER_H