KOSMIndoorMap

abstractreader.h
1/*
2 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#ifndef OSM_ABSTRACTREADER_H
7#define OSM_ABSTRACTREADER_H
8
9#include "kosm_export.h"
10
11#include <QString>
12
13#include <cstdint>
14#include <cstddef>
15
16class QIODevice;
17
18namespace OSM {
19
20class DataSet;
21class DataSetMergeBuffer;
22class Node;
23class Relation;
24class Way;
25
26/** Abstract base class for OSM file format readers. */
27class KOSM_EXPORT AbstractReader
28{
29public:
30 virtual ~AbstractReader();
31
32 /** Sets a merge buffer.
33 * When set, the parser will insert all elements into that buffer
34 * rather than in the OSM::DataSet specified in the constructor.
35 * It is then your responsibility to properly integrate those.
36 * @note The OSM::DataSet is used for generating tag keys and for memory
37 * managing strings in this case as well. So the generated elements are
38 * tied to the OSM::DataSet in any case.
39 */
40 void setMergeBuffer(OSM::DataSetMergeBuffer *buffer);
41
42 /** Read the given data.
43 * Useful e.g. for working on memory-mapped data.
44 */
45 void read(const uint8_t *data, std::size_t len);
46
47 /** Read data from the given QIODevice. */
48 void read(QIODevice *io);
49
50 /** Error message in case parsing failed for some reason. */
51 [[nodiscard]] QString errorString() const;
52
53protected:
54 explicit AbstractReader(DataSet *dataSet);
55
56 /** Implement for actual parsing.
57 * The default implementation convert into the respective other form,
58 * so implementing one is enough.
59 */
60 virtual void readFromData(const uint8_t *data, std::size_t len);
61 virtual void readFromIODevice(QIODevice *io);
62
63 /** Add read elements to the merge buffer if set, or the dataset otherwise. */
64 void addNode(OSM::Node &&node);
65 void addWay(OSM::Way &&way);
66 void addRelation(OSM::Relation &&relation);
67
68 DataSet *m_dataSet = nullptr;
69 QString m_error;
70
71private:
72 DataSetMergeBuffer *m_mergeBuffer = nullptr;
73};
74
75}
76
77#endif // OSM_ABSTRACTREADER_H
Abstract base class for OSM file format readers.
Holds OSM elements produced by a parser prior to merging into OSM::DataSet.
A set of nodes, ways and relations.
Definition datatypes.h:340
An OSM node.
Definition datatypes.h:204
An OSM relation.
Definition datatypes.h:311
An OSM way.
Definition datatypes.h:231
Low-level types and functions to work with raw OSM data as efficiently as possible.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.