File: osmium_benchmark_write_pbf.cpp

package info (click to toggle)
libosmium 2.22.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,544 kB
  • sloc: cpp: 52,804; sh: 148; makefile: 19
file content (44 lines) | stat: -rw-r--r-- 1,135 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*

  The code in this file is released into the Public Domain.

*/

#include <osmium/io/any_input.hpp>
#include <osmium/io/any_output.hpp>

#include <cstdlib>
#include <exception>
#include <iostream>
#include <string>
#include <utility>

int main(int argc, char* argv[]) {
    if (argc != 3) {
        std::cerr << "Usage: " << argv[0] << " INPUT-FILE OUTPUT-FILE\n";
        return 1;
    }

    try {
        const std::string input_filename{argv[1]};
        const std::string output_filename{argv[2]};

        osmium::io::Reader reader{input_filename};
        const osmium::io::File output_file{output_filename, "pbf"};
        const osmium::io::Header header;
        osmium::io::Writer writer{output_file, header, osmium::io::overwrite::allow};

        while (osmium::memory::Buffer buffer = reader.read()) { // NOLINT(bugprone-use-after-move) Bug in clang-tidy https://bugs.llvm.org/show_bug.cgi?id=36516
            writer(std::move(buffer));
        }

        writer.close();
        reader.close();
    } catch (const std::exception& e) {
        std::cerr << e.what() << '\n';
        return 1;
    }

    return 0;
}