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 [[nodiscard]] bool hasError() const;
53
54protected:
55 explicit AbstractReader(DataSet *dataSet);
56
57 /** Implement for actual parsing.
58 * The default implementation convert into the respective other form,
59 * so implementing one is enough.
60 */
61 virtual void readFromData(const uint8_t *data, std::size_t len);
62 virtual void readFromIODevice(QIODevice *io);
63
64 /** Add read elements to the merge buffer if set, or the dataset otherwise. */
65 void addNode(OSM::Node &&node);
66 void addWay(OSM::Way &&way);
67 void addRelation(OSM::Relation &&relation);
68
69 DataSet *m_dataSet = nullptr;
70 QString m_error;
71
72private:
73 DataSetMergeBuffer *m_mergeBuffer = nullptr;
74};
75
76}
77
78#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:346
An OSM node.
Definition datatypes.h:204
An OSM relation.
Definition datatypes.h:316
An OSM way.
Definition datatypes.h:232
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 Sat Dec 21 2024 17:06:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.