Libosmium  2.9.0
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 (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 <cstdint>
37 #include <cstdlib>
38 #include <iosfwd>
39 
40 #include <osmium/memory/item.hpp>
41 #include <osmium/osm/location.hpp>
42 #include <osmium/osm/types.hpp>
43 
44 namespace osmium {
45 
50  class NodeRef : public osmium::memory::detail::ItemHelper {
51 
54 
55  public:
56 
57  constexpr NodeRef(const osmium::object_id_type ref = 0, const osmium::Location& location = Location()) noexcept :
58  m_ref(ref),
59  m_location(location) {
60  }
61 
65  constexpr osmium::object_id_type ref() const noexcept {
66  return m_ref;
67  }
68 
73  return static_cast<osmium::unsigned_object_id_type>(std::abs(m_ref));
74  }
75 
79  osmium::Location& location() noexcept {
80  return m_location;
81  }
82 
86  constexpr osmium::Location location() const noexcept {
87  return m_location;
88  }
89 
95  double lon() const {
96  return m_location.lon();
97  }
98 
104  double lat() const {
105  return m_location.lat();
106  }
107 
111  constexpr int32_t x() const noexcept {
112  return m_location.x();
113  }
114 
118  constexpr int32_t y() const noexcept {
119  return m_location.y();
120  }
121 
128  m_ref = ref;
129  return *this;
130  }
131 
138  m_location = location;
139  return *this;
140  }
141 
142  }; // class NodeRef
143 
147  inline constexpr bool operator==(const NodeRef& lhs, const NodeRef& rhs) noexcept {
148  return lhs.ref() == rhs.ref();
149  }
150 
155  inline constexpr bool operator!=(const NodeRef& lhs, const NodeRef& rhs) noexcept {
156  return ! (lhs == rhs);
157  }
158 
163  inline constexpr bool operator<(const NodeRef& lhs, const NodeRef& rhs) noexcept {
164  return lhs.ref() < rhs.ref();
165  }
166 
171  inline constexpr bool operator>(const NodeRef& lhs, const NodeRef& rhs) noexcept {
172  return rhs < lhs;
173  }
174 
179  inline constexpr bool operator<=(const NodeRef& lhs, const NodeRef& rhs) noexcept {
180  return ! (rhs < lhs);
181  }
182 
187  inline constexpr bool operator>=(const NodeRef& lhs, const NodeRef& rhs) noexcept {
188  return ! (lhs < rhs);
189  }
190 
194  template <typename TChar, typename TTraits>
195  inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const osmium::NodeRef& nr) {
196  return out << "<" << nr.ref() << " " << nr.location() << ">";
197  }
198 
202  struct location_equal {
203 
204  constexpr bool operator()(const NodeRef& lhs, const NodeRef& rhs) const noexcept {
205  return lhs.location() == rhs.location();
206  }
207 
210  using result_type = bool;
211 
212  }; // struct location_equal
213 
217  struct location_less {
218 
219  constexpr bool operator()(const NodeRef& lhs, const NodeRef& rhs) const noexcept {
220  return lhs.location() < rhs.location();
221  }
222 
225  using result_type = bool;
226 
227  }; // struct location_less
228 
229 } // namespace osmium
230 
231 #endif // OSMIUM_OSM_NODE_REF_HPP
double lat() const
Definition: node_ref.hpp:104
NodeRef & set_ref(const osmium::object_id_type ref) noexcept
Definition: node_ref.hpp:127
Definition: node_ref.hpp:202
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:453
bool result_type
Definition: node_ref.hpp:225
constexpr bool operator==(const Box &lhs, const Box &rhs) noexcept
Definition: box.hpp:221
constexpr NodeRef(const osmium::object_id_type ref=0, const osmium::Location &location=Location()) noexcept
Definition: node_ref.hpp:57
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
Definition: node_ref.hpp:217
double lat() const
Definition: location.hpp:380
constexpr osmium::object_id_type ref() const noexcept
Definition: node_ref.hpp:65
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:445
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
NodeRef & set_location(const osmium::Location &location) noexcept
Definition: node_ref.hpp:137
constexpr int32_t x() const noexcept
Definition: node_ref.hpp:111
constexpr int32_t y() const noexcept
Definition: location.hpp:342
constexpr osmium::Location location() const noexcept
Definition: node_ref.hpp:86
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
osmium::object_id_type m_ref
Definition: node_ref.hpp:52
constexpr bool operator()(const NodeRef &lhs, const NodeRef &rhs) const noexcept
Definition: node_ref.hpp:204
osmium::Location m_location
Definition: node_ref.hpp:53
Definition: location.hpp:256
bool result_type
Definition: node_ref.hpp:210
osmium::Location & location() noexcept
Definition: node_ref.hpp:79
constexpr int32_t y() const noexcept
Definition: node_ref.hpp:118
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:457
osmium::unsigned_object_id_type positive_ref() const noexcept
Definition: node_ref.hpp:72
double lon() const
Definition: location.hpp:361
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:449
constexpr bool operator()(const NodeRef &lhs, const NodeRef &rhs) const noexcept
Definition: node_ref.hpp:219
constexpr int32_t x() const noexcept
Definition: location.hpp:338
double lon() const
Definition: node_ref.hpp:95
Definition: node_ref.hpp:50
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:438