Libosmium  2.17.0
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-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/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 return const_tie(lhs > 0, std::abs(lhs)) <
91 const_tie(rhs > 0, std::abs(rhs));
92 }
93
94 }; // struct id_order
95
101
102 bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
103 return lhs < rhs;
104 }
105
107 bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
108 assert(lhs && rhs);
109 return *lhs < *rhs;
110 }
111
112 }; // struct object_order_type_id_version
113
121
122 bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
123 return const_tie(lhs.type(), lhs.id() > 0, lhs.positive_id(), lhs.version()) <
124 const_tie(rhs.type(), rhs.id() > 0, rhs.positive_id(), rhs.version());
125 }
126
128 bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
129 assert(lhs && rhs);
130 return operator()(*lhs, *rhs);
131 }
132
133 }; // struct object_order_type_id_version_without_timestamp
134
144
145 bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
146 return const_tie(lhs.type(), lhs.id() > 0, lhs.positive_id(), rhs.version(),
147 ((lhs.timestamp().valid() && rhs.timestamp().valid()) ? rhs.timestamp() : osmium::Timestamp())) <
148 const_tie(rhs.type(), rhs.id() > 0, rhs.positive_id(), lhs.version(),
149 ((lhs.timestamp().valid() && rhs.timestamp().valid()) ? lhs.timestamp() : osmium::Timestamp()));
150 }
151
153 bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
154 assert(lhs && rhs);
155 return operator()(*lhs, *rhs);
156 }
157
158 }; // struct object_order_type_id_reverse_version
159
160} // namespace osmium
161
162#endif // OSMIUM_OSM_OBJECT_COMPARISONS_HPP
Definition: object.hpp:64
Definition: timestamp.hpp:147
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:143
bool operator()(const osmium::OSMObject &lhs, const osmium::OSMObject &rhs) const noexcept
Definition: object_comparisons.hpp:145
bool operator()(const osmium::OSMObject *lhs, const osmium::OSMObject *rhs) const noexcept
Definition: object_comparisons.hpp:153
Definition: object_comparisons.hpp:120
bool operator()(const osmium::OSMObject *lhs, const osmium::OSMObject *rhs) const noexcept
Definition: object_comparisons.hpp:128
bool operator()(const osmium::OSMObject &lhs, const osmium::OSMObject &rhs) const noexcept
Definition: object_comparisons.hpp:122
Definition: object_comparisons.hpp:100
bool operator()(const osmium::OSMObject &lhs, const osmium::OSMObject &rhs) const noexcept
Definition: object_comparisons.hpp:102
bool operator()(const osmium::OSMObject *lhs, const osmium::OSMObject *rhs) const noexcept
Definition: object_comparisons.hpp:107