File: io.h

package info (click to toggle)
pyosmium 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,600 kB
  • sloc: python: 4,493; cpp: 2,616; makefile: 21
file content (66 lines) | stat: -rw-r--r-- 1,940 bytes parent folder | download | duplicates (2)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* SPDX-License-Identifier: BSD-2-Clause
 *
 * This file is part of pyosmium. (https://osmcode.org/pyosmium/)
 *
 * Copyright (C) 2025 Sarah Hoffmann <lonvia@denofr.de> and others.
 * For a full list of authors see the git log.
 */
#ifndef PYOSMIUM_IO_H
#define PYOSMIUM_IO_H

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

namespace pyosmium {

class PyReader
{
public:
    explicit PyReader(osmium::io::File fname)
    : thread_pool(std::make_unique<osmium::thread::Pool>()),
      reader(std::move(fname))
    {}

    PyReader(osmium::io::File fname, osmium::osm_entity_bits::type const *etype,
             osmium::thread::Pool *pool)
    : thread_pool(pool ? std::unique_ptr<osmium::thread::Pool>()
                       : std::make_unique<osmium::thread::Pool>()),
      reader(std::move(fname),
             etype ? *etype : osmium::osm_entity_bits::all,
             *(pool ? pool : thread_pool.get()))
    {}

    osmium::io::Reader const *get() const { return &reader; }
    osmium::io::Reader *get() { return &reader; }

private:
    std::unique_ptr<osmium::thread::Pool> thread_pool;
    osmium::io::Reader reader;
};


class PyWriter
{
public:
    PyWriter(osmium::io::File file, osmium::io::Header const *header,
             bool overwrite, osmium::thread::Pool *pool)
    : thread_pool(pool ? std::unique_ptr<osmium::thread::Pool>()
                       : std::make_unique<osmium::thread::Pool>()),
      writer(std::move(file),
             header ? *header : osmium::io::Header(),
             overwrite ? osmium::io::overwrite::allow : osmium::io::overwrite::no,
             *(pool ? pool : thread_pool.get()))
    {}

    osmium::io::Writer const *get() const { return &writer; }
    osmium::io::Writer *get() { return &writer; }

private:
    std::unique_ptr<osmium::thread::Pool> thread_pool;
    osmium::io::Writer writer;
};

}

#endif // PYOSMIUM_IO_H