File indexing completed on 2024-12-01 10:29:54

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef OSM_O5MPARSER_H
0008 #define OSM_O5MPARSER_H
0009 
0010 #include "kosm_export.h"
0011 #include "abstractreader.h"
0012 
0013 #include <cstddef>
0014 #include <cstdint>
0015 #include <vector>
0016 
0017 class O5mParserTest;
0018 
0019 namespace OSM {
0020 
0021 class DataSet;
0022 class DataSetMergeBuffer;
0023 
0024 /** Zero-copy parser of O5M binary files.
0025  *  @see https://wiki.openstreetmap.org/wiki/O5m
0026  */
0027 class KOSM_EXPORT O5mParser : public AbstractReader
0028 {
0029 public:
0030     explicit O5mParser(DataSet *dataSet);
0031 
0032 private:
0033     void readFromData(const uint8_t *data, std::size_t len) override;
0034 
0035     friend class ::O5mParserTest;
0036 
0037     uint64_t readUnsigned(const uint8_t *&it, const uint8_t *endIt) const;
0038     int64_t readSigned(const uint8_t *&it, const uint8_t *endIt) const;
0039     template <typename T>
0040     T readDelta(const uint8_t *&it, const uint8_t *endIt, T &deltaState);
0041 
0042     const char* readString(const uint8_t *&it, const uint8_t *endIt);
0043     std::pair<const char*, const char*> readStringPair(const uint8_t *&it, const uint8_t *endIt);
0044 
0045     void skipVersionInformation(const uint8_t *&it, const uint8_t *end);
0046     template <typename Elem>
0047     void readTagOrBbox(Elem &e, const uint8_t *&it, const uint8_t *endIt);
0048 
0049     void readNode(const uint8_t *begin, const uint8_t *end);
0050     void readWay(const uint8_t *begin, const uint8_t *end);
0051     void readRelation(const uint8_t *begin, const uint8_t *end);
0052 
0053     // delta coding state
0054     void resetDeltaCodingState();
0055 
0056     int64_t m_nodeIdDelta = 0;
0057     int32_t m_latDelata = 0; // this can overflow, but that is intentional according to the spec!
0058     int32_t m_lonDelta = 0;
0059 
0060     int64_t m_wayIdDelta = 0;
0061     int64_t m_wayNodeIdDelta = 0;
0062 
0063     int64_t m_relIdDelta = 0;
0064     int64_t m_relNodeMemberIdDelta = 0;
0065     int64_t m_relWayMemberIdDelta = 0;
0066     int64_t m_relRelMemberIdDelta = 0;
0067 
0068     std::vector<const char*> m_stringLookupTable;
0069     uint16_t m_stringLookupPosition = 0;
0070 };
0071 
0072 }
0073 
0074 #endif // OSM_O5MPARSER_H