File: replication.cc

package info (click to toggle)
pyosmium 4.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,584 kB
  • sloc: python: 4,400; cpp: 2,504; makefile: 20
file content (50 lines) | stat: -rw-r--r-- 1,166 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
45
46
47
48
49
50
/* 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.
 */
#include <pybind11/pybind11.h>

#include <osmium/osm.hpp>
#include <osmium/io/any_input.hpp>
#include <osmium/handler.hpp>
#include <osmium/visitor.hpp>
#include "cast.h"

namespace py = pybind11;

namespace {

struct LastChangeHandler : public osmium::handler::Handler
{
    osmium::Timestamp last_change;

    void osm_object(osmium::OSMObject const &obj)
    {
        if (obj.timestamp() > last_change) {
            last_change = obj.timestamp();
        }
    }
};

} // namespace

#ifdef Py_GIL_DISABLED
PYBIND11_MODULE(_replication, m, py::mod_gil_not_used())
#else
PYBIND11_MODULE(_replication, m)
#endif
{
    m.def("newest_change_from_file", [](char const *filename)
        {
            osmium::io::Reader reader(filename, osmium::osm_entity_bits::nwr);

            LastChangeHandler handler;
            osmium::apply(reader, handler);
            reader.close();

            return handler.last_change;
        });
}