Libosmium  2.4.1
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
changeset.hpp
Go to the documentation of this file.
1 #ifndef OSMIUM_OSM_CHANGESET_HPP
2 #define OSMIUM_OSM_CHANGESET_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 <cstring>
37 
39 #include <osmium/memory/item.hpp>
40 #include <osmium/osm/box.hpp>
41 #include <osmium/osm/entity.hpp>
42 #include <osmium/osm/item_type.hpp>
43 #include <osmium/osm/tag.hpp>
44 #include <osmium/osm/timestamp.hpp>
45 #include <osmium/osm/types.hpp>
47 
48 namespace osmium {
49 
50  namespace builder {
51  template <class T> class ObjectBuilder;
52  }
53 
61  class Changeset : public osmium::OSMEntity {
62 
64 
72 
75  }
76 
78  m_user_size = size;
79  }
80 
81  unsigned char* subitems_position() {
82  return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
83  }
84 
85  const unsigned char* subitems_position() const {
86  return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
87  }
88 
89  public:
90 
92  changeset_id_type id() const noexcept {
93  return m_id;
94  }
95 
103  m_id = id;
104  return *this;
105  }
106 
113  Changeset& set_id(const char* id) {
115  }
116 
118  user_id_type uid() const noexcept {
119  return m_uid;
120  }
121 
129  m_uid = uid;
130  return *this;
131  }
132 
141  m_uid = uid < 0 ? 0 : static_cast<user_id_type>(uid);
142  return *this;
143  }
144 
151  Changeset& set_uid(const char* uid) {
153  }
154 
156  bool user_is_anonymous() const noexcept {
157  return m_uid == 0;
158  }
159 
161  osmium::Timestamp created_at() const noexcept {
162  return m_created_at;
163  }
164 
171  osmium::Timestamp closed_at() const noexcept {
172  return m_closed_at;
173  }
174 
176  bool open() const noexcept {
177  return m_closed_at == osmium::Timestamp();
178  }
179 
181  bool closed() const noexcept {
182  return !open();
183  }
184 
192  m_created_at = timestamp;
193  return *this;
194  }
195 
203  m_closed_at = timestamp;
204  return *this;
205  }
206 
208  num_changes_type num_changes() const noexcept {
209  return m_num_changes;
210  }
211 
215  return *this;
216  }
217 
219  Changeset& set_num_changes(const char* num_changes) noexcept {
221  }
222 
228  osmium::Box& bounds() noexcept {
229  return m_bounds;
230  }
231 
237  const osmium::Box& bounds() const noexcept {
238  return m_bounds;
239  }
240 
242  const char* user() const {
243  return reinterpret_cast<const char*>(data() + sizeof(Changeset));
244  }
245 
247  const TagList& tags() const {
248  return osmium::detail::subitem_of_type<const TagList>(cbegin(), cend());
249  }
250 
258  void set_attribute(const char* attr, const char* value) {
259  if (!strcmp(attr, "id")) {
260  set_id(value);
261  } else if (!strcmp(attr, "num_changes")) {
262  set_num_changes(value);
263  } else if (!strcmp(attr, "created_at")) {
265  } else if (!strcmp(attr, "closed_at")) {
267  } else if (!strcmp(attr, "uid")) {
268  set_uid(value);
269  }
270  }
271 
274 
275  iterator begin() {
276  return iterator(subitems_position());
277  }
278 
279  iterator end() {
280  return iterator(data() + padded_size());
281  }
282 
283  const_iterator cbegin() const {
285  }
286 
287  const_iterator cend() const {
288  return const_iterator(data() + padded_size());
289  }
290 
291  const_iterator begin() const {
292  return cbegin();
293  }
294 
295  const_iterator end() const {
296  return cend();
297  }
298 
299  }; // class Changeset
300 
301 
305  inline bool operator==(const Changeset& lhs, const Changeset& rhs) {
306  return lhs.id() == rhs.id();
307  }
308 
309  inline bool operator!=(const Changeset& lhs, const Changeset& rhs) {
310  return ! (lhs == rhs);
311  }
312 
316  inline bool operator<(const Changeset& lhs, const Changeset& rhs) {
317  return lhs.id() < rhs.id();
318  }
319 
320  inline bool operator>(const Changeset& lhs, const Changeset& rhs) {
321  return rhs < lhs;
322  }
323 
324  inline bool operator<=(const Changeset& lhs, const Changeset& rhs) {
325  return ! (rhs < lhs);
326  }
327 
328  inline bool operator>=(const Changeset& lhs, const Changeset& rhs) {
329  return ! (lhs < rhs);
330  }
331 
332 } // namespace osmium
333 
334 #endif // OSMIUM_OSM_CHANGESET_HPP
osmium::Timestamp m_closed_at
Definition: changeset.hpp:66
Changeset & set_closed_at(const osmium::Timestamp timestamp)
Definition: changeset.hpp:202
Definition: collection.hpp:47
num_changes_type m_num_changes
Definition: changeset.hpp:69
Definition: tag.hpp:105
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:324
osmium::Box & bounds() noexcept
Definition: changeset.hpp:228
bool open() const noexcept
Is this changeset open?
Definition: changeset.hpp:176
string_size_type m_user_size
Definition: changeset.hpp:71
void set_attribute(const char *attr, const char *value)
Definition: changeset.hpp:258
user_id_type uid() const noexcept
Get user id.
Definition: changeset.hpp:118
item_type
Definition: item_type.hpp:43
Changeset & set_uid_from_signed(signed_user_id_type uid) noexcept
Definition: changeset.hpp:140
const TagList & tags() const
Get the list of tags.
Definition: changeset.hpp:247
const char * user() const
Get user name.
Definition: changeset.hpp:242
changeset_id_type id() const noexcept
Get ID of this changeset.
Definition: changeset.hpp:92
item_size_type padded_size() const
Definition: item.hpp:151
OSMEntity is the abstract base class for the OSMObject and Changeset classes.
Definition: entity.hpp:64
const_iterator begin() const
Definition: changeset.hpp:291
T padded_length(T length) noexcept
Definition: item.hpp:56
OSMIUM_CONSTEXPR bool operator==(const Box &lhs, const Box &rhs) noexcept
Definition: box.hpp:219
iterator begin()
Definition: changeset.hpp:275
Changeset & set_id(changeset_id_type id) noexcept
Definition: changeset.hpp:102
osmium::Timestamp closed_at() const noexcept
Definition: changeset.hpp:171
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:316
user_id_type m_uid
Definition: changeset.hpp:70
Namespace for everything in the Osmium library.
Definition: assembler.hpp:55
Changeset & set_uid(const char *uid)
Definition: changeset.hpp:151
Changeset & set_num_changes(num_changes_type num_changes) noexcept
Set the number of changes in this changeset.
Definition: changeset.hpp:213
void set_user_size(string_size_type size)
Definition: changeset.hpp:77
num_changes_type num_changes() const noexcept
Get the number of changes in this changeset.
Definition: changeset.hpp:208
const_iterator cend() const
Definition: changeset.hpp:287
Definition: timestamp.hpp:52
uint16_t string_size_type
Definition: types.hpp:58
const_iterator end() const
Definition: changeset.hpp:295
changeset_id_type m_id
Definition: changeset.hpp:68
osmium::Timestamp m_created_at
Definition: changeset.hpp:65
changeset_id_type string_to_changeset_id(const char *input)
Definition: types_from_string.hpp:96
bool user_is_anonymous() const noexcept
Is this user anonymous?
Definition: changeset.hpp:156
osmium::memory::CollectionIterator< Item > iterator
Definition: changeset.hpp:272
osmium::Box m_bounds
Definition: changeset.hpp:67
osmium::Timestamp created_at() const noexcept
Get timestamp when this changeset was created.
Definition: changeset.hpp:161
int32_t signed_user_id_type
Type for signed OSM user IDs.
Definition: types.hpp:50
Changeset()
Definition: changeset.hpp:73
Definition: box.hpp:50
Changeset & set_num_changes(const char *num_changes) noexcept
Set the number of changes in this changeset.
Definition: changeset.hpp:219
iterator end()
Definition: changeset.hpp:279
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:328
signed_user_id_type string_to_user_id(const char *input)
Definition: types_from_string.hpp:101
osmium::memory::CollectionIterator< const Item > const_iterator
Definition: changeset.hpp:273
Definition: builder.hpp:186
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:320
Changeset & set_created_at(const osmium::Timestamp timestamp)
Definition: changeset.hpp:191
unsigned char * subitems_position()
Definition: changeset.hpp:81
const unsigned char * subitems_position() const
Definition: changeset.hpp:85
An OSM Changeset, a group of changes made by a single user over a short period of time...
Definition: changeset.hpp:61
const osmium::Box & bounds() const noexcept
Definition: changeset.hpp:237
uint32_t num_changes_type
Type for changeset num_changes.
Definition: types.hpp:51
bool closed() const noexcept
Is this changeset closed?
Definition: changeset.hpp:181
uint32_t changeset_id_type
Type for OSM changeset IDs.
Definition: types.hpp:48
const_iterator cbegin() const
Definition: changeset.hpp:283
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:309
Changeset & set_id(const char *id)
Definition: changeset.hpp:113
num_changes_type string_to_num_changes(const char *input)
Definition: types_from_string.hpp:109
Changeset & set_uid(user_id_type uid) noexcept
Definition: changeset.hpp:128
uint32_t user_id_type
Type for OSM user IDs.
Definition: types.hpp:49