Libosmium  2.17.0
Fast and flexible C++ library for working with OpenStreetMap data
Loading...
Searching...
No Matches
check_order.hpp
Go to the documentation of this file.
1#ifndef OSMIUM_HANDLER_CHECK_ORDER_HPP
2#define OSMIUM_HANDLER_CHECK_ORDER_HPP
3
4/*
5
6This file is part of Osmium (https://osmcode.org/libosmium).
7
8Copyright 2013-2021 Jochen Topf <jochen@topf.org> and others (see README).
9
10Boost Software License - Version 1.0 - August 17th, 2003
11
12Permission is hereby granted, free of charge, to any person or organization
13obtaining a copy of the software and accompanying documentation covered by
14this license (the "Software") to use, reproduce, display, distribute,
15execute, and transmit the Software, and to prepare derivative works of the
16Software, and to permit third-parties to whom the Software is furnished to
17do so, all subject to the following:
18
19The copyright notices in the Software and this entire statement, including
20the above license grant, this restriction and the following disclaimer,
21must be included in all copies of the Software, in whole or in part, and
22all derivative works of the Software, unless such copies or derivative
23works are solely in the form of machine-executable object code generated by
24a source language processor.
25
26THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32DEALINGS IN THE SOFTWARE.
33
34*/
35
36#include <osmium/handler.hpp>
37#include <osmium/osm/node.hpp>
40#include <osmium/osm/types.hpp>
41#include <osmium/osm/way.hpp>
42
43#include <limits>
44#include <stdexcept>
45#include <string>
46
47namespace osmium {
48
53 struct out_of_order_error : public std::runtime_error {
54
56
57 explicit out_of_order_error(const std::string& what, osmium::object_id_type id) :
58 std::runtime_error(what),
59 object_id(id) {
60 }
61
62 explicit out_of_order_error(const char* what, osmium::object_id_type id) :
63 std::runtime_error(what),
64 object_id(id) {
65 }
66
67 }; // struct out_of_order_error
68
69 namespace handler {
70
88
89 osmium::object_id_type m_max_node_id = std::numeric_limits<osmium::object_id_type>::min();
90 osmium::object_id_type m_max_way_id = std::numeric_limits<osmium::object_id_type>::min();
91 osmium::object_id_type m_max_relation_id = std::numeric_limits<osmium::object_id_type>::min();
92
93 public:
94
95 void node(const osmium::Node& node) {
96 if (m_max_way_id > std::numeric_limits<osmium::object_id_type>::min()) {
97 throw out_of_order_error{"Found a node after a way.", node.id()};
98 }
99 if (m_max_relation_id > std::numeric_limits<osmium::object_id_type>::min()) {
100 throw out_of_order_error{"Found a node after a relation.", node.id()};
101 }
102
103 if (m_max_node_id == node.id()) {
104 throw out_of_order_error{"Node ID twice in input. Maybe you are using a history or change file?", node.id()};
105 }
106 if (id_order{}(node.id(), m_max_node_id)) {
107 throw out_of_order_error{"Node IDs out of order.", node.id()};
108 }
109 m_max_node_id = node.id();
110 }
111
112 void way(const osmium::Way& way) {
113 if (m_max_relation_id > std::numeric_limits<osmium::object_id_type>::min()) {
114 throw out_of_order_error{"Found a way after a relation.", way.id()};
115 }
116
117 if (m_max_way_id == way.id()) {
118 throw out_of_order_error{"Way ID twice in input. Maybe you are using a history or change file?", way.id()};
119 }
120 if (id_order{}(way.id(), m_max_way_id)) {
121 throw out_of_order_error{"Way IDs out of order.", way.id()};
122 }
123 m_max_way_id = way.id();
124 }
125
127 if (m_max_relation_id == relation.id()) {
128 throw out_of_order_error{"Relation ID twice in input. Maybe you are using a history or change file?", relation.id()};
129 }
130 if (id_order{}(relation.id(), m_max_relation_id)) {
131 throw out_of_order_error{"Relation IDs out of order.", relation.id()};
132 }
134 }
135
137 return m_max_node_id;
138 }
139
141 return m_max_way_id;
142 }
143
145 return m_max_relation_id;
146 }
147
148 }; // class CheckOrder
149
150 } // namespace handler
151
152} // namespace osmium
153
154#endif // OSMIUM_HANDLER_CHECK_ORDER_HPP
Definition: node.hpp:48
Definition: relation.hpp:168
Definition: way.hpp:72
Definition: check_order.hpp:87
void node(const osmium::Node &node)
Definition: check_order.hpp:95
osmium::object_id_type m_max_relation_id
Definition: check_order.hpp:91
void relation(const osmium::Relation &relation)
Definition: check_order.hpp:126
osmium::object_id_type m_max_node_id
Definition: check_order.hpp:89
osmium::object_id_type max_node_id() const noexcept
Definition: check_order.hpp:136
osmium::object_id_type max_way_id() const noexcept
Definition: check_order.hpp:140
osmium::object_id_type max_relation_id() const noexcept
Definition: check_order.hpp:144
void way(const osmium::Way &way)
Definition: check_order.hpp:112
osmium::object_id_type m_max_way_id
Definition: check_order.hpp:90
Definition: handler.hpp:71
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
Definition: location.hpp:551
Definition: object_comparisons.hpp:87
Definition: check_order.hpp:53
osmium::object_id_type object_id
Definition: check_order.hpp:55
out_of_order_error(const std::string &what, osmium::object_id_type id)
Definition: check_order.hpp:57
out_of_order_error(const char *what, osmium::object_id_type id)
Definition: check_order.hpp:62