File indexing completed on 2024-05-12 04:42:18

0001 /*
0002     SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #ifndef OSM_OSMPBFWRITER_H
0007 #define OSM_OSMPBFWRITER_H
0008 
0009 #include "abstractwriter.h"
0010 
0011 #include <cstdint>
0012 #include <cstring>
0013 #include <string>
0014 
0015 #include <QDebug>
0016 
0017 namespace OSMPBF {
0018 class PrimitiveBlock;
0019 }
0020 
0021 namespace OSM {
0022 
0023 /** Serialize an OSM::DataSet into the PBF file format. */
0024 class OsmPbfWriter : public OSM::AbstractWriter
0025 {
0026 public:
0027     explicit OsmPbfWriter();
0028     ~OsmPbfWriter() override;
0029 private:
0030     void writeToIODevice(const OSM::DataSet &dataSet, QIODevice *io) override;
0031 
0032     void writeNodes(const OSM::DataSet &dataSet);
0033     void writeWays(const OSM::DataSet &dataSet);
0034     void writeRelations(const OSM::DataSet &dataSet);
0035 
0036     [[nodiscard]] int32_t stringTableEntry(const char *s);
0037     void createBlockIfNeeded();
0038     [[nodiscard]] bool blockSizeLimitReached() const;
0039     void writeBlob();
0040 
0041     std::unique_ptr<OSMPBF::PrimitiveBlock> m_block;
0042     std::map<std::string_view, int32_t> m_stringTable;
0043     std::size_t m_blockSizeEstimate = 0;
0044     QIODevice *m_io = nullptr;
0045 };
0046 
0047 }
0048 
0049 #endif