Libosmium  2.1.0
Fast and flexible C++ library for working with OpenStreetMap data
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-2015 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 <cstdlib>
37 #include <iosfwd>
38 
39 #include <osmium/memory/item.hpp>
40 #include <osmium/osm/item_type.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 
58  m_ref(ref),
59  m_location(location) {
60  }
61 
62  osmium::object_id_type ref() const noexcept {
63  return m_ref;
64  }
65 
67  return static_cast<osmium::unsigned_object_id_type>(std::abs(m_ref));
68  }
69 
73  osmium::Location& location() noexcept {
74  return m_location;
75  }
76 
77  osmium::Location location() const noexcept {
78  return m_location;
79  }
80 
81  double lon() const {
82  return m_location.lon();
83  }
84 
85  double lat() const {
86  return m_location.lat();
87  }
88 
89  int32_t x() const noexcept {
90  return m_location.x();
91  }
92 
93  int32_t y() const noexcept {
94  return m_location.y();
95  }
96 
98  m_ref = ref;
99  return *this;
100  }
101 
103  m_location = location;
104  return *this;
105  }
106 
107  }; // class NodeRef
108 
109  inline bool operator==(const NodeRef& lhs, const NodeRef& rhs) noexcept {
110  return lhs.ref() == rhs.ref();
111  }
112 
113  inline bool operator!=(const NodeRef& lhs, const NodeRef& rhs) noexcept {
114  return ! (lhs == rhs);
115  }
116 
117  inline bool operator<(const NodeRef& lhs, const NodeRef& rhs) noexcept {
118  return lhs.ref() < rhs.ref();
119  }
120 
121  inline bool operator>(const NodeRef& lhs, const NodeRef& rhs) noexcept {
122  return rhs < lhs;
123  }
124 
125  inline bool operator<=(const NodeRef& lhs, const NodeRef& rhs) noexcept {
126  return ! (rhs < lhs);
127  }
128 
129  inline bool operator>=(const NodeRef& lhs, const NodeRef& rhs) noexcept {
130  return ! (lhs < rhs);
131  }
132 
136  template <typename TChar, typename TTraits>
137  inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const osmium::NodeRef& nr) {
138  return out << "<" << nr.ref() << " " << nr.location() << ">";
139  }
140 
144  struct location_equal {
145 
146  bool operator()(const NodeRef& lhs, const NodeRef& rhs) const noexcept {
147  return lhs.location() == rhs.location();
148  }
149 
152  typedef bool result_type;
153 
154  }; // struct location_equal
155 
159  struct location_less {
160 
161  bool operator()(const NodeRef& lhs, const NodeRef& rhs) const noexcept {
162  return lhs.location() < rhs.location();
163  }
164 
167  typedef bool result_type;
168 
169  }; // struct location_less
170 
171 } // namespace osmium
172 
173 #endif // OSMIUM_OSM_NODE_REF_HPP
int32_t y() const noexcept
Definition: node_ref.hpp:93
NodeRef second_argument_type
Definition: node_ref.hpp:166
double lat() const
Definition: node_ref.hpp:85
NodeRef & set_ref(const osmium::object_id_type ref) noexcept
Definition: node_ref.hpp:97
Definition: node_ref.hpp:144
uint64_t unsigned_object_id_type
Type for OSM object (node, way, or relation) IDs where we only allow positive IDs.
Definition: types.hpp:47
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:324
NodeRef second_argument_type
Definition: node_ref.hpp:151
Definition: node_ref.hpp:159
osmium::Location location() const noexcept
Definition: node_ref.hpp:77
osmium::object_id_type ref() const noexcept
Definition: node_ref.hpp:62
OSMIUM_CONSTEXPR bool operator==(const Box &lhs, const Box &rhs) noexcept
Definition: box.hpp:219
double lat() const
Definition: location.hpp:205
bool operator()(const NodeRef &lhs, const NodeRef &rhs) const noexcept
Definition: node_ref.hpp:146
bool operator()(const NodeRef &lhs, const NodeRef &rhs) const noexcept
Definition: node_ref.hpp:161
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:316
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:46
Namespace for everything in the Osmium library.
Definition: assembler.hpp:55
NodeRef first_argument_type
Definition: node_ref.hpp:150
bool result_type
Definition: node_ref.hpp:167
NodeRef & set_location(const osmium::Location &location) noexcept
Definition: node_ref.hpp:102
constexpr int32_t y() const noexcept
Definition: location.hpp:167
osmium::object_id_type m_ref
Definition: node_ref.hpp:52
osmium::Location m_location
Definition: node_ref.hpp:53
Definition: location.hpp:79
osmium::Location & location() noexcept
Definition: node_ref.hpp:73
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:328
NodeRef(const osmium::object_id_type ref=0, const osmium::Location &location=Location()) noexcept
Definition: node_ref.hpp:57
osmium::unsigned_object_id_type positive_ref() const noexcept
Definition: node_ref.hpp:66
double lon() const
Definition: location.hpp:186
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:320
NodeRef first_argument_type
Definition: node_ref.hpp:165
constexpr int32_t x() const noexcept
Definition: location.hpp:163
double lon() const
Definition: node_ref.hpp:81
Definition: node_ref.hpp:50
bool result_type
Definition: node_ref.hpp:152
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:309
int32_t x() const noexcept
Definition: node_ref.hpp:89