KOSMIndoorMap

o5mparser.h
1 /*
2  SPDX-FileCopyrightText: 2020 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef OSM_O5MPARSER_H
8 #define OSM_O5MPARSER_H
9 
10 #include "kosm_export.h"
11 
12 #include <cstddef>
13 #include <cstdint>
14 #include <vector>
15 
16 class O5mParserTest;
17 
18 namespace OSM {
19 
20 class DataSet;
21 class DataSetMergeBuffer;
22 
23 /** Zero-copy parser of O5M binary files.
24  * @see https://wiki.openstreetmap.org/wiki/O5m
25  */
26 class KOSM_EXPORT O5mParser
27 {
28 public:
29  explicit O5mParser(DataSet *dataSet);
30 
31  /** Sets a merge buffer.
32  * When set, the parser will insert all elements into that buffer
33  * rather than in the OSM::DataSet specified in the constructor.
34  * It is then your responsibility to properly integrate those.
35  * @note The OSM::DataSet is used for generating tag keys and for memory
36  * managing strings in this case as well. So the generated elements are
37  * tied to the OSM::DataSet in any case.
38  */
39  void setMergeBuffer(OSM::DataSetMergeBuffer *buffer);
40 
41  /** Parse the given binary content.
42  * Feed this with QFile::map() for example.
43  */
44  void parse(const uint8_t *data, std::size_t len);
45 
46 private:
47  friend class ::O5mParserTest;
48 
49  uint64_t readUnsigned(const uint8_t *&it, const uint8_t *endIt) const;
50  int64_t readSigned(const uint8_t *&it, const uint8_t *endIt) const;
51  template <typename T>
52  T readDelta(const uint8_t *&it, const uint8_t *endIt, T &deltaState);
53 
54  const char* readString(const uint8_t *&it, const uint8_t *endIt);
55  std::pair<const char*, const char*> readStringPair(const uint8_t *&it, const uint8_t *endIt);
56 
57  void skipVersionInformation(const uint8_t *&it, const uint8_t *end);
58  template <typename Elem>
59  void readTagOrBbox(Elem &e, const uint8_t *&it, const uint8_t *endIt);
60 
61  void readNode(const uint8_t *begin, const uint8_t *end);
62  void readWay(const uint8_t *begin, const uint8_t *end);
63  void readRelation(const uint8_t *begin, const uint8_t *end);
64 
65  DataSet *m_dataSet = nullptr;
66  DataSetMergeBuffer *m_mergeBuffer = nullptr;
67 
68  // delta coding state
69  void resetDeltaCodingState();
70 
71  int64_t m_nodeIdDelta = 0;
72  int32_t m_latDelata = 0; // this can overflow, but that is intentional according to the spec!
73  int32_t m_lonDelta = 0;
74 
75  int64_t m_wayIdDelta = 0;
76  int64_t m_wayNodeIdDelta = 0;
77 
78  int64_t m_relIdDelta = 0;
79  int64_t m_relNodeMemberIdDelta = 0;
80  int64_t m_relWayMemberIdDelta = 0;
81  int64_t m_relRelMemberIdDelta = 0;
82 
83  std::vector<const char*> m_stringLookupTable;
84  uint16_t m_stringLookupPosition = 0;
85 };
86 
87 }
88 
89 #endif // OSM_O5MPARSER_H
Holds OSM elements produced by a parser prior to merging into OSM::DataSet.
Zero-copy parser of O5M binary files.
Definition: o5mparser.h:26
A set of nodes, ways and relations.
Definition: datatypes.h:283
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-2021 The KDE developers.
Generated on Mon Oct 25 2021 23:04:00 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.