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

Loading...
Searching...
No Matches
node_ref.hpp
Go to the documentation of this file.
1#ifndef OSMIUM_OSM_NODE_REF_HPP
2#define OSMIUM_OSM_NODE_REF_HPP
3
4/*
5
6 This file is part of Osmium (https://osmcode.org/libosmium).
7
8 Copyright 2013-2025 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 <osmium/memory/item.hpp>
37#include <osmium/osm/location.hpp>
38#include <osmium/osm/types.hpp>
39
40#include <cstdint>
41#include <cstdlib>
42#include <iosfwd>
43
44 namespace osmium {
45
50 class NodeRef : public osmium::memory::detail::ItemHelper {
51
52 osmium::object_id_type m_ref;
53 osmium::Location m_location;
54
55 public:
56
63 constexpr NodeRef(const osmium::object_id_type ref = 0, const osmium::Location& location = Location{}) noexcept : // NOLINT(google-explicit-constructor, hicpp-explicit-conversions)
64 m_ref(ref),
65 m_location(location) {
66 }
67
71 constexpr osmium::object_id_type ref() const noexcept {
72 return m_ref;
73 }
74
78 osmium::unsigned_object_id_type positive_ref() const noexcept {
79 return static_cast<osmium::unsigned_object_id_type>(std::abs(m_ref));
80 }
81
85 osmium::Location& location() noexcept {
86 return m_location;
87 }
88
92 constexpr osmium::Location location() const noexcept {
93 return m_location;
94 }
95
101 double lon() const {
102 return m_location.lon();
103 }
104
110 double lat() const {
111 return m_location.lat();
112 }
113
117 constexpr int32_t x() const noexcept {
118 return m_location.x();
119 }
120
124 constexpr int32_t y() const noexcept {
125 return m_location.y();
126 }
127
133 NodeRef& set_ref(const osmium::object_id_type ref) noexcept {
134 m_ref = ref;
135 return *this;
136 }
137
143 NodeRef& set_location(const osmium::Location& location) noexcept {
144 m_location = location;
145 return *this;
146 }
147
148 }; // class NodeRef
149
153 constexpr bool operator==(const NodeRef& lhs, const NodeRef& rhs) noexcept {
154 return lhs.ref() == rhs.ref();
155 }
156
161 constexpr bool operator!=(const NodeRef& lhs, const NodeRef& rhs) noexcept {
162 return !(lhs == rhs);
163 }
164
169 constexpr bool operator<(const NodeRef& lhs, const NodeRef& rhs) noexcept {
170 return lhs.ref() < rhs.ref();
171 }
172
177 constexpr bool operator>(const NodeRef& lhs, const NodeRef& rhs) noexcept {
178 return rhs < lhs;
179 }
180
185 constexpr bool operator<=(const NodeRef& lhs, const NodeRef& rhs) noexcept {
186 return !(rhs < lhs);
187 }
188
193 constexpr bool operator>=(const NodeRef& lhs, const NodeRef& rhs) noexcept {
194 return !(lhs < rhs);
195 }
196
200 template <typename TChar, typename TTraits>
201 inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const osmium::NodeRef& nr) {
202 return out << "<" << nr.ref() << " " << nr.location() << ">";
203 }
204
208 struct location_equal {
209
210 constexpr bool operator()(const NodeRef& lhs, const NodeRef& rhs) const noexcept {
211 return lhs.location() == rhs.location();
212 }
213
214 using first_argument_type = NodeRef;
215 using second_argument_type = NodeRef;
216 using result_type = bool;
217
218 }; // struct location_equal
219
223 struct location_less {
224
225 constexpr bool operator()(const NodeRef& lhs, const NodeRef& rhs) const noexcept {
226 return lhs.location() < rhs.location();
227 }
228
229 using first_argument_type = NodeRef;
230 using second_argument_type = NodeRef;
231 using result_type = bool;
232
233 }; // struct location_less
234
235} // namespace osmium
236
237#endif // OSMIUM_OSM_NODE_REF_HPP
osmium::Location
Definition location.hpp:271
osmium::Location::lon
double lon() const
Definition location.hpp:400
osmium::Location::x
constexpr int32_t x() const noexcept
Definition location.hpp:377
osmium::Location::lat
double lat() const
Definition location.hpp:419
osmium::Location::y
constexpr int32_t y() const noexcept
Definition location.hpp:381
osmium::NodeRef
Definition node_ref.hpp:50
osmium::NodeRef::set_ref
NodeRef & set_ref(const osmium::object_id_type ref) noexcept
Definition node_ref.hpp:133
osmium::NodeRef::positive_ref
osmium::unsigned_object_id_type positive_ref() const noexcept
Definition node_ref.hpp:78
osmium::NodeRef::x
constexpr int32_t x() const noexcept
Definition node_ref.hpp:117
osmium::NodeRef::NodeRef
constexpr NodeRef(const osmium::object_id_type ref=0, const osmium::Location &location=Location{}) noexcept
Definition node_ref.hpp:63
osmium::NodeRef::lon
double lon() const
Definition node_ref.hpp:101
osmium::NodeRef::set_location
NodeRef & set_location(const osmium::Location &location) noexcept
Definition node_ref.hpp:143
osmium::NodeRef::y
constexpr int32_t y() const noexcept
Definition node_ref.hpp:124
osmium::NodeRef::location
constexpr osmium::Location location() const noexcept
Definition node_ref.hpp:92
osmium::NodeRef::ref
constexpr osmium::object_id_type ref() const noexcept
Definition node_ref.hpp:71
osmium::NodeRef::lat
double lat() const
Definition node_ref.hpp:110
osmium::NodeRef::location
osmium::Location & location() noexcept
Definition node_ref.hpp:85
osmium::NodeRef::m_ref
osmium::object_id_type m_ref
Definition node_ref.hpp:52
osmium::NodeRef::m_location
osmium::Location m_location
Definition node_ref.hpp:53
item.hpp
location.hpp
osmium
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
osmium::operator==
bool operator==(const Changeset &lhs, const Changeset &rhs)
Definition changeset.hpp:440
osmium::operator<=
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition changeset.hpp:459
osmium::operator>
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition changeset.hpp:455
osmium::unsigned_object_id_type
uint64_t unsigned_object_id_type
Type for OSM object (node, way, or relation) IDs where we only allow positive IDs.
Definition types.hpp:46
osmium::operator>=
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition changeset.hpp:463
osmium::operator!=
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition changeset.hpp:444
osmium::object_id_type
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition types.hpp:45
osmium::operator<<
std::basic_ostream< TChar, TTraits > & operator<<(std::basic_ostream< TChar, TTraits > &out, const item_type item_type)
Definition item_type.hpp:187
osmium::operator<
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition changeset.hpp:451
osmium::location_equal
Definition node_ref.hpp:208
osmium::location_equal::result_type
bool result_type
Definition node_ref.hpp:216
osmium::location_equal::operator()
constexpr bool operator()(const NodeRef &lhs, const NodeRef &rhs) const noexcept
Definition node_ref.hpp:210
osmium::location_less
Definition node_ref.hpp:223
osmium::location_less::result_type
bool result_type
Definition node_ref.hpp:231
osmium::location_less::operator()
constexpr bool operator()(const NodeRef &lhs, const NodeRef &rhs) const noexcept
Definition node_ref.hpp:225
types.hpp