Libosmium  2.6.0
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
6 This file is part of Osmium (http://osmcode.org/libosmium).
7 
8 Copyright 2013-2016 Jochen Topf <jochen@topf.org> and others (see README).
9 
10 Boost Software License - Version 1.0 - August 17th, 2003
11 
12 Permission is hereby granted, free of charge, to any person or organization
13 obtaining a copy of the software and accompanying documentation covered by
14 this license (the "Software") to use, reproduce, display, distribute,
15 execute, and transmit the Software, and to prepare derivative works of the
16 Software, and to permit third-parties to whom the Software is furnished to
17 do so, all subject to the following:
18 
19 The copyright notices in the Software and this entire statement, including
20 the above license grant, this restriction and the following disclaimer,
21 must be included in all copies of the Software, in whole or in part, and
22 all derivative works of the Software, unless such copies or derivative
23 works are solely in the form of machine-executable object code generated by
24 a source language processor.
25 
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 DEALINGS IN THE SOFTWARE.
33 
34 */
35 
36 #include <limits>
37 #include <stdexcept>
38 #include <string>
39 
40 #include <osmium/handler.hpp>
41 #include <osmium/osm/node.hpp>
42 #include <osmium/osm/relation.hpp>
43 #include <osmium/osm/types.hpp>
44 #include <osmium/osm/way.hpp>
45 
46 namespace osmium {
47 
52  struct out_of_order_error : public std::runtime_error {
53 
54  out_of_order_error(const std::string& what) :
55  std::runtime_error(what) {
56  }
57 
58  out_of_order_error(const char* what) :
59  std::runtime_error(what) {
60  }
61 
62  }; // struct out_of_order_error
63 
64  namespace handler {
65 
79 
80  osmium::object_id_type m_max_node_id = std::numeric_limits<osmium::object_id_type>::min();
81  osmium::object_id_type m_max_way_id = std::numeric_limits<osmium::object_id_type>::min();
82  osmium::object_id_type m_max_relation_id = std::numeric_limits<osmium::object_id_type>::min();
83 
84  public:
85 
86  void node(const osmium::Node& node) {
87  if (m_max_way_id > 0) {
88  throw out_of_order_error("Found a node after a way.");
89  }
90  if (m_max_relation_id > 0) {
91  throw out_of_order_error("Found a node after a relation.");
92  }
93 
94  if (m_max_node_id >= node.id()) {
95  throw out_of_order_error("Node IDs out of order.");
96  }
97  m_max_node_id = node.id();
98  }
99 
100  void way(const osmium::Way& way) {
101  if (m_max_relation_id > 0) {
102  throw out_of_order_error("Found a way after a relation.");
103  }
104 
105  if (m_max_way_id >= way.id()) {
106  throw out_of_order_error("Way IDs out of order.");
107  }
108  m_max_way_id = way.id();
109  }
110 
112  if (m_max_relation_id >= relation.id()) {
113  throw out_of_order_error("Relation IDs out of order.");
114  }
115  m_max_relation_id = relation.id();
116  }
117 
119  return m_max_node_id;
120  }
121 
123  return m_max_way_id;
124  }
125 
127  return m_max_relation_id;
128  }
129 
130  }; // class CheckOrder
131 
132  } // namespace handler
133 
134 } // namespace osmium
135 
136 #endif // OSMIUM_HANDLER_CHECK_ORDER_HPP
osmium::object_id_type m_max_way_id
Definition: check_order.hpp:81
Definition: check_order.hpp:78
osmium::object_id_type m_max_node_id
Definition: check_order.hpp:80
Definition: relation.hpp:165
void node(const osmium::Node &node)
Definition: check_order.hpp:86
Definition: reader_iterator.hpp:39
Definition: handler.hpp:45
osmium::object_id_type m_max_relation_id
Definition: check_order.hpp:82
Definition: way.hpp:65
out_of_order_error(const char *what)
Definition: check_order.hpp:58
out_of_order_error(const std::string &what)
Definition: check_order.hpp:54
void way(const osmium::Way &way)
Definition: check_order.hpp:100
osmium::object_id_type max_node_id() const noexcept
Definition: check_order.hpp:118
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
Namespace for everything in the Osmium library.
Definition: assembler.hpp:59
osmium::object_id_type max_relation_id() const noexcept
Definition: check_order.hpp:126
Definition: check_order.hpp:52
object_id_type id() const noexcept
Get ID of this object.
Definition: object.hpp:110
void relation(const osmium::Relation &relation)
Definition: check_order.hpp:111
Definition: node.hpp:47
osmium::object_id_type max_way_id() const noexcept
Definition: check_order.hpp:122