Libosmium: include/osmium/osm/object_comparisons.hpp Source File

Libosmium Fast and flexible C++ library for working with OpenStreetMap data

Loading...
Searching...
No Matches
object_comparisons.hpp
Go to the documentation of this file.
1#ifndef OSMIUM_OSM_OBJECT_COMPARISONS_HPP
2#define OSMIUM_OSM_OBJECT_COMPARISONS_HPP
3
4/*
5
6This file is part of Osmium (https://osmcode.org/libosmium).
7
8Copyright 2013-2026 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/osm/object.hpp>
37#include <osmium/osm/timestamp.hpp>
38#include <osmium/util/misc.hpp>
39
40#include <cassert>
41#include <cstdlib>
42#include <tuple>
43
44namespace osmium {
45
50 struct object_equal_type_id_version {
51
52 bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
53 return lhs == rhs;
54 }
55
57 bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
58 assert(lhs && rhs);
59 return *lhs == *rhs;
60 }
61
62 }; // struct object_equal_type_id_version
63
68 struct object_equal_type_id {
69
70 bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
71 return lhs.type() == rhs.type() &&
72 lhs.id() == rhs.id();
73 }
74
76 bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
77 assert(lhs && rhs);
78 return operator()(*lhs, *rhs);
79 }
80
81 }; // struct object_equal_type_id
82
87 struct id_order {
88
89 bool operator()(const object_id_type lhs, const object_id_type rhs) const noexcept {
90 if (rhs == 0) {
91 return false;
92 }
93 if (lhs == 0) {
94 return true;
95 }
96 if (lhs < 0) {
97 if (rhs > 0) {
98 return true;
99 }
100 // rhs < 0
101 return lhs > rhs;
102 }
103 // lhs > 0
104 if (rhs < 0) {
105 return false;
106 }
107 return lhs < rhs;
108 }
109
110 }; // struct id_order
111
116 struct object_order_type_id_version {
117
118 bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
119 return lhs < rhs;
120 }
121
123 bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
124 assert(lhs && rhs);
125 return *lhs < *rhs;
126 }
127
128 }; // struct object_order_type_id_version
129
136 struct object_order_type_id_version_without_timestamp {
137
138 bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
139 return const_tie(lhs.type(), lhs.id() > 0, lhs.positive_id(), lhs.version()) <
140 const_tie(rhs.type(), rhs.id() > 0, rhs.positive_id(), rhs.version());
141 }
142
144 bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
145 assert(lhs && rhs);
146 return operator()(*lhs, *rhs);
147 }
148
149 }; // struct object_order_type_id_version_without_timestamp
150
160 struct object_order_type_id_reverse_version {
161
162 bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
163 const bool tsvalid = lhs.timestamp().valid() && rhs.timestamp().valid();
164 return const_tie(lhs.type(), lhs.id() > 0, lhs.positive_id(), rhs.version(),
165 (tsvalid ? rhs.timestamp() : osmium::Timestamp())) <
166 const_tie(rhs.type(), rhs.id() > 0, rhs.positive_id(), lhs.version(),
167 (tsvalid ? lhs.timestamp() : osmium::Timestamp()));
168 }
169
171 bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
172 assert(lhs && rhs);
173 return operator()(*lhs, *rhs);
174 }
175
176 }; // struct object_order_type_id_reverse_version
177
178} // namespace osmium
179
180#endif // OSMIUM_OSM_OBJECT_COMPARISONS_HPP
osmium::OSMObject
Definition object.hpp:64
osmium::Timestamp
Definition timestamp.hpp:175
misc.hpp
osmium
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
osmium::const_tie
std::tuple< const Ts &... > const_tie(const Ts &... args) noexcept
Definition misc.hpp:52
osmium::object_id_type
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition types.hpp:45
object.hpp
osmium::id_order
Definition object_comparisons.hpp:87
osmium::id_order::operator()
bool operator()(const object_id_type lhs, const object_id_type rhs) const noexcept
Definition object_comparisons.hpp:89
osmium::object_equal_type_id_version
Definition object_comparisons.hpp:50
osmium::object_equal_type_id_version::operator()
bool operator()(const osmium::OSMObject *lhs, const osmium::OSMObject *rhs) const noexcept
Definition object_comparisons.hpp:57
osmium::object_equal_type_id_version::operator()
bool operator()(const osmium::OSMObject &lhs, const osmium::OSMObject &rhs) const noexcept
Definition object_comparisons.hpp:52
osmium::object_equal_type_id
Definition object_comparisons.hpp:68
osmium::object_equal_type_id::operator()
bool operator()(const osmium::OSMObject &lhs, const osmium::OSMObject &rhs) const noexcept
Definition object_comparisons.hpp:70
osmium::object_equal_type_id::operator()
bool operator()(const osmium::OSMObject *lhs, const osmium::OSMObject *rhs) const noexcept
Definition object_comparisons.hpp:76
osmium::object_order_type_id_reverse_version
Definition object_comparisons.hpp:160
osmium::object_order_type_id_reverse_version::operator()
bool operator()(const osmium::OSMObject &lhs, const osmium::OSMObject &rhs) const noexcept
Definition object_comparisons.hpp:162
osmium::object_order_type_id_reverse_version::operator()
bool operator()(const osmium::OSMObject *lhs, const osmium::OSMObject *rhs) const noexcept
Definition object_comparisons.hpp:171
osmium::object_order_type_id_version_without_timestamp
Definition object_comparisons.hpp:136
osmium::object_order_type_id_version_without_timestamp::operator()
bool operator()(const osmium::OSMObject *lhs, const osmium::OSMObject *rhs) const noexcept
Definition object_comparisons.hpp:144
osmium::object_order_type_id_version_without_timestamp::operator()
bool operator()(const osmium::OSMObject &lhs, const osmium::OSMObject &rhs) const noexcept
Definition object_comparisons.hpp:138
osmium::object_order_type_id_version
Definition object_comparisons.hpp:116
osmium::object_order_type_id_version::operator()
bool operator()(const osmium::OSMObject &lhs, const osmium::OSMObject &rhs) const noexcept
Definition object_comparisons.hpp:118
osmium::object_order_type_id_version::operator()
bool operator()(const osmium::OSMObject *lhs, const osmium::OSMObject *rhs) const noexcept
Definition object_comparisons.hpp:123
timestamp.hpp