Libosmium  2.20.0
Fast and flexible C++ library for working with OpenStreetMap data
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-2023 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>
38#include <osmium/util/misc.hpp>
39
40#include <cassert>
41#include <cstdlib>
42#include <tuple>
43
44namespace osmium {
45
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
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
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
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
161 bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
162 return const_tie(lhs.type(), lhs.id() > 0, lhs.positive_id(), rhs.version(),
163 ((lhs.timestamp().valid() && rhs.timestamp().valid()) ? rhs.timestamp() : osmium::Timestamp())) <
164 const_tie(rhs.type(), rhs.id() > 0, rhs.positive_id(), lhs.version(),
165 ((lhs.timestamp().valid() && rhs.timestamp().valid()) ? lhs.timestamp() : osmium::Timestamp()));
166 }
167
169 bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
170 assert(lhs && rhs);
171 return operator()(*lhs, *rhs);
172 }
173
174 }; // struct object_order_type_id_reverse_version
175
176} // namespace osmium
177
178#endif // OSMIUM_OSM_OBJECT_COMPARISONS_HPP
Definition: object.hpp:64
Definition: timestamp.hpp:175
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
std::tuple< const Ts &... > const_tie(const Ts &... args) noexcept
Definition: misc.hpp:52
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
Definition: object_comparisons.hpp:87
bool operator()(const object_id_type lhs, const object_id_type rhs) const noexcept
Definition: object_comparisons.hpp:89
Definition: object_comparisons.hpp:50
bool operator()(const osmium::OSMObject *lhs, const osmium::OSMObject *rhs) const noexcept
Definition: object_comparisons.hpp:57
bool operator()(const osmium::OSMObject &lhs, const osmium::OSMObject &rhs) const noexcept
Definition: object_comparisons.hpp:52
Definition: object_comparisons.hpp:68
bool operator()(const osmium::OSMObject &lhs, const osmium::OSMObject &rhs) const noexcept
Definition: object_comparisons.hpp:70
bool operator()(const osmium::OSMObject *lhs, const osmium::OSMObject *rhs) const noexcept
Definition: object_comparisons.hpp:76
Definition: object_comparisons.hpp:159
bool operator()(const osmium::OSMObject &lhs, const osmium::OSMObject &rhs) const noexcept
Definition: object_comparisons.hpp:161
bool operator()(const osmium::OSMObject *lhs, const osmium::OSMObject *rhs) const noexcept
Definition: object_comparisons.hpp:169
Definition: object_comparisons.hpp:136
bool operator()(const osmium::OSMObject *lhs, const osmium::OSMObject *rhs) const noexcept
Definition: object_comparisons.hpp:144
bool operator()(const osmium::OSMObject &lhs, const osmium::OSMObject &rhs) const noexcept
Definition: object_comparisons.hpp:138
Definition: object_comparisons.hpp:116
bool operator()(const osmium::OSMObject &lhs, const osmium::OSMObject &rhs) const noexcept
Definition: object_comparisons.hpp:118
bool operator()(const osmium::OSMObject *lhs, const osmium::OSMObject *rhs) const noexcept
Definition: object_comparisons.hpp:123