First Commit
This commit is contained in:
commit
8a6c7106e3
1312 files changed
+425396
No files matched your search
+249
@@ -0,0 +1,249 @@
|
||||
#ifndef OSMIUM_OSM_AREA_HPP
|
||||
#define OSMIUM_OSM_AREA_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/memory/collection.hpp>
|
||||
#include <osmium/memory/item.hpp>
|
||||
#include <osmium/memory/item_iterator.hpp>
|
||||
#include <osmium/osm/box.hpp>
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
#include <osmium/osm/node_ref_list.hpp>
|
||||
#include <osmium/osm/object.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
namespace builder {
|
||||
template <typename TDerived, typename T>
|
||||
class OSMObjectBuilder;
|
||||
} // namespace builder
|
||||
|
||||
/**
|
||||
* An outer ring of an Area.
|
||||
*/
|
||||
class OuterRing : public NodeRefList {
|
||||
|
||||
public:
|
||||
|
||||
static constexpr osmium::item_type itemtype = osmium::item_type::outer_ring;
|
||||
|
||||
constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
|
||||
return t == itemtype;
|
||||
}
|
||||
|
||||
OuterRing() :
|
||||
NodeRefList(itemtype) {
|
||||
}
|
||||
|
||||
}; // class OuterRing
|
||||
|
||||
static_assert(sizeof(OuterRing) % osmium::memory::align_bytes == 0, "Class osmium::OuterRing has wrong size to be aligned properly!");
|
||||
|
||||
/**
|
||||
* An inner ring of an Area.
|
||||
*/
|
||||
class InnerRing : public NodeRefList {
|
||||
|
||||
public:
|
||||
|
||||
static constexpr osmium::item_type itemtype = osmium::item_type::inner_ring;
|
||||
|
||||
constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
|
||||
return t == itemtype;
|
||||
}
|
||||
|
||||
InnerRing() :
|
||||
NodeRefList(itemtype) {
|
||||
}
|
||||
|
||||
}; // class InnerRing
|
||||
|
||||
static_assert(sizeof(InnerRing) % osmium::memory::align_bytes == 0, "Class osmium::InnerRing has wrong size to be aligned properly!");
|
||||
|
||||
/**
|
||||
* Convert way or (multipolygon) relation id into unique area id.
|
||||
*
|
||||
* @param id Id of a way or relation
|
||||
* @param type Type of object (way or relation)
|
||||
* @returns Area id
|
||||
*/
|
||||
inline osmium::object_id_type object_id_to_area_id(osmium::object_id_type id, osmium::item_type type) noexcept {
|
||||
osmium::object_id_type area_id = std::abs(id) * 2;
|
||||
if (type == osmium::item_type::relation) {
|
||||
++area_id;
|
||||
}
|
||||
return id < 0 ? -area_id : area_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert area id into id of the way or relation it was created from.
|
||||
*
|
||||
* @param id Area id
|
||||
* @returns Way or Relation id.
|
||||
*/
|
||||
inline osmium::object_id_type area_id_to_object_id(osmium::object_id_type id) noexcept {
|
||||
return id / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* An OSM area created out of a closed way or a multipolygon relation.
|
||||
*/
|
||||
class Area : public OSMObject {
|
||||
|
||||
template <typename TDerived, typename T>
|
||||
friend class osmium::builder::OSMObjectBuilder;
|
||||
|
||||
Area() :
|
||||
OSMObject(sizeof(Area), osmium::item_type::area) {
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static constexpr osmium::item_type itemtype = osmium::item_type::area;
|
||||
|
||||
constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
|
||||
return t == itemtype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Was this area created from a way? (In contrast to areas
|
||||
* created from a relation and their members.)
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*/
|
||||
bool from_way() const noexcept {
|
||||
return (positive_id() & 0x1U) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Id of the way or relation this area was created from.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*/
|
||||
osmium::object_id_type orig_id() const noexcept {
|
||||
return osmium::area_id_to_object_id(id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of outer and inner rings of this area.
|
||||
*
|
||||
* Complexity: Linear in the number of rings.
|
||||
*
|
||||
* @returns Pair (number outer rings, number inner rings)
|
||||
*/
|
||||
std::pair<size_t, size_t> num_rings() const {
|
||||
std::pair<size_t, size_t> counter{0, 0};
|
||||
|
||||
for (const auto& item : *this) {
|
||||
switch (item.type()) {
|
||||
case osmium::item_type::outer_ring:
|
||||
++counter.first;
|
||||
break;
|
||||
case osmium::item_type::inner_ring:
|
||||
++counter.second;
|
||||
break;
|
||||
case osmium::item_type::tag_list:
|
||||
// ignore tags
|
||||
break;
|
||||
case osmium::item_type::undefined:
|
||||
case osmium::item_type::node:
|
||||
case osmium::item_type::way:
|
||||
case osmium::item_type::relation:
|
||||
case osmium::item_type::area:
|
||||
case osmium::item_type::changeset:
|
||||
case osmium::item_type::way_node_list:
|
||||
case osmium::item_type::relation_member_list:
|
||||
case osmium::item_type::relation_member_list_with_full_members:
|
||||
case osmium::item_type::changeset_discussion:
|
||||
assert(false && "Children of Area can only be outer/inner_ring and tag_list.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this area is a multipolygon, ie. whether it has more
|
||||
* than one outer ring.
|
||||
*/
|
||||
bool is_multipolygon() const {
|
||||
return num_rings().first > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an iterator range for all outer rings.
|
||||
* You can use the usual begin() and end() functions to iterate over
|
||||
* all outer rings.
|
||||
*/
|
||||
osmium::memory::ItemIteratorRange<const osmium::OuterRing> outer_rings() const {
|
||||
return subitems<const osmium::OuterRing>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an iterator range for all inner rings in the given outer
|
||||
* ring.
|
||||
* You can use the usual begin() and end() functions to iterate over
|
||||
* all inner rings.
|
||||
*/
|
||||
osmium::memory::ItemIteratorRange<const osmium::InnerRing> inner_rings(const osmium::OuterRing& outer) const {
|
||||
const osmium::memory::ItemIteratorRange<const osmium::OuterRing> outer_range{outer.data(), next()};
|
||||
return osmium::memory::ItemIteratorRange<const osmium::InnerRing>{outer_range.cbegin().data(), std::next(outer_range.cbegin()).data()};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the envelope of this area.
|
||||
*
|
||||
* Complexity: Linear in the number of nodes in the outer rings.
|
||||
*/
|
||||
osmium::Box envelope() const noexcept {
|
||||
osmium::Box box;
|
||||
for (const auto& ring : outer_rings()) {
|
||||
box.extend(ring.envelope());
|
||||
}
|
||||
return box;
|
||||
}
|
||||
|
||||
}; // class Area
|
||||
|
||||
static_assert(sizeof(Area) % osmium::memory::align_bytes == 0, "Class osmium::Area has wrong size to be aligned properly!");
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_AREA_HPP
|
||||
+278
@@ -0,0 +1,278 @@
|
||||
#ifndef OSMIUM_OSM_BOX_HPP
|
||||
#define OSMIUM_OSM_BOX_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/osm/location.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <iosfwd>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
/**
|
||||
* Bounding box. A box is defined by two locations (bottom left location
|
||||
* and top right location) or, alternatively by four coordinates (minx,
|
||||
* miny, maxx, and maxy). If both locations are undefined, the box is
|
||||
* undefined, too.
|
||||
*/
|
||||
class Box {
|
||||
|
||||
osmium::Location m_bottom_left{};
|
||||
osmium::Location m_top_right{};
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create undefined Box. Use the extend() function
|
||||
* to add actual bounds.
|
||||
*/
|
||||
constexpr Box() noexcept = default;
|
||||
|
||||
/**
|
||||
* Create box from minimum and maximum coordinates in WGS84.
|
||||
*
|
||||
* @pre @code minx <= maxx && miny <= maxy @endcode
|
||||
*/
|
||||
Box(double minx, double miny, double maxx, double maxy) :
|
||||
m_bottom_left(minx, miny),
|
||||
m_top_right(maxx, maxy) {
|
||||
assert(minx <= maxx && miny <= maxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create box from bottom left and top right locations.
|
||||
*
|
||||
* @pre Either both locations must be defined or neither.
|
||||
* @pre If both locations are defined, the
|
||||
* bottom left location must actually be to the left and below
|
||||
* the top right location. Same coordinates for bottom/top or
|
||||
* left/right are also okay.
|
||||
*/
|
||||
Box(const osmium::Location& bottom_left, const osmium::Location& top_right) :
|
||||
m_bottom_left(bottom_left),
|
||||
m_top_right(top_right) {
|
||||
assert(
|
||||
(!!bottom_left && !!top_right) ||
|
||||
(bottom_left.x() <= top_right.x() && bottom_left.y() <= top_right.y()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend this bounding box by the specified location. If the
|
||||
* location is invalid, the bounding box is unchanged. If the
|
||||
* box is undefined it will only contain the new location after
|
||||
* this call.
|
||||
*
|
||||
* @param location The location we want to extend the box by.
|
||||
* @returns A reference to this box.
|
||||
*/
|
||||
Box& extend(const Location& location) noexcept {
|
||||
if (location.valid()) {
|
||||
if (m_bottom_left) {
|
||||
if (location.x() < m_bottom_left.x()) {
|
||||
m_bottom_left.set_x(location.x());
|
||||
}
|
||||
if (location.x() > m_top_right.x()) {
|
||||
m_top_right.set_x(location.x());
|
||||
}
|
||||
if (location.y() < m_bottom_left.y()) {
|
||||
m_bottom_left.set_y(location.y());
|
||||
}
|
||||
if (location.y() > m_top_right.y()) {
|
||||
m_top_right.set_y(location.y());
|
||||
}
|
||||
} else {
|
||||
m_bottom_left = location;
|
||||
m_top_right = location;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend this bounding box by the specified box. If the
|
||||
* specified box is undefined, the bounding box is unchanged.
|
||||
*
|
||||
* @param box The box to extend by.
|
||||
* @returns A reference to this box.
|
||||
*/
|
||||
Box& extend(const Box& box) noexcept {
|
||||
extend(box.bottom_left());
|
||||
extend(box.top_right());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Box is defined, ie. contains defined locations.
|
||||
*/
|
||||
explicit constexpr operator bool() const noexcept {
|
||||
return static_cast<bool>(m_bottom_left) && static_cast<bool>(m_top_right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Box is valid, ie. defined and inside usual bounds
|
||||
* (-180<=lon<=180, -90<=lat<=90).
|
||||
*/
|
||||
constexpr bool valid() const noexcept {
|
||||
return bottom_left().valid() && top_right().valid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Access bottom-left location.
|
||||
*/
|
||||
constexpr Location bottom_left() const noexcept {
|
||||
return m_bottom_left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access bottom-left location.
|
||||
*/
|
||||
Location& bottom_left() noexcept {
|
||||
return m_bottom_left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access top-right location.
|
||||
*/
|
||||
constexpr Location top_right() const noexcept {
|
||||
return m_top_right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access top-right location.
|
||||
*/
|
||||
Location& top_right() noexcept {
|
||||
return m_top_right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get left boundary.
|
||||
*
|
||||
* @pre @code valid() == true @encode
|
||||
*/
|
||||
double left() const noexcept {
|
||||
assert(valid());
|
||||
return m_bottom_left.lon_without_check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get right boundary.
|
||||
*
|
||||
* @pre @code valid() == true @encode
|
||||
*/
|
||||
double right() const noexcept {
|
||||
assert(valid());
|
||||
return m_top_right.lon_without_check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top boundary.
|
||||
*
|
||||
* @pre @code valid() == true @encode
|
||||
*/
|
||||
double top() const noexcept {
|
||||
assert(valid());
|
||||
return m_top_right.lat_without_check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bottom boundary.
|
||||
*
|
||||
* @pre @code valid() == true @encode
|
||||
*/
|
||||
double bottom() const noexcept {
|
||||
assert(valid());
|
||||
return m_bottom_left.lat_without_check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the location is inside the box.
|
||||
*
|
||||
* @pre Location must be defined.
|
||||
* @pre Box must be defined.
|
||||
*/
|
||||
bool contains(const osmium::Location& location) const noexcept {
|
||||
assert(bottom_left());
|
||||
assert(top_right());
|
||||
assert(location);
|
||||
return location.x() >= bottom_left().x() && location.y() >= bottom_left().y() &&
|
||||
location.x() <= top_right().x() && location.y() <= top_right().y();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate size of the box in square degrees.
|
||||
*
|
||||
* Note that this measure isn't very useful if you want to know the
|
||||
* real-world size of the bounding box!
|
||||
*
|
||||
* @throws osmium::invalid_location unless all coordinates are valid.
|
||||
*/
|
||||
double size() const {
|
||||
return (m_top_right.lon() - m_bottom_left.lon()) *
|
||||
(m_top_right.lat() - m_bottom_left.lat());
|
||||
}
|
||||
|
||||
}; // class Box
|
||||
|
||||
/**
|
||||
* Boxes are equal if both locations are equal. Undefined boxes will
|
||||
* compare equal.
|
||||
*/
|
||||
inline constexpr bool operator==(const Box& lhs, const Box& rhs) noexcept {
|
||||
return lhs.bottom_left() == rhs.bottom_left() &&
|
||||
lhs.top_right() == rhs.top_right();
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a box to a stream. The format is "(LON, LAT, LON, LAT)" or
|
||||
* "(undefined)" if the box is undefined.
|
||||
*
|
||||
* @returns Reference to basic_ostream given as first parameter.
|
||||
*/
|
||||
template <typename TChar, typename TTraits>
|
||||
inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const osmium::Box& box) {
|
||||
if (box) {
|
||||
out << '(';
|
||||
box.bottom_left().as_string_without_check(std::ostream_iterator<char>(out));
|
||||
out << ',';
|
||||
box.top_right().as_string_without_check(std::ostream_iterator<char>(out));
|
||||
out << ')';
|
||||
} else {
|
||||
out << "(undefined)";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_BOX_HPP
|
||||
@@ -0,0 +1,471 @@
|
||||
#ifndef OSMIUM_OSM_CHANGESET_HPP
|
||||
#define OSMIUM_OSM_CHANGESET_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/memory/collection.hpp>
|
||||
#include <osmium/memory/item.hpp>
|
||||
#include <osmium/osm/box.hpp>
|
||||
#include <osmium/osm/entity.hpp>
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
#include <osmium/osm/tag.hpp>
|
||||
#include <osmium/osm/timestamp.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
#include <osmium/osm/types_from_string.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
namespace builder {
|
||||
class ChangesetDiscussionBuilder;
|
||||
class ChangesetBuilder;
|
||||
} // namespace builder
|
||||
|
||||
class Changeset;
|
||||
|
||||
class ChangesetComment : public osmium::memory::detail::ItemHelper {
|
||||
|
||||
friend class osmium::builder::ChangesetDiscussionBuilder;
|
||||
|
||||
osmium::Timestamp m_date;
|
||||
osmium::user_id_type m_uid = 0;
|
||||
changeset_comment_size_type m_text_size = 0;
|
||||
string_size_type m_user_size = 0;
|
||||
|
||||
unsigned char* endpos() {
|
||||
return data() + osmium::memory::padded_length(sizeof(ChangesetComment) + m_user_size + m_text_size);
|
||||
}
|
||||
|
||||
const unsigned char* endpos() const {
|
||||
return data() + osmium::memory::padded_length(sizeof(ChangesetComment) + m_user_size + m_text_size);
|
||||
}
|
||||
|
||||
template <typename TMember>
|
||||
friend class osmium::memory::CollectionIterator;
|
||||
|
||||
unsigned char* next() {
|
||||
return endpos();
|
||||
}
|
||||
|
||||
const unsigned char* next() const {
|
||||
return endpos();
|
||||
}
|
||||
|
||||
void set_user_size(string_size_type size) noexcept {
|
||||
m_user_size = size;
|
||||
}
|
||||
|
||||
void set_text_size(changeset_comment_size_type size) noexcept {
|
||||
m_text_size = size;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static constexpr item_type collection_type = item_type::changeset_discussion;
|
||||
|
||||
ChangesetComment(osmium::Timestamp date, osmium::user_id_type uid) noexcept :
|
||||
m_date(date),
|
||||
m_uid(uid) {
|
||||
}
|
||||
|
||||
ChangesetComment(const ChangesetComment&) = delete;
|
||||
ChangesetComment& operator=(const ChangesetComment&) = delete;
|
||||
|
||||
ChangesetComment(ChangesetComment&&) = delete;
|
||||
ChangesetComment& operator=(ChangesetComment&&) = delete;
|
||||
|
||||
~ChangesetComment() noexcept = default;
|
||||
|
||||
osmium::Timestamp date() const noexcept {
|
||||
return m_date;
|
||||
}
|
||||
|
||||
osmium::user_id_type uid() const noexcept {
|
||||
return m_uid;
|
||||
}
|
||||
|
||||
const char* user() const noexcept {
|
||||
return reinterpret_cast<const char*>(data() + sizeof(ChangesetComment));
|
||||
}
|
||||
|
||||
const char* text() const noexcept {
|
||||
return reinterpret_cast<const char*>(data() + sizeof(ChangesetComment) + m_user_size);
|
||||
}
|
||||
|
||||
}; // class ChangesetComment
|
||||
|
||||
class ChangesetDiscussion : public osmium::memory::Collection<ChangesetComment, osmium::item_type::changeset_discussion> {
|
||||
|
||||
public:
|
||||
|
||||
ChangesetDiscussion() noexcept = default;
|
||||
|
||||
}; // class ChangesetDiscussion
|
||||
|
||||
static_assert(sizeof(ChangesetDiscussion) % osmium::memory::align_bytes == 0, "Class osmium::ChangesetDiscussion has wrong size to be aligned properly!");
|
||||
|
||||
/**
|
||||
* \brief An OSM Changeset, a group of changes made by a single user over
|
||||
* a short period of time.
|
||||
*
|
||||
* You can not create Changeset objects directly. Use the ChangesetBuilder
|
||||
* class to create Changesets in a Buffer.
|
||||
*/
|
||||
class Changeset : public osmium::OSMEntity {
|
||||
|
||||
friend class osmium::builder::ChangesetBuilder;
|
||||
|
||||
osmium::Box m_bounds;
|
||||
osmium::Timestamp m_created_at;
|
||||
osmium::Timestamp m_closed_at;
|
||||
changeset_id_type m_id = 0;
|
||||
num_changes_type m_num_changes = 0;
|
||||
num_comments_type m_num_comments = 0;
|
||||
user_id_type m_uid = 0;
|
||||
string_size_type m_user_size = 0;
|
||||
int16_t m_padding1 = 0;
|
||||
int32_t m_padding2 = 0;
|
||||
|
||||
Changeset() :
|
||||
OSMEntity(sizeof(Changeset), osmium::item_type::changeset) {
|
||||
}
|
||||
|
||||
void set_user_size(string_size_type size) noexcept {
|
||||
m_user_size = size;
|
||||
}
|
||||
|
||||
string_size_type user_size() const noexcept {
|
||||
return m_user_size;
|
||||
}
|
||||
|
||||
unsigned char* subitems_position() {
|
||||
return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
|
||||
}
|
||||
|
||||
const unsigned char* subitems_position() const {
|
||||
return data() + osmium::memory::padded_length(sizeof(Changeset) + m_user_size);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static constexpr osmium::item_type itemtype = osmium::item_type::changeset;
|
||||
|
||||
constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
|
||||
return t == itemtype;
|
||||
}
|
||||
|
||||
// Dummy to avoid warning because of unused private fields. Do not use.
|
||||
int32_t do_not_use() const noexcept {
|
||||
return m_padding1 + m_padding2;
|
||||
}
|
||||
|
||||
/// Get ID of this changeset
|
||||
changeset_id_type id() const noexcept {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ID of this changeset
|
||||
*
|
||||
* @param id The id.
|
||||
* @returns Reference to changeset to make calls chainable.
|
||||
*/
|
||||
Changeset& set_id(changeset_id_type id) noexcept {
|
||||
m_id = id;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ID of this changeset.
|
||||
*
|
||||
* @param id The id.
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
Changeset& set_id(const char* id) {
|
||||
return set_id(osmium::string_to_changeset_id(id));
|
||||
}
|
||||
|
||||
/// Get user id.
|
||||
user_id_type uid() const noexcept {
|
||||
return m_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set user id.
|
||||
*
|
||||
* @param uid The user id.
|
||||
* @returns Reference to changeset to make calls chainable.
|
||||
*/
|
||||
Changeset& set_uid(user_id_type uid) noexcept {
|
||||
m_uid = uid;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set user id to given uid or to 0 (anonymous user) if the given
|
||||
* uid is smaller than 0.
|
||||
*
|
||||
* @param uid The user id.
|
||||
* @returns Reference to changeset to make calls chainable.
|
||||
*/
|
||||
Changeset& set_uid_from_signed(signed_user_id_type uid) noexcept {
|
||||
m_uid = uid < 0 ? 0 : static_cast<user_id_type>(uid);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set user id to given uid or to 0 (anonymous user) if the given
|
||||
* uid is smaller than 0.
|
||||
*
|
||||
* @returns Reference to changeset to make calls chainable.
|
||||
*/
|
||||
Changeset& set_uid(const char* uid) {
|
||||
m_uid = string_to_uid(uid);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Is this user anonymous?
|
||||
bool user_is_anonymous() const noexcept {
|
||||
return m_uid == 0;
|
||||
}
|
||||
|
||||
/// Get timestamp when this changeset was created.
|
||||
osmium::Timestamp created_at() const noexcept {
|
||||
return m_created_at;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get timestamp when this changeset was closed.
|
||||
*
|
||||
* @returns Timestamp. Will return the empty Timestamp when the
|
||||
* changeset is not yet closed.
|
||||
*/
|
||||
osmium::Timestamp closed_at() const noexcept {
|
||||
return m_closed_at;
|
||||
}
|
||||
|
||||
/// Is this changeset open?
|
||||
bool open() const noexcept {
|
||||
return m_closed_at == osmium::Timestamp();
|
||||
}
|
||||
|
||||
/// Is this changeset closed?
|
||||
bool closed() const noexcept {
|
||||
return !open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the timestamp when this changeset was created.
|
||||
*
|
||||
* @param timestamp Timestamp
|
||||
* @returns Reference to changeset to make calls chainable.
|
||||
*/
|
||||
Changeset& set_created_at(const osmium::Timestamp& timestamp) {
|
||||
m_created_at = timestamp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the timestamp when this changeset was closed.
|
||||
*
|
||||
* @param timestamp Timestamp
|
||||
* @returns Reference to changeset to make calls chainable.
|
||||
*/
|
||||
Changeset& set_closed_at(const osmium::Timestamp& timestamp) {
|
||||
m_closed_at = timestamp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Get the number of changes in this changeset
|
||||
num_changes_type num_changes() const noexcept {
|
||||
return m_num_changes;
|
||||
}
|
||||
|
||||
/// Set the number of changes in this changeset
|
||||
Changeset& set_num_changes(num_changes_type num_changes) noexcept {
|
||||
m_num_changes = num_changes;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Set the number of changes in this changeset
|
||||
Changeset& set_num_changes(const char* num_changes) {
|
||||
return set_num_changes(osmium::string_to_num_changes(num_changes));
|
||||
}
|
||||
|
||||
/// Get the number of comments in this changeset
|
||||
num_comments_type num_comments() const noexcept {
|
||||
return m_num_comments;
|
||||
}
|
||||
|
||||
/// Set the number of comments in this changeset
|
||||
Changeset& set_num_comments(num_comments_type num_comments) noexcept {
|
||||
m_num_comments = num_comments;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Set the number of comments in this changeset
|
||||
Changeset& set_num_comments(const char* num_comments) {
|
||||
return set_num_comments(osmium::string_to_num_comments(num_comments));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bounding box of this changeset.
|
||||
*
|
||||
* @returns Bounding box. Can be empty.
|
||||
*/
|
||||
osmium::Box& bounds() noexcept {
|
||||
return m_bounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bounding box of this changeset.
|
||||
*
|
||||
* @returns Bounding box. Can be empty.
|
||||
*/
|
||||
const osmium::Box& bounds() const noexcept {
|
||||
return m_bounds;
|
||||
}
|
||||
|
||||
/// Get user name.
|
||||
const char* user() const {
|
||||
return reinterpret_cast<const char*>(data() + sizeof(Changeset));
|
||||
}
|
||||
|
||||
/// Clear user name.
|
||||
void clear_user() noexcept {
|
||||
std::memset(data() + sizeof(Changeset), 0, user_size());
|
||||
}
|
||||
|
||||
/// Get the list of tags.
|
||||
const TagList& tags() const {
|
||||
return osmium::detail::subitem_of_type<const TagList>(cbegin(), cend());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set named attribute.
|
||||
*
|
||||
* @param attr Name of the attribute (must be one of "id", "version",
|
||||
* "changeset", "timestamp", "uid", "visible")
|
||||
* @param value Value of the attribute
|
||||
*/
|
||||
void set_attribute(const char* attr, const char* value) {
|
||||
if (!std::strcmp(attr, "id")) {
|
||||
set_id(value);
|
||||
} else if (!std::strcmp(attr, "num_changes")) {
|
||||
set_num_changes(value);
|
||||
} else if (!std::strcmp(attr, "comments_count")) {
|
||||
set_num_comments(value);
|
||||
} else if (!std::strcmp(attr, "created_at")) {
|
||||
set_created_at(osmium::Timestamp(value));
|
||||
} else if (!std::strcmp(attr, "closed_at")) {
|
||||
set_closed_at(osmium::Timestamp(value));
|
||||
} else if (!std::strcmp(attr, "uid")) {
|
||||
set_uid(value);
|
||||
}
|
||||
}
|
||||
|
||||
using iterator = osmium::memory::CollectionIterator<Item>;
|
||||
using const_iterator = osmium::memory::CollectionIterator<const Item>;
|
||||
|
||||
iterator begin() {
|
||||
return iterator(subitems_position());
|
||||
}
|
||||
|
||||
iterator end() {
|
||||
return iterator(data() + padded_size());
|
||||
}
|
||||
|
||||
const_iterator cbegin() const {
|
||||
return const_iterator(subitems_position());
|
||||
}
|
||||
|
||||
const_iterator cend() const {
|
||||
return const_iterator(data() + padded_size());
|
||||
}
|
||||
|
||||
const_iterator begin() const {
|
||||
return cbegin();
|
||||
}
|
||||
|
||||
const_iterator end() const {
|
||||
return cend();
|
||||
}
|
||||
|
||||
ChangesetDiscussion& discussion() {
|
||||
return osmium::detail::subitem_of_type<ChangesetDiscussion>(begin(), end());
|
||||
}
|
||||
|
||||
const ChangesetDiscussion& discussion() const {
|
||||
return osmium::detail::subitem_of_type<const ChangesetDiscussion>(cbegin(), cend());
|
||||
}
|
||||
|
||||
}; // class Changeset
|
||||
|
||||
static_assert(sizeof(Changeset) % osmium::memory::align_bytes == 0, "Class osmium::Changeset has wrong size to be aligned properly!");
|
||||
|
||||
/**
|
||||
* Changesets are equal if their IDs are equal.
|
||||
*/
|
||||
inline bool operator==(const Changeset& lhs, const Changeset& rhs) {
|
||||
return lhs.id() == rhs.id();
|
||||
}
|
||||
|
||||
inline bool operator!=(const Changeset& lhs, const Changeset& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changesets can be ordered by id.
|
||||
*/
|
||||
inline bool operator<(const Changeset& lhs, const Changeset& rhs) {
|
||||
return lhs.id() < rhs.id();
|
||||
}
|
||||
|
||||
inline bool operator>(const Changeset& lhs, const Changeset& rhs) {
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator<=(const Changeset& lhs, const Changeset& rhs) {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const Changeset& lhs, const Changeset& rhs) {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_CHANGESET_HPP
|
||||
+266
@@ -0,0 +1,266 @@
|
||||
#ifndef OSMIUM_OSM_CRC_HPP
|
||||
#define OSMIUM_OSM_CRC_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/osm/area.hpp>
|
||||
#include <osmium/osm/box.hpp>
|
||||
#include <osmium/osm/changeset.hpp>
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
#include <osmium/osm/location.hpp>
|
||||
#include <osmium/osm/node.hpp>
|
||||
#include <osmium/osm/node_ref.hpp>
|
||||
#include <osmium/osm/node_ref_list.hpp>
|
||||
#include <osmium/osm/object.hpp>
|
||||
#include <osmium/osm/relation.hpp>
|
||||
#include <osmium/osm/tag.hpp>
|
||||
#include <osmium/osm/timestamp.hpp>
|
||||
#include <osmium/osm/way.hpp>
|
||||
#include <osmium/util/endian.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
inline namespace util {
|
||||
|
||||
inline uint16_t byte_swap_16(uint16_t value) noexcept {
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
return __builtin_bswap16(value);
|
||||
#else
|
||||
return (value >> 8) | (value << 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline uint32_t byte_swap_32(uint32_t value) noexcept {
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
return __builtin_bswap32(value);
|
||||
#else
|
||||
return (value >> 24) |
|
||||
((value >> 8) & 0x0000FF00) |
|
||||
((value << 8) & 0x00FF0000) |
|
||||
(value << 24);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline uint64_t byte_swap_64(uint64_t value) noexcept {
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
return __builtin_bswap64(value);
|
||||
#else
|
||||
const uint64_t val1 = byte_swap_32(value & 0xFFFFFFFF);
|
||||
const uint64_t val2 = byte_swap_32(value >> 32);
|
||||
return (val1 << 32) | val2;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
||||
/**
|
||||
* Framework for computing a checksum from OSM data. This class must be
|
||||
* instantiated with a policy class that does the actual CRC calculations.
|
||||
* It must have the process_byte(), process_bytes(), and checksum()
|
||||
* member functions implemented according to the description in Boost
|
||||
* (https://www.boost.org/doc/libs/release/libs/crc/crc.html).
|
||||
*
|
||||
* Typically you will either use the boost::crc_32_type from the Boost
|
||||
* CRC library or the osmium::CRC_zlib class which uses the zlib library
|
||||
* for this, but other checksums are possible.
|
||||
*
|
||||
* @tparam TCRC A CRC type.
|
||||
*/
|
||||
template <typename TCRC>
|
||||
class CRC {
|
||||
|
||||
TCRC m_crc;
|
||||
|
||||
public:
|
||||
|
||||
TCRC& operator()() noexcept {
|
||||
return m_crc;
|
||||
}
|
||||
|
||||
const TCRC& operator()() const noexcept {
|
||||
return m_crc;
|
||||
}
|
||||
|
||||
void update_bool(const bool value) noexcept {
|
||||
m_crc.process_byte(value);
|
||||
}
|
||||
|
||||
void update_int8(const uint8_t value) noexcept {
|
||||
m_crc.process_byte(value);
|
||||
}
|
||||
|
||||
void update_int16(const uint16_t value) noexcept {
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
m_crc.process_bytes(&value, sizeof(uint16_t));
|
||||
#else
|
||||
const uint16_t v = osmium::byte_swap_16(value);
|
||||
m_crc.process_bytes(&v, sizeof(uint16_t));
|
||||
#endif
|
||||
}
|
||||
|
||||
void update_int32(const uint32_t value) noexcept {
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
m_crc.process_bytes(&value, sizeof(uint32_t));
|
||||
#else
|
||||
const uint32_t v = osmium::byte_swap_32(value);
|
||||
m_crc.process_bytes(&v, sizeof(uint32_t));
|
||||
#endif
|
||||
}
|
||||
|
||||
void update_int64(const uint64_t value) noexcept {
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
m_crc.process_bytes(&value, sizeof(uint64_t));
|
||||
#else
|
||||
const uint64_t v = osmium::byte_swap_64(value);
|
||||
m_crc.process_bytes(&v, sizeof(uint64_t));
|
||||
#endif
|
||||
}
|
||||
|
||||
void update_string(const char* str) noexcept {
|
||||
while (*str) {
|
||||
m_crc.process_byte(*str++);
|
||||
}
|
||||
}
|
||||
|
||||
void update(const Timestamp& timestamp) noexcept {
|
||||
update_int32(static_cast<uint32_t>(timestamp));
|
||||
}
|
||||
|
||||
void update(const osmium::Location& location) noexcept {
|
||||
update_int32(location.x());
|
||||
update_int32(location.y());
|
||||
}
|
||||
|
||||
void update(const osmium::Box& box) noexcept {
|
||||
update(box.bottom_left());
|
||||
update(box.top_right());
|
||||
}
|
||||
|
||||
void update(const NodeRef& node_ref) noexcept {
|
||||
update_int64(static_cast<uint64_t>(node_ref.ref()));
|
||||
update(node_ref.location());
|
||||
}
|
||||
|
||||
void update(const NodeRefList& node_refs) noexcept {
|
||||
for (const NodeRef& node_ref : node_refs) {
|
||||
update(node_ref);
|
||||
}
|
||||
}
|
||||
|
||||
void update(const TagList& tags) noexcept {
|
||||
for (const Tag& tag : tags) {
|
||||
update_string(tag.key());
|
||||
update_string(tag.value());
|
||||
}
|
||||
}
|
||||
|
||||
void update(const osmium::RelationMember& member) noexcept {
|
||||
update_int64(static_cast<uint64_t>(member.ref()));
|
||||
update_int16(static_cast<uint16_t>(member.type()));
|
||||
update_string(member.role());
|
||||
}
|
||||
|
||||
void update(const osmium::RelationMemberList& members) noexcept {
|
||||
for (const RelationMember& member : members) {
|
||||
update(member);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX Changeset id is not added to the CRC. This is an oversight,
|
||||
// but we don't want to change this now to keep compatibility.
|
||||
void update(const osmium::OSMObject& object) noexcept {
|
||||
update_int64(static_cast<uint64_t>(object.id()));
|
||||
update_bool(object.visible());
|
||||
update_int32(object.version());
|
||||
update(object.timestamp());
|
||||
update_int32(object.uid());
|
||||
update_string(object.user());
|
||||
update(object.tags());
|
||||
}
|
||||
|
||||
void update(const osmium::Node& node) noexcept {
|
||||
update(static_cast<const osmium::OSMObject&>(node));
|
||||
update(node.location());
|
||||
}
|
||||
|
||||
void update(const osmium::Way& way) noexcept {
|
||||
update(static_cast<const osmium::OSMObject&>(way));
|
||||
update(way.nodes());
|
||||
}
|
||||
|
||||
void update(const osmium::Relation& relation) noexcept {
|
||||
update(static_cast<const osmium::OSMObject&>(relation));
|
||||
update(relation.members());
|
||||
}
|
||||
|
||||
void update(const osmium::Area& area) noexcept {
|
||||
update(static_cast<const osmium::OSMObject&>(area));
|
||||
for (const auto& subitem : area) {
|
||||
if (subitem.type() == osmium::item_type::outer_ring ||
|
||||
subitem.type() == osmium::item_type::inner_ring) {
|
||||
update(static_cast<const osmium::NodeRefList&>(subitem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void update(const osmium::ChangesetDiscussion& discussion) noexcept {
|
||||
for (const auto& comment : discussion) {
|
||||
update(comment.date());
|
||||
update_int32(comment.uid());
|
||||
update_string(comment.user());
|
||||
update_string(comment.text());
|
||||
}
|
||||
}
|
||||
|
||||
void update(const osmium::Changeset& changeset) noexcept {
|
||||
// The static_cast and use of update_int64 is necessary here
|
||||
// for backwards compatibility. It should have used update_int32.
|
||||
update_int64(static_cast<uint64_t>(changeset.id()));
|
||||
update(changeset.created_at());
|
||||
update(changeset.closed_at());
|
||||
update(changeset.bounds());
|
||||
update_int32(changeset.num_changes());
|
||||
update_int32(changeset.num_comments());
|
||||
update_int32(changeset.uid());
|
||||
update_string(changeset.user());
|
||||
update(changeset.tags());
|
||||
update(changeset.discussion());
|
||||
}
|
||||
|
||||
}; // class CRC
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_CRC_HPP
|
||||
@@ -0,0 +1,77 @@
|
||||
#ifndef OSMIUM_OSM_CRC_ZLIB_HPP
|
||||
#define OSMIUM_OSM_CRC_ZLIB_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
/**
|
||||
* This class is used together with the CRC class to implement a CRC32
|
||||
* checksum based on the implementation from zlib.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* @code
|
||||
* osmium::CRC<osmium::CRC_zlib> crc32;
|
||||
* const osmium::Node& node = ...;
|
||||
* crc32.update(node);
|
||||
* std::cout << crc32.checksum() << '\n';
|
||||
* @endcode
|
||||
*/
|
||||
class CRC_zlib {
|
||||
|
||||
unsigned long m_crc32 = ::crc32(0, nullptr, 0); // NOLINT(google-runtime-int)
|
||||
|
||||
public:
|
||||
|
||||
void process_byte(const unsigned char byte) noexcept {
|
||||
m_crc32 = ::crc32(m_crc32, &byte, 1U);
|
||||
}
|
||||
|
||||
void process_bytes(const void* buffer, std::size_t byte_count) noexcept {
|
||||
m_crc32 = ::crc32(m_crc32, reinterpret_cast<const unsigned char*>(buffer), static_cast<unsigned int>(byte_count));
|
||||
}
|
||||
|
||||
unsigned long checksum() const noexcept { // NOLINT(google-runtime-int)
|
||||
return m_crc32;
|
||||
}
|
||||
|
||||
}; // class CRC_zlib
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_CRC_ZLIB_HPP
|
||||
@@ -0,0 +1,271 @@
|
||||
#ifndef OSMIUM_OSM_DIFF_OBJECT_HPP
|
||||
#define OSMIUM_OSM_DIFF_OBJECT_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
#include <osmium/osm/object.hpp>
|
||||
#include <osmium/osm/timestamp.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
class Node;
|
||||
class Way;
|
||||
class Relation;
|
||||
|
||||
/**
|
||||
* A DiffObject holds pointers to three OSMObjects, the current object,
|
||||
* the previous, and the next. They always have the same type (Node, Way,
|
||||
* or Relation) and the same ID, but may have different versions.
|
||||
*
|
||||
* It is used when iterating over OSM files with history data to make
|
||||
* working with versioned OSM objects easier. Because you have access to
|
||||
* the previous and next objects as well as the current one, comparisons
|
||||
* between object versions is easy.
|
||||
*
|
||||
* If the current object is the first version available, the previous
|
||||
* pointer must be the same as the current one. If the current object is
|
||||
* the last version available, the next pointer must be the same as the
|
||||
* current one.
|
||||
*
|
||||
* DiffObjects are immutable.
|
||||
*/
|
||||
class DiffObject {
|
||||
|
||||
const osmium::OSMObject* m_prev = nullptr;
|
||||
const osmium::OSMObject* m_curr = nullptr;
|
||||
const osmium::OSMObject* m_next = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default construct an empty DiffObject. Most methods of this class
|
||||
* can not be called on empty DiffObjects.
|
||||
*/
|
||||
DiffObject() noexcept = default;
|
||||
|
||||
/**
|
||||
* Construct a non-empty DiffObject from the given OSMObjects. All
|
||||
* OSMObjects must be of the same type (Node, Way, or Relation) and
|
||||
* have the same ID.
|
||||
*/
|
||||
DiffObject(const osmium::OSMObject& prev, const osmium::OSMObject& curr, const osmium::OSMObject& next) noexcept :
|
||||
m_prev(&prev),
|
||||
m_curr(&curr),
|
||||
m_next(&next) {
|
||||
assert(prev.type() == curr.type() && curr.type() == next.type());
|
||||
assert(prev.id() == curr.id() && curr.id() == next.id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the DiffObject was created empty.
|
||||
*/
|
||||
bool empty() const noexcept {
|
||||
return m_prev == nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the previous object stored.
|
||||
*
|
||||
* @pre DiffObject must not be empty.
|
||||
*/
|
||||
const osmium::OSMObject& prev() const noexcept {
|
||||
assert(m_prev && m_curr && m_next);
|
||||
return *m_prev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current object stored.
|
||||
*
|
||||
* @pre DiffObject must not be empty.
|
||||
*/
|
||||
const osmium::OSMObject& curr() const noexcept {
|
||||
assert(m_prev && m_curr && m_next);
|
||||
return *m_curr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next object stored.
|
||||
*
|
||||
* @pre DiffObject must not be empty.
|
||||
*/
|
||||
const osmium::OSMObject& next() const noexcept {
|
||||
assert(m_prev && m_curr && m_next);
|
||||
return *m_next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the current object version the first (with this type and ID)?
|
||||
*
|
||||
* @pre DiffObject must not be empty.
|
||||
*/
|
||||
bool first() const noexcept {
|
||||
assert(m_prev && m_curr && m_next);
|
||||
return m_prev == m_curr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the current object version the last (with this type and ID)?
|
||||
*
|
||||
* @pre DiffObject must not be empty.
|
||||
*/
|
||||
bool last() const noexcept {
|
||||
assert(m_prev && m_curr && m_next);
|
||||
return m_curr == m_next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of the current object.
|
||||
*
|
||||
* @pre DiffObject must not be empty.
|
||||
*/
|
||||
osmium::item_type type() const noexcept {
|
||||
assert(m_prev && m_curr && m_next);
|
||||
return m_curr->type();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ID of the current object.
|
||||
*
|
||||
* @pre DiffObject must not be empty.
|
||||
*/
|
||||
osmium::object_id_type id() const noexcept {
|
||||
assert(m_prev && m_curr && m_next);
|
||||
return m_curr->id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version of the current object.
|
||||
*
|
||||
* @pre DiffObject must not be empty.
|
||||
*/
|
||||
osmium::object_version_type version() const noexcept {
|
||||
assert(m_prev && m_curr && m_next);
|
||||
return m_curr->version();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the changeset ID of the current object.
|
||||
*
|
||||
* @pre DiffObject must not be empty.
|
||||
*/
|
||||
osmium::changeset_id_type changeset() const noexcept {
|
||||
assert(m_prev && m_curr && m_next);
|
||||
return m_curr->changeset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the timestamp when the current object version was created.
|
||||
*
|
||||
* @pre DiffObject must not be empty.
|
||||
*/
|
||||
osmium::Timestamp start_time() const noexcept {
|
||||
assert(m_prev && m_curr && m_next);
|
||||
return m_curr->timestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the timestamp when the current version of the object is
|
||||
* not valid any more, ie the time when the next version of the object
|
||||
* is valid. If this is the last version of the object, this will
|
||||
* return a special "end of time" timestamp that is guaranteed to
|
||||
* be larger than any normal timestamp.
|
||||
*
|
||||
* @pre DiffObject must not be empty.
|
||||
*/
|
||||
osmium::Timestamp end_time() const noexcept {
|
||||
assert(m_prev && m_curr && m_next);
|
||||
return last() ? osmium::end_of_time() : m_next->timestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Current object version is valid between time "from" (inclusive) and
|
||||
* time "to" (not inclusive).
|
||||
*
|
||||
* This is a bit more complex than you'd think, because we have to
|
||||
* handle the case properly where the start_time() == end_time().
|
||||
*
|
||||
* @pre DiffObject must not be empty.
|
||||
*/
|
||||
bool is_between(const osmium::Timestamp& from, const osmium::Timestamp& to) const noexcept {
|
||||
assert(m_prev && m_curr && m_next);
|
||||
return start_time() < to &&
|
||||
((start_time() != end_time() && end_time() > from) ||
|
||||
(start_time() == end_time() && end_time() >= from));
|
||||
}
|
||||
|
||||
/**
|
||||
* Current object version is visible at the given timestamp.
|
||||
*
|
||||
* @pre DiffObject must not be empty.
|
||||
*/
|
||||
bool is_visible_at(const osmium::Timestamp& timestamp) const noexcept {
|
||||
assert(m_prev && m_curr && m_next);
|
||||
return start_time() <= timestamp && end_time() > timestamp && m_curr->visible();
|
||||
}
|
||||
|
||||
}; // class DiffObject
|
||||
|
||||
template <typename T>
|
||||
class DiffObjectDerived : public DiffObject {
|
||||
|
||||
public:
|
||||
|
||||
DiffObjectDerived(const T& prev, const T& curr, const T& next) noexcept :
|
||||
DiffObject(prev, curr, next) {
|
||||
}
|
||||
|
||||
const T& prev() const noexcept {
|
||||
return static_cast<const T&>(DiffObject::prev());
|
||||
}
|
||||
|
||||
const T& curr() const noexcept {
|
||||
return static_cast<const T&>(DiffObject::curr());
|
||||
}
|
||||
|
||||
const T& next() const noexcept {
|
||||
return static_cast<const T&>(DiffObject::next());
|
||||
}
|
||||
|
||||
}; // class DiffObjectDerived
|
||||
|
||||
using DiffNode = DiffObjectDerived<osmium::Node>;
|
||||
using DiffWay = DiffObjectDerived<osmium::Way>;
|
||||
using DiffRelation = DiffObjectDerived<osmium::Relation>;
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_DIFF_OBJECT_HPP
|
||||
@@ -0,0 +1,88 @@
|
||||
#ifndef OSMIUM_OSM_ENTITY_HPP
|
||||
#define OSMIUM_OSM_ENTITY_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/memory/item.hpp>
|
||||
#include <osmium/osm/entity_bits.hpp>
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename TSubitem, typename TIter>
|
||||
inline TSubitem& subitem_of_type(TIter it, const TIter& end) {
|
||||
for (; it != end; ++it) {
|
||||
if (TSubitem::is_compatible_to(it->type()) && !it->removed()) {
|
||||
return reinterpret_cast<TSubitem&>(*it);
|
||||
}
|
||||
}
|
||||
|
||||
// If no subitem of the TSubitem type was found,
|
||||
// return a default constructed one.
|
||||
static TSubitem subitem;
|
||||
return subitem;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* \brief OSMEntity is the abstract base class for the OSMObject and
|
||||
* Changeset classes.
|
||||
*/
|
||||
class OSMEntity : public osmium::memory::Item {
|
||||
|
||||
public:
|
||||
|
||||
constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
|
||||
return t == osmium::item_type::node ||
|
||||
t == osmium::item_type::way ||
|
||||
t == osmium::item_type::relation ||
|
||||
t == osmium::item_type::area ||
|
||||
t == osmium::item_type::changeset;
|
||||
}
|
||||
|
||||
explicit OSMEntity(osmium::memory::item_size_type size, osmium::item_type type) :
|
||||
Item(size, type) {
|
||||
}
|
||||
|
||||
bool type_is_in(osmium::osm_entity_bits::type entity_bits) const {
|
||||
return (osm_entity_bits::from_item_type(type()) & entity_bits) != 0;
|
||||
}
|
||||
|
||||
}; // class OSMEntity
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_ENTITY_HPP
|
||||
@@ -0,0 +1,121 @@
|
||||
#ifndef OSMIUM_OSM_ENTITY_BITS_HPP
|
||||
#define OSMIUM_OSM_ENTITY_BITS_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
/**
|
||||
* @brief Bit field for OSM entity types.
|
||||
*/
|
||||
namespace osm_entity_bits {
|
||||
|
||||
/**
|
||||
* Describes zero or more OSM entities.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* @code{.cpp}
|
||||
* osmium::osm_entity_bits::type entities = osmium::osm_entity_bits::node | osmium::osm_entity_bits::way;
|
||||
*
|
||||
* entities |= osmium::osm_entity_bits::relation;
|
||||
*
|
||||
* assert(entities & osmium::osm_entity_bits::object);
|
||||
*
|
||||
* assert(! (entities & osmium::osm_entity_bits::changeset));
|
||||
* @endcode
|
||||
*/
|
||||
enum type : unsigned char { // this should have been an enum class
|
||||
// but now we can't change it any more
|
||||
// without breaking lots of code
|
||||
|
||||
nothing = 0x00,
|
||||
node = 0x01,
|
||||
way = 0x02,
|
||||
relation = 0x04,
|
||||
nwr = 0x07, ///< node, way, or relation object
|
||||
area = 0x08,
|
||||
nwra = 0x0f, ///< node, way, relation, or area object
|
||||
object = 0x0f, ///< node, way, relation, or area object
|
||||
changeset = 0x10,
|
||||
all = 0x1f ///< object or changeset
|
||||
|
||||
}; // enum type
|
||||
|
||||
inline constexpr type operator|(const type lhs, const type rhs) noexcept {
|
||||
return static_cast<type>(static_cast<unsigned char>(lhs) | static_cast<unsigned char>(rhs));
|
||||
}
|
||||
|
||||
inline constexpr type operator&(const type lhs, const type rhs) noexcept {
|
||||
return static_cast<type>(static_cast<unsigned char>(lhs) & static_cast<unsigned char>(rhs));
|
||||
}
|
||||
|
||||
inline constexpr type operator~(const type value) noexcept {
|
||||
return all & static_cast<type>(~static_cast<unsigned char>(value));
|
||||
}
|
||||
|
||||
inline type& operator|=(type& lhs, const type rhs) noexcept {
|
||||
lhs = lhs | rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
inline type operator&=(type& lhs, const type rhs) noexcept {
|
||||
lhs = lhs & rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entity_bits from item_type.
|
||||
*
|
||||
* @pre item_type must be undefined, node, way, relation, area, or
|
||||
* changeset.
|
||||
*/
|
||||
inline type from_item_type(osmium::item_type item_type) noexcept {
|
||||
const auto ut = static_cast<std::underlying_type<osmium::item_type>::type>(item_type);
|
||||
assert(ut <= 0x05);
|
||||
if (ut == 0) {
|
||||
return nothing;
|
||||
}
|
||||
return static_cast<osmium::osm_entity_bits::type>(1U << (ut - 1U));
|
||||
}
|
||||
|
||||
} // namespace osm_entity_bits
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_ENTITY_BITS_HPP
|
||||
@@ -0,0 +1,207 @@
|
||||
#ifndef OSMIUM_OSM_ITEM_TYPE_HPP
|
||||
#define OSMIUM_OSM_ITEM_TYPE_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/util/compatibility.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint> // IWYU pragma: keep
|
||||
#include <iosfwd>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
enum class item_type : uint16_t {
|
||||
|
||||
undefined = 0x00,
|
||||
node = 0x01,
|
||||
way = 0x02,
|
||||
relation = 0x03,
|
||||
area = 0x04,
|
||||
changeset = 0x05,
|
||||
tag_list = 0x11,
|
||||
way_node_list = 0x12,
|
||||
relation_member_list = 0x13,
|
||||
relation_member_list_with_full_members = 0x23,
|
||||
outer_ring = 0x40,
|
||||
inner_ring = 0x41,
|
||||
changeset_discussion = 0x80
|
||||
|
||||
}; // enum class item_type
|
||||
|
||||
/**
|
||||
* Return item_type for index:
|
||||
* 0 -> node, 1 -> way, 2 -> relation
|
||||
*
|
||||
* @param i Index. Must be between 0 and 2.
|
||||
*
|
||||
* @returns Item type.
|
||||
*/
|
||||
inline item_type nwr_index_to_item_type(unsigned int i) noexcept {
|
||||
assert(i <= 2);
|
||||
return static_cast<item_type>(i + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return index for item_type:
|
||||
* node -> 0, way -> 1, relation -> 2
|
||||
*
|
||||
* @param type Item type. Must be node, way, or relation.
|
||||
*
|
||||
* @returns Index.
|
||||
*/
|
||||
inline unsigned int item_type_to_nwr_index(item_type type) noexcept {
|
||||
const auto i = static_cast<unsigned int>(type);
|
||||
assert(i >= 1 && i <= 3);
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
inline item_type char_to_item_type(const char c) noexcept {
|
||||
switch (c) {
|
||||
case 'n':
|
||||
return item_type::node;
|
||||
case 'w':
|
||||
return item_type::way;
|
||||
case 'r':
|
||||
return item_type::relation;
|
||||
case 'a':
|
||||
return item_type::area;
|
||||
case 'c':
|
||||
return item_type::changeset;
|
||||
case 'T':
|
||||
return item_type::tag_list;
|
||||
case 'N':
|
||||
return item_type::way_node_list;
|
||||
case 'M':
|
||||
return item_type::relation_member_list;
|
||||
case 'F':
|
||||
return item_type::relation_member_list_with_full_members;
|
||||
case 'O':
|
||||
return item_type::outer_ring;
|
||||
case 'I':
|
||||
return item_type::inner_ring;
|
||||
case 'D':
|
||||
return item_type::changeset_discussion;
|
||||
default: // 'X'
|
||||
break;
|
||||
}
|
||||
return item_type::undefined;
|
||||
}
|
||||
|
||||
inline char item_type_to_char(const item_type type) noexcept {
|
||||
switch (type) {
|
||||
case item_type::node:
|
||||
return 'n';
|
||||
case item_type::way:
|
||||
return 'w';
|
||||
case item_type::relation:
|
||||
return 'r';
|
||||
case item_type::area:
|
||||
return 'a';
|
||||
case item_type::changeset:
|
||||
return 'c';
|
||||
case item_type::tag_list:
|
||||
return 'T';
|
||||
case item_type::way_node_list:
|
||||
return 'N';
|
||||
case item_type::relation_member_list:
|
||||
return 'M';
|
||||
case item_type::relation_member_list_with_full_members:
|
||||
return 'F';
|
||||
case item_type::outer_ring:
|
||||
return 'O';
|
||||
case item_type::inner_ring:
|
||||
return 'I';
|
||||
case item_type::changeset_discussion:
|
||||
return 'D';
|
||||
default: // item_type::undefined
|
||||
break;
|
||||
}
|
||||
return 'X';
|
||||
}
|
||||
|
||||
inline const char* item_type_to_name(const item_type type) noexcept {
|
||||
switch (type) {
|
||||
case item_type::node:
|
||||
return "node";
|
||||
case item_type::way:
|
||||
return "way";
|
||||
case item_type::relation:
|
||||
return "relation";
|
||||
case item_type::area:
|
||||
return "area";
|
||||
case item_type::changeset:
|
||||
return "changeset";
|
||||
case item_type::tag_list:
|
||||
return "tag_list";
|
||||
case item_type::way_node_list:
|
||||
return "way_node_list";
|
||||
case item_type::relation_member_list:
|
||||
return "relation_member_list";
|
||||
case item_type::relation_member_list_with_full_members:
|
||||
return "relation_member_list_with_full_members";
|
||||
case item_type::outer_ring:
|
||||
return "outer_ring";
|
||||
case item_type::inner_ring:
|
||||
return "inner_ring";
|
||||
case item_type::changeset_discussion:
|
||||
return "changeset_discussion";
|
||||
default: // item_type::undefined
|
||||
break;
|
||||
}
|
||||
return "undefined";
|
||||
}
|
||||
|
||||
template <typename TChar, typename TTraits>
|
||||
inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const item_type item_type) {
|
||||
return out << item_type_to_char(item_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* This exception is thrown when a visitor encounters an unknown item type.
|
||||
* Under usual circumstance this should not happen. If it does happen, it
|
||||
* probably means the buffer contains different kinds of objects than were
|
||||
* expected or that there is some kind of data corruption.
|
||||
*/
|
||||
struct OSMIUM_EXPORT unknown_type : public std::runtime_error {
|
||||
|
||||
unknown_type() :
|
||||
std::runtime_error{"unknown item type"} {
|
||||
}
|
||||
|
||||
}; // struct unknown_type
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_ITEM_TYPE_HPP
|
||||
@@ -0,0 +1,576 @@
|
||||
#ifndef OSMIUM_OSM_LOCATION_HPP
|
||||
#define OSMIUM_OSM_LOCATION_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
/**
|
||||
* Exception signaling an invalid location, ie a location
|
||||
* outside the -180 to 180 and -90 to 90 degree range.
|
||||
*/
|
||||
struct invalid_location : public std::range_error {
|
||||
|
||||
explicit invalid_location(const std::string& what) :
|
||||
std::range_error(what) {
|
||||
}
|
||||
|
||||
explicit invalid_location(const char* what) :
|
||||
std::range_error(what) {
|
||||
}
|
||||
|
||||
}; // struct invalid_location
|
||||
|
||||
namespace detail {
|
||||
|
||||
enum {
|
||||
coordinate_precision = 10000000
|
||||
};
|
||||
|
||||
// Convert string with a floating point number into integer suitable
|
||||
// for use as coordinate in a Location.
|
||||
inline int32_t string_to_location_coordinate(const char** data) {
|
||||
const char* str = *data;
|
||||
const char* full = str;
|
||||
|
||||
int64_t result = 0;
|
||||
int sign = 1;
|
||||
|
||||
// one more than significant digits to allow rounding
|
||||
int64_t scale = 8;
|
||||
|
||||
// paranoia check for maximum number of digits
|
||||
int max_digits = 10;
|
||||
|
||||
// optional minus sign
|
||||
if (*str == '-') {
|
||||
sign = -1;
|
||||
++str;
|
||||
}
|
||||
|
||||
if (*str != '.') {
|
||||
// there has to be at least one digit
|
||||
if (*str >= '0' && *str <= '9') {
|
||||
result = *str - '0';
|
||||
++str;
|
||||
} else {
|
||||
throw invalid_location{std::string{"wrong format for coordinate: '"} + full + "'"};
|
||||
}
|
||||
|
||||
// optional additional digits before decimal point
|
||||
while (*str >= '0' && *str <= '9' && max_digits > 0) {
|
||||
result = result * 10 + (*str - '0');
|
||||
++str;
|
||||
--max_digits;
|
||||
}
|
||||
|
||||
if (max_digits == 0) {
|
||||
throw invalid_location{std::string{"wrong format for coordinate: '"} + full + "'"};
|
||||
}
|
||||
} else {
|
||||
// need at least one digit after decimal dot if there was no
|
||||
// digit before decimal dot
|
||||
if (*(str + 1) < '0' || *(str + 1) > '9') {
|
||||
throw invalid_location{std::string{"wrong format for coordinate: '"} + full + "'"};
|
||||
}
|
||||
}
|
||||
|
||||
// optional decimal point
|
||||
if (*str == '.') {
|
||||
++str;
|
||||
|
||||
// read significant digits
|
||||
for (; scale > 0 && *str >= '0' && *str <= '9'; --scale, ++str) {
|
||||
result = result * 10 + (*str - '0');
|
||||
}
|
||||
|
||||
// ignore non-significant digits
|
||||
max_digits = 20;
|
||||
while (*str >= '0' && *str <= '9' && max_digits > 0) {
|
||||
++str;
|
||||
--max_digits;
|
||||
}
|
||||
|
||||
if (max_digits == 0) {
|
||||
throw invalid_location{std::string{"wrong format for coordinate: '"} + full + "'"};
|
||||
}
|
||||
}
|
||||
|
||||
// optional exponent in scientific notation
|
||||
if (*str == 'e' || *str == 'E') {
|
||||
++str;
|
||||
|
||||
int esign = 1;
|
||||
// optional minus sign
|
||||
if (*str == '-') {
|
||||
esign = -1;
|
||||
++str;
|
||||
}
|
||||
|
||||
int64_t eresult = 0;
|
||||
|
||||
// there has to be at least one digit in exponent
|
||||
if (*str >= '0' && *str <= '9') {
|
||||
eresult = *str - '0';
|
||||
++str;
|
||||
} else {
|
||||
throw invalid_location{std::string{"wrong format for coordinate: '"} + full + "'"};
|
||||
}
|
||||
|
||||
// optional additional digits in exponent
|
||||
max_digits = 5;
|
||||
while (*str >= '0' && *str <= '9' && max_digits > 0) {
|
||||
eresult = eresult * 10 + (*str - '0');
|
||||
++str;
|
||||
--max_digits;
|
||||
}
|
||||
|
||||
if (max_digits == 0) {
|
||||
throw invalid_location{std::string{"wrong format for coordinate: '"} + full + "'"};
|
||||
}
|
||||
|
||||
scale += eresult * esign;
|
||||
}
|
||||
|
||||
if (scale < 0) {
|
||||
for (; scale < 0 && result > 0; ++scale) {
|
||||
result /= 10;
|
||||
}
|
||||
} else {
|
||||
for (; scale > 0; --scale) {
|
||||
result *= 10;
|
||||
}
|
||||
}
|
||||
|
||||
result = (result + 5) / 10 * sign;
|
||||
|
||||
if (result > std::numeric_limits<int32_t>::max() ||
|
||||
result < std::numeric_limits<int32_t>::min()) {
|
||||
throw invalid_location{std::string{"wrong format for coordinate: '"} + full + "'"};
|
||||
}
|
||||
|
||||
*data = str;
|
||||
return static_cast<int32_t>(result);
|
||||
}
|
||||
|
||||
// Convert integer as used by location for coordinates into a string.
|
||||
template <typename T>
|
||||
inline T append_location_coordinate_to_string(T iterator, int32_t value) {
|
||||
// need to special-case this, because later `value = -value` would overflow.
|
||||
if (value == std::numeric_limits<int32_t>::min()) {
|
||||
static const char minresult[] = "-214.7483648";
|
||||
return std::copy_n(minresult, sizeof(minresult) - 1, iterator);
|
||||
}
|
||||
|
||||
// handle negative values
|
||||
if (value < 0) {
|
||||
*iterator++ = '-';
|
||||
value = -value;
|
||||
}
|
||||
|
||||
// write digits into temporary buffer
|
||||
int32_t v = value;
|
||||
char temp[10];
|
||||
char* t = temp;
|
||||
do {
|
||||
*t++ = static_cast<char>(v % 10) + '0'; // NOLINT(bugprone-narrowing-conversions, cppcoreguidelines-narrowing-conversions)
|
||||
v /= 10;
|
||||
} while (v != 0);
|
||||
|
||||
while (t - temp < 7) {
|
||||
*t++ = '0';
|
||||
}
|
||||
|
||||
// write out digits before decimal point
|
||||
if (value >= coordinate_precision) {
|
||||
if (value >= 10 * coordinate_precision) {
|
||||
if (value >= 100 * coordinate_precision) {
|
||||
*iterator++ = *--t;
|
||||
}
|
||||
*iterator++ = *--t;
|
||||
}
|
||||
*iterator++ = *--t;
|
||||
} else {
|
||||
*iterator++ = '0';
|
||||
}
|
||||
|
||||
// remove trailing zeros
|
||||
const char* tn = temp;
|
||||
while (tn < t && *tn == '0') {
|
||||
++tn;
|
||||
}
|
||||
|
||||
// decimal point
|
||||
if (t != tn) {
|
||||
*iterator++ = '.';
|
||||
while (t != tn) {
|
||||
*iterator++ = *--t;
|
||||
}
|
||||
}
|
||||
|
||||
return iterator;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* Locations define a place on earth.
|
||||
*
|
||||
* Locations are stored in 32 bit integers for the x and y
|
||||
* coordinates, respectively. This gives you an accuracy of a few
|
||||
* centimeters, good enough for OSM use. (The main OSM database
|
||||
* uses the same scheme.)
|
||||
*
|
||||
* An undefined Location can be created by calling the constructor
|
||||
* without parameters.
|
||||
*
|
||||
* Coordinates are never checked on whether they are inside bounds.
|
||||
* Call valid() to check this.
|
||||
*/
|
||||
class Location {
|
||||
|
||||
int32_t m_x; // NOLINT(modernize-use-default-member-init)
|
||||
int32_t m_y; // NOLINT(modernize-use-default-member-init)
|
||||
|
||||
constexpr static double precision() noexcept {
|
||||
return static_cast<double>(detail::coordinate_precision);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// this value is used for a coordinate to mark it as undefined
|
||||
// MSVC doesn't declare std::numeric_limits<int32_t>::max() as
|
||||
// constexpr, so we hard code this for the time being.
|
||||
// undefined_coordinate = std::numeric_limits<int32_t>::max();
|
||||
enum {
|
||||
undefined_coordinate = 2147483647
|
||||
};
|
||||
|
||||
static int32_t double_to_fix(const double c) noexcept {
|
||||
return static_cast<int32_t>(std::round(c * precision()));
|
||||
}
|
||||
|
||||
static constexpr double fix_to_double(const int32_t c) noexcept {
|
||||
return static_cast<double>(c) / precision();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create undefined Location.
|
||||
*/
|
||||
explicit constexpr Location() noexcept :
|
||||
m_x(undefined_coordinate),
|
||||
m_y(undefined_coordinate) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Location with given x and y coordinates.
|
||||
* Note that these coordinates are coordinate_precision
|
||||
* times larger than the real coordinates.
|
||||
*/
|
||||
constexpr Location(const int32_t x, const int32_t y) noexcept :
|
||||
m_x(x),
|
||||
m_y(y) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Location with given x and y coordinates.
|
||||
* Note that these coordinates are coordinate_precision
|
||||
* times larger than the real coordinates.
|
||||
*/
|
||||
constexpr Location(const int64_t x, const int64_t y) noexcept :
|
||||
m_x(static_cast<int32_t>(x)),
|
||||
m_y(static_cast<int32_t>(y)) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Location with given longitude and latitude in WGS84
|
||||
* coordinates.
|
||||
*/
|
||||
Location(const double lon, const double lat) :
|
||||
m_x(double_to_fix(lon)),
|
||||
m_y(double_to_fix(lat)) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the coordinates of this location
|
||||
* are defined.
|
||||
*
|
||||
* @deprecated Use is_defined() or is_undefined() or is_valid() which
|
||||
* have all slightly different meanings.
|
||||
*/
|
||||
explicit constexpr operator bool() const noexcept {
|
||||
return m_x != undefined_coordinate && m_y != undefined_coordinate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the coordinates are inside the
|
||||
* usual bounds (-180<=lon<=180, -90<=lat<=90).
|
||||
*
|
||||
* See also is_defined() and is_undefined().
|
||||
*/
|
||||
constexpr bool valid() const noexcept {
|
||||
return m_x >= -180 * precision()
|
||||
&& m_x <= 180 * precision()
|
||||
&& m_y >= -90 * precision()
|
||||
&& m_y <= 90 * precision();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if at least one of the coordinates is defined.
|
||||
*
|
||||
* See also is_undefined() and is_valid().
|
||||
*/
|
||||
constexpr bool is_defined() const noexcept {
|
||||
return m_x != undefined_coordinate || m_y != undefined_coordinate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if both coordinates are undefined.
|
||||
*
|
||||
* See also is_defined() and is_valid().
|
||||
*/
|
||||
constexpr bool is_undefined() const noexcept {
|
||||
return m_x == undefined_coordinate && m_y == undefined_coordinate;
|
||||
}
|
||||
|
||||
constexpr int32_t x() const noexcept {
|
||||
return m_x;
|
||||
}
|
||||
|
||||
constexpr int32_t y() const noexcept {
|
||||
return m_y;
|
||||
}
|
||||
|
||||
Location& set_x(const int32_t x) noexcept {
|
||||
m_x = x;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Location& set_y(const int32_t y) noexcept {
|
||||
m_y = y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get longitude.
|
||||
*
|
||||
* @throws invalid_location if the location is invalid
|
||||
*/
|
||||
double lon() const {
|
||||
if (!valid()) {
|
||||
throw osmium::invalid_location{"invalid location"};
|
||||
}
|
||||
return fix_to_double(m_x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get longitude without checking the validity.
|
||||
*/
|
||||
double lon_without_check() const noexcept {
|
||||
return fix_to_double(m_x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latitude.
|
||||
*
|
||||
* @throws invalid_location if the location is invalid
|
||||
*/
|
||||
double lat() const {
|
||||
if (!valid()) {
|
||||
throw osmium::invalid_location{"invalid location"};
|
||||
}
|
||||
return fix_to_double(m_y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latitude without checking the validity.
|
||||
*/
|
||||
double lat_without_check() const noexcept {
|
||||
return fix_to_double(m_y);
|
||||
}
|
||||
|
||||
Location& set_lon(double lon) noexcept {
|
||||
m_x = double_to_fix(lon);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Location& set_lat(double lat) noexcept {
|
||||
m_y = double_to_fix(lat);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Location& set_lon(const char* str) {
|
||||
const char** data = &str;
|
||||
const auto value = detail::string_to_location_coordinate(data);
|
||||
if (**data != '\0') {
|
||||
throw invalid_location{std::string{"characters after coordinate: '"} + *data + "'"};
|
||||
}
|
||||
m_x = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Location& set_lat(const char* str) {
|
||||
const char** data = &str;
|
||||
const auto value = detail::string_to_location_coordinate(data);
|
||||
if (**data != '\0') {
|
||||
throw invalid_location{std::string{"characters after coordinate: '"} + *data + "'"};
|
||||
}
|
||||
m_y = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Location& set_lon_partial(const char** str) {
|
||||
m_x = detail::string_to_location_coordinate(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Location& set_lat_partial(const char** str) {
|
||||
m_y = detail::string_to_location_coordinate(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T as_string_without_check(T iterator, const char separator = ',') const {
|
||||
iterator = detail::append_location_coordinate_to_string(iterator, x());
|
||||
*iterator++ = separator;
|
||||
return detail::append_location_coordinate_to_string(iterator, y());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T as_string(T iterator, const char separator = ',') const {
|
||||
if (!valid()) {
|
||||
throw osmium::invalid_location{"invalid location"};
|
||||
}
|
||||
return as_string_without_check(iterator, separator);
|
||||
}
|
||||
|
||||
}; // class Location
|
||||
|
||||
/**
|
||||
* Locations are equal if both coordinates are equal.
|
||||
*/
|
||||
inline constexpr bool operator==(const Location& lhs, const Location& rhs) noexcept {
|
||||
return lhs.x() == rhs.x() && lhs.y() == rhs.y();
|
||||
}
|
||||
|
||||
inline constexpr bool operator!=(const Location& lhs, const Location& rhs) noexcept {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two locations by comparing first the x and then
|
||||
* the y coordinate. If either of the locations is
|
||||
* undefined the result is undefined.
|
||||
*/
|
||||
inline constexpr bool operator<(const Location& lhs, const Location& rhs) noexcept {
|
||||
return (lhs.x() == rhs.x() && lhs.y() < rhs.y()) || lhs.x() < rhs.x();
|
||||
}
|
||||
|
||||
inline constexpr bool operator>(const Location& lhs, const Location& rhs) noexcept {
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline constexpr bool operator<=(const Location& lhs, const Location& rhs) noexcept {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
inline constexpr bool operator>=(const Location& lhs, const Location& rhs) noexcept {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a location to a stream.
|
||||
*/
|
||||
template <typename TChar, typename TTraits>
|
||||
inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const osmium::Location& location) {
|
||||
if (location) {
|
||||
out << '(';
|
||||
location.as_string(std::ostream_iterator<char>(out), ',');
|
||||
out << ')';
|
||||
} else {
|
||||
out << "(undefined,undefined)";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <int N>
|
||||
inline size_t hash(const osmium::Location& location) noexcept {
|
||||
return static_cast<uint32_t>(location.x()) ^ static_cast<uint32_t>(location.y());
|
||||
}
|
||||
|
||||
template <>
|
||||
inline size_t hash<8>(const osmium::Location& location) noexcept {
|
||||
uint64_t h = location.x();
|
||||
h <<= 32U;
|
||||
return static_cast<size_t>(h ^ static_cast<uint64_t>(location.y()));
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
namespace std {
|
||||
|
||||
// This pragma is a workaround for a bug in an old libc implementation
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wmismatched-tags"
|
||||
#endif
|
||||
template <>
|
||||
struct hash<osmium::Location> {
|
||||
using argument_type = osmium::Location;
|
||||
using result_type = size_t;
|
||||
size_t operator()(const osmium::Location& location) const noexcept {
|
||||
return osmium::detail::hash<sizeof(size_t)>(location);
|
||||
}
|
||||
};
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // OSMIUM_OSM_LOCATION_HPP
|
||||
@@ -0,0 +1,248 @@
|
||||
#ifndef OSMIUM_OSM_METADATA_OPTIONS_HPP
|
||||
#define OSMIUM_OSM_METADATA_OPTIONS_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/osm/object.hpp>
|
||||
#include <osmium/util/string.hpp>
|
||||
|
||||
#include <ostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
/**
|
||||
* Describes which metadata fields are available in an OSMObject. This is
|
||||
* most often used to describe which metadata fields are available in the
|
||||
* objects of an OSM file or which metadata information should be written
|
||||
* to an OSM file.
|
||||
*/
|
||||
class metadata_options {
|
||||
|
||||
enum options : unsigned int {
|
||||
md_none = 0x00,
|
||||
md_version = 0x01,
|
||||
md_timestamp = 0x02,
|
||||
md_changeset = 0x04,
|
||||
md_uid = 0x08,
|
||||
md_user = 0x10,
|
||||
md_all = 0x1f
|
||||
} m_options = md_all;
|
||||
|
||||
public:
|
||||
|
||||
metadata_options() noexcept = default;
|
||||
|
||||
explicit metadata_options(const std::string& attributes) {
|
||||
if (attributes.empty() || attributes == "all" || attributes == "true" || attributes == "yes") {
|
||||
return;
|
||||
}
|
||||
if (attributes == "none" || attributes == "false" || attributes == "no") {
|
||||
m_options = options::md_none;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto attrs = osmium::split_string(attributes, '+', true);
|
||||
unsigned int opts = 0;
|
||||
for (const auto& attr : attrs) {
|
||||
if (attr == "version") {
|
||||
opts |= options::md_version;
|
||||
} else if (attr == "timestamp") {
|
||||
opts |= options::md_timestamp;
|
||||
} else if (attr == "changeset") {
|
||||
opts |= options::md_changeset;
|
||||
} else if (attr == "uid") {
|
||||
opts |= options::md_uid;
|
||||
} else if (attr == "user") {
|
||||
opts |= options::md_user;
|
||||
} else {
|
||||
throw std::invalid_argument{std::string{"Unknown OSM object metadata attribute: '"} + attr + "'"};
|
||||
}
|
||||
}
|
||||
m_options = static_cast<options>(opts);
|
||||
}
|
||||
|
||||
/// At least one metadata attribute should be stored.
|
||||
bool any() const noexcept {
|
||||
return m_options != 0;
|
||||
}
|
||||
|
||||
/// All metadata attributes should be stored.
|
||||
bool all() const noexcept {
|
||||
return m_options == options::md_all;
|
||||
}
|
||||
|
||||
/// No metadata attributes should be stored.
|
||||
bool none() const noexcept {
|
||||
return m_options == 0;
|
||||
}
|
||||
|
||||
bool version() const noexcept {
|
||||
return (m_options & options::md_version) != 0;
|
||||
}
|
||||
|
||||
void set_version(bool flag) noexcept {
|
||||
if (flag) {
|
||||
m_options = static_cast<options>(m_options | options::md_version);
|
||||
} else {
|
||||
m_options = static_cast<options>(m_options & ~options::md_version);
|
||||
}
|
||||
}
|
||||
|
||||
bool timestamp() const noexcept {
|
||||
return (m_options & options::md_timestamp) != 0;
|
||||
}
|
||||
|
||||
void set_timestamp(bool flag) noexcept {
|
||||
if (flag) {
|
||||
m_options = static_cast<options>(m_options | options::md_timestamp);
|
||||
} else {
|
||||
m_options = static_cast<options>(m_options & ~options::md_timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
bool changeset() const noexcept {
|
||||
return (m_options & options::md_changeset) != 0;
|
||||
}
|
||||
|
||||
void set_changeset(bool flag) noexcept {
|
||||
if (flag) {
|
||||
m_options = static_cast<options>(m_options | options::md_changeset);
|
||||
} else {
|
||||
m_options = static_cast<options>(m_options & ~options::md_changeset);
|
||||
}
|
||||
}
|
||||
|
||||
bool uid() const noexcept {
|
||||
return (m_options & options::md_uid) != 0;
|
||||
}
|
||||
|
||||
void set_uid(bool flag) noexcept {
|
||||
if (flag) {
|
||||
m_options = static_cast<options>(m_options | options::md_uid);
|
||||
} else {
|
||||
m_options = static_cast<options>(m_options & ~options::md_uid);
|
||||
}
|
||||
}
|
||||
|
||||
bool user() const noexcept {
|
||||
return (m_options & options::md_user) != 0;
|
||||
}
|
||||
|
||||
void set_user(bool flag) noexcept {
|
||||
if (flag) {
|
||||
m_options = static_cast<options>(m_options | options::md_user);
|
||||
} else {
|
||||
m_options = static_cast<options>(m_options & ~options::md_user);
|
||||
}
|
||||
}
|
||||
|
||||
metadata_options operator&=(const metadata_options& other) {
|
||||
m_options = static_cast<options>(other.m_options & m_options);
|
||||
return *this;
|
||||
}
|
||||
|
||||
metadata_options operator|=(const metadata_options& other) {
|
||||
m_options = static_cast<options>(other.m_options | m_options);
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string to_string() const {
|
||||
std::string result;
|
||||
|
||||
if (none()) {
|
||||
result = "none";
|
||||
return result;
|
||||
}
|
||||
|
||||
if (all()) {
|
||||
result = "all";
|
||||
return result;
|
||||
}
|
||||
|
||||
if (version()) {
|
||||
result += "version+";
|
||||
}
|
||||
|
||||
if (timestamp()) {
|
||||
result += "timestamp+";
|
||||
}
|
||||
|
||||
if (changeset()) {
|
||||
result += "changeset+";
|
||||
}
|
||||
|
||||
if (uid()) {
|
||||
result += "uid+";
|
||||
}
|
||||
|
||||
if (user()) {
|
||||
result += "user+";
|
||||
}
|
||||
|
||||
// remove last '+' character
|
||||
result.pop_back();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}; // class metadata_options
|
||||
|
||||
template <typename TChar, typename TTraits>
|
||||
inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const metadata_options& options) {
|
||||
return out << options.to_string();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of metadata_options based on the availability of
|
||||
* metadata of an instance of osmium::OSMObject.
|
||||
*/
|
||||
inline osmium::metadata_options detect_available_metadata(const osmium::OSMObject& object) {
|
||||
osmium::metadata_options opts;
|
||||
|
||||
opts.set_version(object.version() > 0);
|
||||
opts.set_timestamp(object.timestamp().valid());
|
||||
opts.set_changeset(object.changeset() > 0);
|
||||
|
||||
// Objects by anonymous users don't have these attributes set. There is no way
|
||||
// to distinguish them from objects with a reduced number of metadata fields.
|
||||
opts.set_uid(object.uid() > 0);
|
||||
opts.set_user(object.user()[0] != '\0');
|
||||
|
||||
return opts;
|
||||
}
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_METADATA_OPTIONS_HPP
|
||||
@@ -0,0 +1,82 @@
|
||||
#ifndef OSMIUM_OSM_NODE_HPP
|
||||
#define OSMIUM_OSM_NODE_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/memory/item.hpp>
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
#include <osmium/osm/location.hpp>
|
||||
#include <osmium/osm/object.hpp>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
namespace builder {
|
||||
template <typename TDerived, typename T>
|
||||
class OSMObjectBuilder;
|
||||
} // namespace builder
|
||||
|
||||
class Node : public OSMObject {
|
||||
|
||||
template <typename TDerived, typename T>
|
||||
friend class osmium::builder::OSMObjectBuilder;
|
||||
|
||||
osmium::Location m_location;
|
||||
|
||||
Node() :
|
||||
OSMObject(sizeof(Node), osmium::item_type::node) {
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static constexpr osmium::item_type itemtype = osmium::item_type::node;
|
||||
|
||||
constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
|
||||
return t == itemtype;
|
||||
}
|
||||
|
||||
osmium::Location location() const noexcept {
|
||||
return m_location;
|
||||
}
|
||||
|
||||
Node& set_location(const osmium::Location& location) noexcept {
|
||||
m_location = location;
|
||||
return *this;
|
||||
}
|
||||
|
||||
}; // class Node
|
||||
|
||||
static_assert(sizeof(Node) % osmium::memory::align_bytes == 0, "Class osmium::Node has wrong size to be aligned properly!");
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_NODE_HPP
|
||||
@@ -0,0 +1,237 @@
|
||||
#ifndef OSMIUM_OSM_NODE_REF_HPP
|
||||
#define OSMIUM_OSM_NODE_REF_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/memory/item.hpp>
|
||||
#include <osmium/osm/location.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <iosfwd>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
/**
|
||||
* This reference to a node contains a node ID and a (possibly empty)
|
||||
* location.
|
||||
*/
|
||||
class NodeRef : public osmium::memory::detail::ItemHelper {
|
||||
|
||||
osmium::object_id_type m_ref;
|
||||
osmium::Location m_location;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor for NodeRef
|
||||
*
|
||||
* This is not explicit to allow implicit construction from an object
|
||||
* ID.
|
||||
*/
|
||||
constexpr NodeRef(const osmium::object_id_type ref = 0, const osmium::Location& location = Location{}) noexcept : // NOLINT(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
m_ref(ref),
|
||||
m_location(location) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get reference ID of this NodeRef.
|
||||
*/
|
||||
constexpr osmium::object_id_type ref() const noexcept {
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get absolute value of the reference ID of this NodeRef.
|
||||
*/
|
||||
osmium::unsigned_object_id_type positive_ref() const noexcept {
|
||||
return static_cast<osmium::unsigned_object_id_type>(std::abs(m_ref));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get reference to location in this NodeRef. Can be used to update it.
|
||||
*/
|
||||
osmium::Location& location() noexcept {
|
||||
return m_location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get location of this NodeRef.
|
||||
*/
|
||||
constexpr osmium::Location location() const noexcept {
|
||||
return m_location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get longitude of the location in this NodeRef.
|
||||
*
|
||||
* @throws osmium::invalid_location if the location is not set.
|
||||
*/
|
||||
double lon() const {
|
||||
return m_location.lon();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latitude of the location in this NodeRef.
|
||||
*
|
||||
* @throws osmium::invalid_location if the location is not set.
|
||||
*/
|
||||
double lat() const {
|
||||
return m_location.lat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get internal x value of the location in this NodeRef.
|
||||
*/
|
||||
constexpr int32_t x() const noexcept {
|
||||
return m_location.x();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get internal y value of the location in this NodeRef.
|
||||
*/
|
||||
constexpr int32_t y() const noexcept {
|
||||
return m_location.y();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the referenced ID.
|
||||
*
|
||||
* @returns Reference to this NodeRef for chaining calls.
|
||||
*/
|
||||
NodeRef& set_ref(const osmium::object_id_type ref) noexcept {
|
||||
m_ref = ref;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the location.
|
||||
*
|
||||
* @returns Reference to this NodeRef for chaining calls.
|
||||
*/
|
||||
NodeRef& set_location(const osmium::Location& location) noexcept {
|
||||
m_location = location;
|
||||
return *this;
|
||||
}
|
||||
|
||||
}; // class NodeRef
|
||||
|
||||
/**
|
||||
* Compare two NodeRefs. They are equal if they reference the same Node ID.
|
||||
*/
|
||||
inline constexpr bool operator==(const NodeRef& lhs, const NodeRef& rhs) noexcept {
|
||||
return lhs.ref() == rhs.ref();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two NodeRefs. They are not equal if they reference different
|
||||
* Node IDs.
|
||||
*/
|
||||
inline constexpr bool operator!=(const NodeRef& lhs, const NodeRef& rhs) noexcept {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two NodeRefs. NodeRefs are ordered according to the Node ID
|
||||
* they reference.
|
||||
*/
|
||||
inline constexpr bool operator<(const NodeRef& lhs, const NodeRef& rhs) noexcept {
|
||||
return lhs.ref() < rhs.ref();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two NodeRefs. NodeRefs are ordered according to the Node ID
|
||||
* they reference.
|
||||
*/
|
||||
inline constexpr bool operator>(const NodeRef& lhs, const NodeRef& rhs) noexcept {
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two NodeRefs. NodeRefs are ordered according to the Node ID
|
||||
* they reference.
|
||||
*/
|
||||
inline constexpr bool operator<=(const NodeRef& lhs, const NodeRef& rhs) noexcept {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two NodeRefs. NodeRefs are ordered according to the Node ID
|
||||
* they reference.
|
||||
*/
|
||||
inline constexpr bool operator>=(const NodeRef& lhs, const NodeRef& rhs) noexcept {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a NodeRef to a stream.
|
||||
*/
|
||||
template <typename TChar, typename TTraits>
|
||||
inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const osmium::NodeRef& nr) {
|
||||
return out << "<" << nr.ref() << " " << nr.location() << ">";
|
||||
}
|
||||
|
||||
/**
|
||||
* Functor to compare NodeRefs by Location instead of ID.
|
||||
*/
|
||||
struct location_equal {
|
||||
|
||||
constexpr bool operator()(const NodeRef& lhs, const NodeRef& rhs) const noexcept {
|
||||
return lhs.location() == rhs.location();
|
||||
}
|
||||
|
||||
using first_argument_type = NodeRef;
|
||||
using second_argument_type = NodeRef;
|
||||
using result_type = bool;
|
||||
|
||||
}; // struct location_equal
|
||||
|
||||
/**
|
||||
* Functor to compare NodeRefs by Location instead of ID.
|
||||
*/
|
||||
struct location_less {
|
||||
|
||||
constexpr bool operator()(const NodeRef& lhs, const NodeRef& rhs) const noexcept {
|
||||
return lhs.location() < rhs.location();
|
||||
}
|
||||
|
||||
using first_argument_type = NodeRef;
|
||||
using second_argument_type = NodeRef;
|
||||
using result_type = bool;
|
||||
|
||||
}; // struct location_less
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_NODE_REF_HPP
|
||||
@@ -0,0 +1,242 @@
|
||||
#ifndef OSMIUM_OSM_NODE_REF_LIST_HPP
|
||||
#define OSMIUM_OSM_NODE_REF_LIST_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/memory/item.hpp>
|
||||
#include <osmium/osm/box.hpp>
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
#include <osmium/osm/location.hpp>
|
||||
#include <osmium/osm/node_ref.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
/**
|
||||
* An ordered collection of NodeRef objects. Usually this is not
|
||||
* instantiated directly, but one of its subclasses are used.
|
||||
*/
|
||||
class NodeRefList : public osmium::memory::Item {
|
||||
|
||||
public:
|
||||
|
||||
using value_type = NodeRef;
|
||||
using reference = NodeRef&;
|
||||
using const_reference = const NodeRef&;
|
||||
using iterator = NodeRef*;
|
||||
using const_iterator = const NodeRef*;
|
||||
using const_reverse_iterator = std::reverse_iterator<const NodeRef*>;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using size_type = std::size_t;
|
||||
|
||||
explicit NodeRefList(osmium::item_type itemtype) noexcept :
|
||||
osmium::memory::Item(sizeof(NodeRefList), itemtype) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the collection is empty.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*/
|
||||
bool empty() const noexcept {
|
||||
return sizeof(NodeRefList) == byte_size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of NodeRefs in the collection.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*/
|
||||
size_type size() const noexcept {
|
||||
const auto size_node_refs = byte_size() - sizeof(NodeRefList);
|
||||
assert(size_node_refs % sizeof(NodeRef) == 0);
|
||||
return size_node_refs / sizeof(NodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Access specified element.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*
|
||||
* @pre @code n < size() @endcode
|
||||
*
|
||||
* @param n Get the n-th element of the collection.
|
||||
*/
|
||||
const NodeRef& operator[](size_type n) const noexcept {
|
||||
assert(n < size());
|
||||
const NodeRef* node_ref = &*(cbegin());
|
||||
return node_ref[n];
|
||||
}
|
||||
|
||||
/**
|
||||
* Access specified element.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*
|
||||
* @pre @code n < size() @endcode
|
||||
*
|
||||
* @param n Get the n-th element of the collection.
|
||||
*/
|
||||
NodeRef& operator[](size_type n) noexcept {
|
||||
assert(n < size());
|
||||
NodeRef* node_ref = &*(begin());
|
||||
return node_ref[n];
|
||||
}
|
||||
|
||||
/**
|
||||
* Access the first element.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*
|
||||
* @pre @code !empty() @endcode
|
||||
*/
|
||||
const NodeRef& front() const noexcept {
|
||||
assert(!empty());
|
||||
return operator[](0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Access the last element.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*
|
||||
* @pre @code !empty() @endcode
|
||||
*/
|
||||
const NodeRef& back() const noexcept {
|
||||
assert(!empty());
|
||||
return operator[](size() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the first and last node in the collection have the
|
||||
* same ID. The locations are not checked.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*
|
||||
* @pre @code !empty() @endcode
|
||||
*/
|
||||
bool is_closed() const noexcept {
|
||||
assert(!empty());
|
||||
return ends_have_same_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the first and last node in the collection have the
|
||||
* same ID. The locations are not checked.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*
|
||||
* @pre @code !empty() @endcode
|
||||
*/
|
||||
bool ends_have_same_id() const noexcept {
|
||||
assert(!empty());
|
||||
return front().ref() == back().ref();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the first and last node in the collection have the
|
||||
* same location. The IDs are not checked.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*
|
||||
* @pre @code !empty() @endcode
|
||||
* @pre @code front().location() && back().location() @endcode
|
||||
*/
|
||||
bool ends_have_same_location() const {
|
||||
assert(!empty());
|
||||
assert(front().location() && back().location());
|
||||
return front().location() == back().location();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the envelope of this node ref list. If the locations
|
||||
* are not set, the resulting box will be invalid.
|
||||
*
|
||||
* Complexity: Linear in the number of elements.
|
||||
*/
|
||||
osmium::Box envelope() const noexcept {
|
||||
osmium::Box box;
|
||||
for (const auto& node_ref : *this) {
|
||||
box.extend(node_ref.location());
|
||||
}
|
||||
return box;
|
||||
}
|
||||
|
||||
/// Returns an iterator to the beginning.
|
||||
iterator begin() noexcept {
|
||||
return reinterpret_cast<iterator>(data() + sizeof(NodeRefList));
|
||||
}
|
||||
|
||||
/// Returns an iterator to the end.
|
||||
iterator end() noexcept {
|
||||
return reinterpret_cast<iterator>(data() + byte_size());
|
||||
}
|
||||
|
||||
/// Returns an iterator to the beginning.
|
||||
const_iterator cbegin() const noexcept {
|
||||
return reinterpret_cast<const_iterator>(data() + sizeof(NodeRefList));
|
||||
}
|
||||
|
||||
/// Returns an iterator to the end.
|
||||
const_iterator cend() const noexcept {
|
||||
return reinterpret_cast<const_iterator>(data() + byte_size());
|
||||
}
|
||||
|
||||
/// Returns an iterator to the beginning.
|
||||
const_iterator begin() const noexcept {
|
||||
return cbegin();
|
||||
}
|
||||
|
||||
/// Returns an iterator to the end.
|
||||
const_iterator end() const noexcept {
|
||||
return cend();
|
||||
}
|
||||
|
||||
/// Returns a reverse_iterator to the beginning.
|
||||
const_reverse_iterator crbegin() const noexcept {
|
||||
return const_reverse_iterator(cend());
|
||||
}
|
||||
|
||||
/// Returns a reverse_iterator to the end.
|
||||
const_reverse_iterator crend() const noexcept {
|
||||
return const_reverse_iterator(cbegin());
|
||||
}
|
||||
|
||||
}; // class NodeRefList
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_NODE_REF_LIST_HPP
|
||||
+520
@@ -0,0 +1,520 @@
|
||||
#ifndef OSMIUM_OSM_OBJECT_HPP
|
||||
#define OSMIUM_OSM_OBJECT_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/memory/collection.hpp>
|
||||
#include <osmium/memory/item.hpp>
|
||||
#include <osmium/memory/item_iterator.hpp>
|
||||
#include <osmium/osm/entity.hpp>
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
#include <osmium/osm/location.hpp>
|
||||
#include <osmium/osm/tag.hpp>
|
||||
#include <osmium/osm/timestamp.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
#include <osmium/osm/types_from_string.hpp>
|
||||
#include <osmium/util/misc.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
namespace builder {
|
||||
template <typename TDerived, typename T>
|
||||
class OSMObjectBuilder;
|
||||
} // namespace builder
|
||||
|
||||
/**
|
||||
* OSMObject (Node, Way, Relation, or Area).
|
||||
*/
|
||||
class OSMObject : public osmium::OSMEntity {
|
||||
|
||||
template <typename TDerived, typename T>
|
||||
friend class osmium::builder::OSMObjectBuilder;
|
||||
|
||||
object_id_type m_id = 0;
|
||||
bool m_deleted : 1;
|
||||
object_version_type m_version : 31;
|
||||
osmium::Timestamp m_timestamp{};
|
||||
user_id_type m_uid = 0;
|
||||
changeset_id_type m_changeset = 0;
|
||||
|
||||
size_t sizeof_object() const noexcept {
|
||||
return sizeof(OSMObject) + (type() == item_type::node ? sizeof(osmium::Location) : 0) + sizeof(string_size_type);
|
||||
}
|
||||
|
||||
unsigned char* user_position() noexcept {
|
||||
return data() + sizeof_object() - sizeof(string_size_type);
|
||||
}
|
||||
|
||||
const unsigned char* user_position() const noexcept {
|
||||
return data() + sizeof_object() - sizeof(string_size_type);
|
||||
}
|
||||
|
||||
string_size_type user_size() const noexcept {
|
||||
return *reinterpret_cast<const string_size_type*>(user_position());
|
||||
}
|
||||
|
||||
unsigned char* subitems_position() {
|
||||
return data() + osmium::memory::padded_length(sizeof_object() + user_size());
|
||||
}
|
||||
|
||||
const unsigned char* subitems_position() const {
|
||||
return data() + osmium::memory::padded_length(sizeof_object() + user_size());
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
OSMObject(osmium::memory::item_size_type size, osmium::item_type type) :
|
||||
OSMEntity(size, type),
|
||||
m_deleted(false),
|
||||
m_version(0) {
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
|
||||
return t == osmium::item_type::node ||
|
||||
t == osmium::item_type::way ||
|
||||
t == osmium::item_type::relation ||
|
||||
t == osmium::item_type::area;
|
||||
}
|
||||
|
||||
/// Get ID of this object.
|
||||
object_id_type id() const noexcept {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
/// Get absolute value of the ID of this object.
|
||||
unsigned_object_id_type positive_id() const noexcept {
|
||||
return static_cast<unsigned_object_id_type>(std::abs(m_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ID of this object.
|
||||
*
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_id(object_id_type id) noexcept {
|
||||
m_id = id;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ID of this object.
|
||||
*
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_id(const char* id) {
|
||||
return set_id(osmium::string_to_object_id(id));
|
||||
}
|
||||
|
||||
/// Is this object marked as deleted?
|
||||
bool deleted() const noexcept {
|
||||
return m_deleted;
|
||||
}
|
||||
|
||||
/// Is this object marked visible (ie not deleted)?
|
||||
bool visible() const noexcept {
|
||||
return !deleted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this object as deleted (or not).
|
||||
*
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_deleted(bool deleted) noexcept {
|
||||
m_deleted = deleted;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this object as visible (ie not deleted) (or not).
|
||||
*
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_visible(bool visible) noexcept {
|
||||
m_deleted = !visible;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this object as visible (ie not deleted) or deleted.
|
||||
*
|
||||
* @param visible Either "true" or "false"
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_visible(const char* visible) {
|
||||
if (!std::strcmp("true", visible)) {
|
||||
set_visible(true);
|
||||
} else if (!std::strcmp("false", visible)) {
|
||||
set_visible(false);
|
||||
} else {
|
||||
throw std::invalid_argument{"Unknown value for visible attribute (allowed is 'true' or 'false')"};
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Get version of this object.
|
||||
object_version_type version() const noexcept {
|
||||
return m_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set object version.
|
||||
*
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_version(object_version_type version) noexcept {
|
||||
m_version = version;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set object version.
|
||||
*
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_version(const char* version) {
|
||||
return set_version(string_to_object_version(version));
|
||||
}
|
||||
|
||||
/// Get changeset id of this object.
|
||||
changeset_id_type changeset() const noexcept {
|
||||
return m_changeset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set changeset id of this object.
|
||||
*
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_changeset(changeset_id_type changeset) noexcept {
|
||||
m_changeset = changeset;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set changeset id of this object.
|
||||
*
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_changeset(const char* changeset) {
|
||||
return set_changeset(string_to_changeset_id(changeset));
|
||||
}
|
||||
|
||||
/// Get user id of this object.
|
||||
user_id_type uid() const noexcept {
|
||||
return m_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set user id of this object.
|
||||
*
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_uid(user_id_type uid) noexcept {
|
||||
m_uid = uid;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set user id of this object.
|
||||
* Sets uid to 0 (anonymous) if the given uid is smaller than 0.
|
||||
*
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_uid_from_signed(signed_user_id_type uid) noexcept {
|
||||
m_uid = uid < 0 ? 0 : static_cast<user_id_type>(uid);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set user id of this object.
|
||||
*
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_uid(const char* uid) {
|
||||
m_uid = string_to_uid(uid);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Is this user anonymous?
|
||||
bool user_is_anonymous() const noexcept {
|
||||
return m_uid == 0;
|
||||
}
|
||||
|
||||
/// Get timestamp when this object last changed.
|
||||
osmium::Timestamp timestamp() const noexcept {
|
||||
return m_timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the timestamp when this object last changed.
|
||||
*
|
||||
* @param timestamp Timestamp
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_timestamp(const osmium::Timestamp& timestamp) noexcept {
|
||||
m_timestamp = timestamp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the timestamp when this object last changed.
|
||||
*
|
||||
* @param timestamp Timestamp in ISO format.
|
||||
* @returns Reference to object to make calls chainable.
|
||||
* @throws std::invalid_argment if the timestamp isn't a correctly ISO
|
||||
* formatted string with the Z timezone.
|
||||
*
|
||||
* @pre @code timestamp != nullptr @endcode
|
||||
*/
|
||||
OSMObject& set_timestamp(const char* timestamp) {
|
||||
assert(timestamp);
|
||||
const char** str = ×tamp;
|
||||
m_timestamp = detail::parse_timestamp(str);
|
||||
if (**str != '\0') {
|
||||
throw std::invalid_argument{"can not parse timestamp: garbage after timestamp"};
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Get user name for this object.
|
||||
const char* user() const noexcept {
|
||||
return reinterpret_cast<const char*>(data() + sizeof_object());
|
||||
}
|
||||
|
||||
/// Clear user name.
|
||||
void clear_user() noexcept {
|
||||
std::memset(data() + sizeof_object(), 0, user_size());
|
||||
}
|
||||
|
||||
/// Get the list of tags for this object.
|
||||
const TagList& tags() const {
|
||||
return osmium::detail::subitem_of_type<const TagList>(cbegin(), cend());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tag value by key.
|
||||
*
|
||||
* Convenience function that will forward to same function on TagList
|
||||
* object.
|
||||
*/
|
||||
const char* get_value_by_key(const char* key, const char* default_value = nullptr) const noexcept {
|
||||
return tags().get_value_by_key(key, default_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set named attribute.
|
||||
*
|
||||
* @param attr Name of the attribute (must be one of "id", "version", "changeset", "timestamp", "uid", "visible")
|
||||
* @param value Value of the attribute
|
||||
* @returns Reference to object to make calls chainable.
|
||||
*/
|
||||
OSMObject& set_attribute(const char* attr, const char* value) {
|
||||
if (!std::strcmp(attr, "id")) {
|
||||
set_id(value);
|
||||
} else if (!std::strcmp(attr, "version")) {
|
||||
set_version(value);
|
||||
} else if (!std::strcmp(attr, "changeset")) {
|
||||
set_changeset(value);
|
||||
} else if (!std::strcmp(attr, "timestamp")) {
|
||||
set_timestamp(value);
|
||||
} else if (!std::strcmp(attr, "uid")) {
|
||||
set_uid(value);
|
||||
} else if (!std::strcmp(attr, "visible")) {
|
||||
set_visible(value);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
using iterator = osmium::memory::CollectionIterator<Item>;
|
||||
using const_iterator = osmium::memory::CollectionIterator<const Item>;
|
||||
|
||||
/**
|
||||
* Remove all tags from this object.
|
||||
*
|
||||
* (This will not change the size of the object, the tags are simply
|
||||
* marked as removed.)
|
||||
*/
|
||||
void remove_tags() noexcept {
|
||||
for (auto& subitem : *this) {
|
||||
if (subitem.type() == osmium::item_type::tag_list) {
|
||||
subitem.set_removed(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iterator begin() {
|
||||
return iterator(subitems_position());
|
||||
}
|
||||
|
||||
iterator end() {
|
||||
return iterator(next());
|
||||
}
|
||||
|
||||
const_iterator cbegin() const {
|
||||
return const_iterator(subitems_position());
|
||||
}
|
||||
|
||||
const_iterator cend() const {
|
||||
return const_iterator(next());
|
||||
}
|
||||
|
||||
const_iterator begin() const {
|
||||
return cbegin();
|
||||
}
|
||||
|
||||
const_iterator end() const {
|
||||
return cend();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a range of subitems of a specific type.
|
||||
*
|
||||
* @tparam The type (must be derived from osmium::memory::Item).
|
||||
*/
|
||||
template <typename T>
|
||||
osmium::memory::ItemIteratorRange<T> subitems() {
|
||||
static_assert(std::is_base_of<osmium::memory::Item, T>::value, "T must be derived from osmium::memory::Item");
|
||||
return osmium::memory::ItemIteratorRange<T>{subitems_position(), next()};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a range of subitems of a specific type.
|
||||
*
|
||||
* @tparam The type (must be derived from osmium::memory::Item).
|
||||
*/
|
||||
template <typename T>
|
||||
osmium::memory::ItemIteratorRange<const T> subitems() const {
|
||||
static_assert(std::is_base_of<osmium::memory::Item, T>::value, "T must be derived from osmium::memory::Item");
|
||||
return osmium::memory::ItemIteratorRange<const T>{subitems_position(), next()};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using t_iterator = osmium::memory::ItemIterator<T>;
|
||||
|
||||
template <typename T>
|
||||
using t_const_iterator = osmium::memory::ItemIterator<const T>;
|
||||
|
||||
template <typename T>
|
||||
t_iterator<T> begin() {
|
||||
return t_iterator<T>(subitems_position(), next());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
t_iterator<T> end() {
|
||||
return t_iterator<T>(next(), next());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
t_const_iterator<T> cbegin() const {
|
||||
return t_const_iterator<T>(subitems_position(), next());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
t_const_iterator<T> cend() const {
|
||||
return t_const_iterator<T>(next(), next());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
t_const_iterator<T> begin() const {
|
||||
return cbegin<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
t_const_iterator<T> end() const {
|
||||
return cend<T>();
|
||||
}
|
||||
|
||||
}; // class OSMObject
|
||||
|
||||
static_assert(sizeof(OSMObject) % osmium::memory::align_bytes == 0, "Class osmium::OSMObject has wrong size to be aligned properly!");
|
||||
|
||||
/**
|
||||
* OSMObjects are equal if their type, id, and version are equal.
|
||||
*/
|
||||
inline bool operator==(const OSMObject& lhs, const OSMObject& rhs) noexcept {
|
||||
return lhs.type() == rhs.type() &&
|
||||
lhs.id() == rhs.id() &&
|
||||
lhs.version() == rhs.version();
|
||||
}
|
||||
|
||||
inline bool operator!=(const OSMObject& lhs, const OSMObject& rhs) noexcept {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* OSMObjects can be ordered by type, id, version, and timestamp. Usually
|
||||
* ordering by timestamp is not necessary as there shouldn't be two
|
||||
* objects with the same type, id, and version. But this can happen when
|
||||
* creating diff files from extracts, so we take the timestamp into
|
||||
* account here.
|
||||
*
|
||||
* Note that we use the absolute value of the id for a better ordering
|
||||
* of objects with negative id. All the negative IDs come first, then the
|
||||
* positive IDs. IDs are ordered by their absolute values. (This is the
|
||||
* same ordering JOSM uses.)
|
||||
*
|
||||
* See object_order_type_id_reverse_version if you need a different
|
||||
* ordering.
|
||||
*/
|
||||
inline bool operator<(const OSMObject& lhs, const OSMObject& rhs) noexcept {
|
||||
return const_tie(lhs.type(), lhs.id() > 0, lhs.positive_id(), lhs.version(),
|
||||
((lhs.timestamp().valid() && rhs.timestamp().valid()) ? lhs.timestamp() : osmium::Timestamp())) <
|
||||
const_tie(rhs.type(), rhs.id() > 0, rhs.positive_id(), rhs.version(),
|
||||
((lhs.timestamp().valid() && rhs.timestamp().valid()) ? rhs.timestamp() : osmium::Timestamp()));
|
||||
}
|
||||
|
||||
inline bool operator>(const OSMObject& lhs, const OSMObject& rhs) noexcept {
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator<=(const OSMObject& lhs, const OSMObject& rhs) noexcept {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const OSMObject& lhs, const OSMObject& rhs) noexcept {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_OBJECT_HPP
|
||||
@@ -0,0 +1,178 @@
|
||||
#ifndef OSMIUM_OSM_OBJECT_COMPARISONS_HPP
|
||||
#define OSMIUM_OSM_OBJECT_COMPARISONS_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/osm/object.hpp>
|
||||
#include <osmium/osm/timestamp.hpp>
|
||||
#include <osmium/util/misc.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
/**
|
||||
* Function object class for comparing OSM objects for equality by type,
|
||||
* ID, and version.
|
||||
*/
|
||||
struct object_equal_type_id_version {
|
||||
|
||||
bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
/// @pre lhs and rhs must not be nullptr
|
||||
bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
|
||||
assert(lhs && rhs);
|
||||
return *lhs == *rhs;
|
||||
}
|
||||
|
||||
}; // struct object_equal_type_id_version
|
||||
|
||||
/**
|
||||
* Function object class for comparing OSM objects for equality by type
|
||||
* and ID, ignoring the version.
|
||||
*/
|
||||
struct object_equal_type_id {
|
||||
|
||||
bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
|
||||
return lhs.type() == rhs.type() &&
|
||||
lhs.id() == rhs.id();
|
||||
}
|
||||
|
||||
/// @pre lhs and rhs must not be nullptr
|
||||
bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
|
||||
assert(lhs && rhs);
|
||||
return operator()(*lhs, *rhs);
|
||||
}
|
||||
|
||||
}; // struct object_equal_type_id
|
||||
|
||||
/**
|
||||
* Compare two objects IDs. Order is as follows: 0 first, then negative
|
||||
* IDs, then positive IDs, both ordered by their absolute values.
|
||||
*/
|
||||
struct id_order {
|
||||
|
||||
bool operator()(const object_id_type lhs, const object_id_type rhs) const noexcept {
|
||||
if (rhs == 0) {
|
||||
return false;
|
||||
}
|
||||
if (lhs == 0) {
|
||||
return true;
|
||||
}
|
||||
if (lhs < 0) {
|
||||
if (rhs > 0) {
|
||||
return true;
|
||||
}
|
||||
// rhs < 0
|
||||
return lhs > rhs;
|
||||
}
|
||||
// lhs > 0
|
||||
if (rhs < 0) {
|
||||
return false;
|
||||
}
|
||||
return lhs < rhs;
|
||||
}
|
||||
|
||||
}; // struct id_order
|
||||
|
||||
/**
|
||||
* Function object class for ordering OSM objects by type, id, version,
|
||||
* and timestamp.
|
||||
*/
|
||||
struct object_order_type_id_version {
|
||||
|
||||
bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
|
||||
return lhs < rhs;
|
||||
}
|
||||
|
||||
/// @pre lhs and rhs must not be nullptr
|
||||
bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
|
||||
assert(lhs && rhs);
|
||||
return *lhs < *rhs;
|
||||
}
|
||||
|
||||
}; // struct object_order_type_id_version
|
||||
|
||||
/**
|
||||
* Function object class for ordering OSM objects by type, id, and version.
|
||||
*
|
||||
* The naming is a bit awkward here, but necessary to keep backwards
|
||||
* compatibility with object_order_type_id_version.
|
||||
*/
|
||||
struct object_order_type_id_version_without_timestamp {
|
||||
|
||||
bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
|
||||
return const_tie(lhs.type(), lhs.id() > 0, lhs.positive_id(), lhs.version()) <
|
||||
const_tie(rhs.type(), rhs.id() > 0, rhs.positive_id(), rhs.version());
|
||||
}
|
||||
|
||||
/// @pre lhs and rhs must not be nullptr
|
||||
bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
|
||||
assert(lhs && rhs);
|
||||
return operator()(*lhs, *rhs);
|
||||
}
|
||||
|
||||
}; // struct object_order_type_id_version_without_timestamp
|
||||
|
||||
/**
|
||||
* Function object class for ordering OSM objects by type, ID, and
|
||||
* reverse version, timestamp. So objects are ordered by type and ID
|
||||
* (negative IDs first, then positive IDs, both in the order of their
|
||||
* absolute values), but later versions of an object are ordered before
|
||||
* earlier versions of the same object. This is useful when the last
|
||||
* version of an object needs to be used.
|
||||
*/
|
||||
struct object_order_type_id_reverse_version {
|
||||
|
||||
bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
|
||||
return const_tie(lhs.type(), lhs.id() > 0, lhs.positive_id(), rhs.version(),
|
||||
((lhs.timestamp().valid() && rhs.timestamp().valid()) ? rhs.timestamp() : osmium::Timestamp())) <
|
||||
const_tie(rhs.type(), rhs.id() > 0, rhs.positive_id(), lhs.version(),
|
||||
((lhs.timestamp().valid() && rhs.timestamp().valid()) ? lhs.timestamp() : osmium::Timestamp()));
|
||||
}
|
||||
|
||||
/// @pre lhs and rhs must not be nullptr
|
||||
bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
|
||||
assert(lhs && rhs);
|
||||
return operator()(*lhs, *rhs);
|
||||
}
|
||||
|
||||
}; // struct object_order_type_id_reverse_version
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_OBJECT_COMPARISONS_HPP
|
||||
@@ -0,0 +1,200 @@
|
||||
#ifndef OSMIUM_OSM_RELATION_HPP
|
||||
#define OSMIUM_OSM_RELATION_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/memory/collection.hpp> // IWYU pragma: keep
|
||||
#include <osmium/memory/item.hpp>
|
||||
#include <osmium/osm/entity.hpp>
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
#include <osmium/osm/object.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <iterator>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
namespace builder {
|
||||
template <typename TDerived, typename T>
|
||||
class OSMObjectBuilder;
|
||||
|
||||
class RelationMemberListBuilder;
|
||||
} // namespace builder
|
||||
|
||||
class RelationMember : public osmium::memory::detail::ItemHelper {
|
||||
|
||||
friend class osmium::builder::RelationMemberListBuilder;
|
||||
|
||||
object_id_type m_ref;
|
||||
item_type m_type;
|
||||
uint16_t m_flags;
|
||||
string_size_type m_role_size = 0;
|
||||
|
||||
unsigned char* endpos() {
|
||||
return data() + osmium::memory::padded_length(sizeof(RelationMember) + m_role_size);
|
||||
}
|
||||
|
||||
const unsigned char* endpos() const {
|
||||
return data() + osmium::memory::padded_length(sizeof(RelationMember) + m_role_size);
|
||||
}
|
||||
|
||||
template <typename TMember>
|
||||
friend class osmium::memory::CollectionIterator;
|
||||
|
||||
unsigned char* next() {
|
||||
if (full_member()) {
|
||||
return endpos() + reinterpret_cast<osmium::memory::Item*>(endpos())->byte_size();
|
||||
}
|
||||
return endpos();
|
||||
}
|
||||
|
||||
const unsigned char* next() const {
|
||||
if (full_member()) {
|
||||
return endpos() + reinterpret_cast<const osmium::memory::Item*>(endpos())->byte_size();
|
||||
}
|
||||
return endpos();
|
||||
}
|
||||
|
||||
void set_role_size(string_size_type size) noexcept {
|
||||
m_role_size = size;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static constexpr item_type collection_type = item_type::relation_member_list;
|
||||
|
||||
explicit RelationMember(const object_id_type ref = 0, const item_type type = item_type(), const bool full = false) noexcept :
|
||||
m_ref(ref),
|
||||
m_type(type),
|
||||
m_flags(full ? 1 : 0) {
|
||||
}
|
||||
|
||||
RelationMember(const RelationMember&) = delete;
|
||||
RelationMember& operator=(const RelationMember&) = delete;
|
||||
|
||||
RelationMember(RelationMember&&) = delete;
|
||||
RelationMember& operator=(RelationMember&&) = delete;
|
||||
|
||||
~RelationMember() noexcept = default;
|
||||
|
||||
object_id_type ref() const noexcept {
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
unsigned_object_id_type positive_ref() const noexcept {
|
||||
return static_cast<unsigned_object_id_type>(std::abs(m_ref));
|
||||
}
|
||||
|
||||
RelationMember& set_ref(const osmium::object_id_type ref) noexcept {
|
||||
m_ref = ref;
|
||||
return *this;
|
||||
}
|
||||
|
||||
item_type type() const noexcept {
|
||||
return m_type;
|
||||
}
|
||||
|
||||
bool full_member() const noexcept {
|
||||
return m_flags == 1;
|
||||
}
|
||||
|
||||
const char* role() const noexcept {
|
||||
return reinterpret_cast<const char*>(data() + sizeof(RelationMember));
|
||||
}
|
||||
|
||||
OSMObject& get_object() {
|
||||
return *reinterpret_cast<OSMObject*>(endpos());
|
||||
}
|
||||
|
||||
const OSMObject& get_object() const {
|
||||
return *reinterpret_cast<const OSMObject*>(endpos());
|
||||
}
|
||||
|
||||
}; // class RelationMember
|
||||
|
||||
class RelationMemberList : public osmium::memory::Collection<RelationMember, osmium::item_type::relation_member_list> {
|
||||
|
||||
public:
|
||||
|
||||
constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
|
||||
return t == osmium::item_type::relation_member_list ||
|
||||
t == osmium::item_type::relation_member_list_with_full_members;
|
||||
}
|
||||
|
||||
RelationMemberList() noexcept = default;
|
||||
|
||||
}; // class RelationMemberList
|
||||
|
||||
static_assert(sizeof(RelationMemberList) % osmium::memory::align_bytes == 0, "Class osmium::RelationMemberList has wrong size to be aligned properly!");
|
||||
|
||||
class Relation : public OSMObject {
|
||||
|
||||
template <typename TDerived, typename T>
|
||||
friend class osmium::builder::OSMObjectBuilder;
|
||||
|
||||
Relation() noexcept :
|
||||
OSMObject(sizeof(Relation), osmium::item_type::relation) {
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static constexpr osmium::item_type itemtype = osmium::item_type::relation;
|
||||
|
||||
constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
|
||||
return t == itemtype;
|
||||
}
|
||||
|
||||
/// Get a reference to the member list.
|
||||
RelationMemberList& members() {
|
||||
return osmium::detail::subitem_of_type<RelationMemberList>(begin(), end());
|
||||
}
|
||||
|
||||
/// Get a const reference to the member list.
|
||||
const RelationMemberList& members() const {
|
||||
return osmium::detail::subitem_of_type<const RelationMemberList>(cbegin(), cend());
|
||||
}
|
||||
|
||||
/// Get a const reference to the member list.
|
||||
const RelationMemberList& cmembers() const {
|
||||
return osmium::detail::subitem_of_type<const RelationMemberList>(cbegin(), cend());
|
||||
}
|
||||
|
||||
}; // class Relation
|
||||
|
||||
static_assert(sizeof(Relation) % osmium::memory::align_bytes == 0, "Class osmium::Relation has wrong size to be aligned properly!");
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_RELATION_HPP
|
||||
@@ -0,0 +1,96 @@
|
||||
#ifndef OSMIUM_OSM_SEGMENT_HPP
|
||||
#define OSMIUM_OSM_SEGMENT_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/osm/location.hpp>
|
||||
|
||||
#include <iosfwd>
|
||||
#include <utility>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
/**
|
||||
* A Segment is the directed connection between two Locations.
|
||||
*/
|
||||
class Segment {
|
||||
|
||||
osmium::Location m_first;
|
||||
osmium::Location m_second;
|
||||
|
||||
public:
|
||||
|
||||
explicit constexpr Segment(const osmium::Location& location1, const osmium::Location& location2) noexcept :
|
||||
m_first(location1),
|
||||
m_second(location2) {
|
||||
}
|
||||
|
||||
/// Return first Location of Segment.
|
||||
constexpr osmium::Location first() const noexcept {
|
||||
return m_first;
|
||||
}
|
||||
|
||||
/// Return second Location of Segment.
|
||||
constexpr osmium::Location second() const noexcept {
|
||||
return m_second;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void swap_locations() {
|
||||
using std::swap;
|
||||
swap(m_first, m_second);
|
||||
}
|
||||
|
||||
}; // class Segment
|
||||
|
||||
/// Segments are equal if both their locations are equal
|
||||
inline constexpr bool operator==(const Segment& lhs, const Segment& rhs) noexcept {
|
||||
return lhs.first() == rhs.first() && lhs.second() == rhs.second();
|
||||
}
|
||||
|
||||
inline constexpr bool operator!=(const Segment& lhs, const Segment& rhs) noexcept {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output Segment to a stream.
|
||||
*/
|
||||
template <typename TChar, typename TTraits>
|
||||
inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const osmium::Segment& segment) {
|
||||
return out << segment.first() << "->" << segment.second();
|
||||
}
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_SEGMENT_HPP
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
#ifndef OSMIUM_OSM_TAG_HPP
|
||||
#define OSMIUM_OSM_TAG_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/memory/collection.hpp>
|
||||
#include <osmium/memory/item.hpp>
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <iosfwd>
|
||||
#include <iterator>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
class Tag : public osmium::memory::detail::ItemHelper {
|
||||
|
||||
template <typename TMember>
|
||||
friend class osmium::memory::CollectionIterator;
|
||||
|
||||
static unsigned char* after_null(unsigned char* ptr) noexcept {
|
||||
return reinterpret_cast<unsigned char*>(std::strchr(reinterpret_cast<char*>(ptr), 0) + 1);
|
||||
}
|
||||
|
||||
static const unsigned char* after_null(const unsigned char* ptr) noexcept {
|
||||
return reinterpret_cast<const unsigned char*>(std::strchr(reinterpret_cast<const char*>(ptr), 0) + 1);
|
||||
}
|
||||
|
||||
unsigned char* next() noexcept {
|
||||
return after_null(after_null(data()));
|
||||
}
|
||||
|
||||
const unsigned char* next() const noexcept {
|
||||
return after_null(after_null(data()));
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Tag(const Tag&) = delete;
|
||||
Tag& operator=(const Tag&) = delete;
|
||||
|
||||
Tag(Tag&&) = delete;
|
||||
Tag& operator=(Tag&&) = delete;
|
||||
|
||||
~Tag() noexcept = default;
|
||||
|
||||
static constexpr item_type collection_type = item_type::tag_list;
|
||||
|
||||
/**
|
||||
* Get a pointer to the C string containing the tag key.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*/
|
||||
const char* key() const noexcept {
|
||||
return reinterpret_cast<const char*>(data());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pointer to the C string containing the tag value.
|
||||
*
|
||||
* Complexity: Linear on the number of characters in the key!
|
||||
*/
|
||||
const char* value() const noexcept {
|
||||
return reinterpret_cast<const char*>(after_null(data()));
|
||||
}
|
||||
|
||||
}; // class Tag
|
||||
|
||||
inline bool operator==(const Tag& lhs, const Tag& rhs) noexcept {
|
||||
return !std::strcmp(lhs.key(), rhs.key()) &&
|
||||
!std::strcmp(lhs.value(), rhs.value());
|
||||
}
|
||||
|
||||
inline bool operator<(const Tag& lhs, const Tag& rhs) noexcept {
|
||||
const auto c = std::strcmp(lhs.key(), rhs.key());
|
||||
return (c == 0 ? std::strcmp(lhs.value(), rhs.value()) : c) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a Tag to a stream.
|
||||
*/
|
||||
template <typename TChar, typename TTraits>
|
||||
inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const Tag& tag) {
|
||||
return out << tag.key() << '=' << tag.value();
|
||||
}
|
||||
|
||||
class TagList : public osmium::memory::Collection<Tag, osmium::item_type::tag_list> {
|
||||
|
||||
const_iterator find_key(const char* key) const noexcept {
|
||||
return std::find_if(cbegin(), cend(), [key](const Tag& tag) {
|
||||
return !std::strcmp(tag.key(), key);
|
||||
});
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
TagList() noexcept = default;
|
||||
|
||||
/**
|
||||
* Get tag value for the given tag key. If the key is not set, returns
|
||||
* the default_value.
|
||||
*
|
||||
* @pre @code key != nullptr @endcode
|
||||
*/
|
||||
const char* get_value_by_key(const char* key, const char* default_value = nullptr) const noexcept {
|
||||
assert(key);
|
||||
const auto result = find_key(key);
|
||||
return result == cend() ? default_value : result->value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tag value for the given tag key. If the key is not set, returns
|
||||
* nullptr.
|
||||
*
|
||||
* @pre @code key != nullptr @endcode
|
||||
*/
|
||||
const char* operator[](const char* key) const noexcept {
|
||||
return get_value_by_key(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the tag with the given key is in the tag list.
|
||||
*
|
||||
* @pre @code key != nullptr @endcode
|
||||
*/
|
||||
bool has_key(const char* key) const noexcept {
|
||||
assert(key);
|
||||
return find_key(key) != cend();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the tag with the given key and value is in the
|
||||
* tag list.
|
||||
*
|
||||
* @pre @code key != nullptr && value != nullptr @endcode
|
||||
*/
|
||||
bool has_tag(const char* key, const char* value) const noexcept {
|
||||
assert(key);
|
||||
assert(value);
|
||||
const auto result = find_key(key);
|
||||
return result != cend() && !std::strcmp(result->value(), value);
|
||||
}
|
||||
|
||||
}; // class TagList
|
||||
|
||||
static_assert(sizeof(TagList) % osmium::memory::align_bytes == 0, "Class osmium::TagList has wrong size to be aligned properly!");
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_TAG_HPP
|
||||
@@ -0,0 +1,374 @@
|
||||
#ifndef OSMIUM_OSM_TIMESTAMP_HPP
|
||||
#define OSMIUM_OSM_TIMESTAMP_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/util/minmax.hpp> // IWYU pragma: keep
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <iosfwd>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
namespace detail {
|
||||
|
||||
inline void add_2digit_int_to_string(int value, std::string& out) {
|
||||
assert(value >= 0 && value <= 99);
|
||||
if (value > 9) {
|
||||
const int dec = value / 10;
|
||||
out += static_cast<char>('0' + dec);
|
||||
value -= dec * 10;
|
||||
} else {
|
||||
out += '0';
|
||||
}
|
||||
out += static_cast<char>('0' + value);
|
||||
}
|
||||
|
||||
inline void add_4digit_int_to_string(int value, std::string& out) {
|
||||
assert(value >= 1000 && value <= 9999);
|
||||
|
||||
const int dec1 = value / 1000;
|
||||
out += static_cast<char>('0' + dec1);
|
||||
value -= dec1 * 1000;
|
||||
|
||||
const int dec2 = value / 100;
|
||||
out += static_cast<char>('0' + dec2);
|
||||
value -= dec2 * 100;
|
||||
|
||||
const int dec3 = value / 10;
|
||||
out += static_cast<char>('0' + dec3);
|
||||
value -= dec3 * 10;
|
||||
|
||||
out += static_cast<char>('0' + value);
|
||||
}
|
||||
|
||||
inline bool fractional_seconds(const char** s) noexcept {
|
||||
const char* str = *s;
|
||||
|
||||
if (*str != '.' && *str != ',') {
|
||||
return false;
|
||||
}
|
||||
|
||||
++str;
|
||||
if (*str < '0' || *str > '9') {
|
||||
return false;
|
||||
}
|
||||
|
||||
do {
|
||||
++str;
|
||||
} while (*str >= '0' && *str <= '9');
|
||||
|
||||
*s = str;
|
||||
return *str == 'Z';
|
||||
}
|
||||
|
||||
inline std::time_t parse_timestamp(const char** s) {
|
||||
const char* str = *s;
|
||||
*s += 19;
|
||||
|
||||
static const std::array<int, 12> mon_lengths = {{
|
||||
31, 29, 31, 30, 31, 30,
|
||||
31, 31, 30, 31, 30, 31
|
||||
}};
|
||||
|
||||
if (str[ 0] >= '0' && str[ 0] <= '9' &&
|
||||
str[ 1] >= '0' && str[ 1] <= '9' &&
|
||||
str[ 2] >= '0' && str[ 2] <= '9' &&
|
||||
str[ 3] >= '0' && str[ 3] <= '9' &&
|
||||
str[ 4] == '-' &&
|
||||
str[ 5] >= '0' && str[ 5] <= '9' &&
|
||||
str[ 6] >= '0' && str[ 6] <= '9' &&
|
||||
str[ 7] == '-' &&
|
||||
str[ 8] >= '0' && str[ 8] <= '9' &&
|
||||
str[ 9] >= '0' && str[ 9] <= '9' &&
|
||||
str[10] == 'T' &&
|
||||
str[11] >= '0' && str[11] <= '9' &&
|
||||
str[12] >= '0' && str[12] <= '9' &&
|
||||
str[13] == ':' &&
|
||||
str[14] >= '0' && str[14] <= '9' &&
|
||||
str[15] >= '0' && str[15] <= '9' &&
|
||||
str[16] == ':' &&
|
||||
str[17] >= '0' && str[17] <= '9' &&
|
||||
str[18] >= '0' && str[18] <= '9' &&
|
||||
(str[19] == 'Z' || fractional_seconds(s))) {
|
||||
++(*s);
|
||||
std::tm tm; // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
||||
tm.tm_year = (str[ 0] - '0') * 1000 +
|
||||
(str[ 1] - '0') * 100 +
|
||||
(str[ 2] - '0') * 10 +
|
||||
(str[ 3] - '0') - 1900;
|
||||
tm.tm_mon = (str[ 5] - '0') * 10 + (str[ 6] - '0') - 1;
|
||||
tm.tm_mday = (str[ 8] - '0') * 10 + (str[ 9] - '0');
|
||||
tm.tm_hour = (str[11] - '0') * 10 + (str[12] - '0');
|
||||
tm.tm_min = (str[14] - '0') * 10 + (str[15] - '0');
|
||||
tm.tm_sec = (str[17] - '0') * 10 + (str[18] - '0');
|
||||
tm.tm_wday = 0;
|
||||
tm.tm_yday = 0;
|
||||
tm.tm_isdst = 0;
|
||||
if (tm.tm_year >= 0 &&
|
||||
tm.tm_mon >= 0 && tm.tm_mon <= 11 &&
|
||||
tm.tm_mday >= 1 && tm.tm_mday <= mon_lengths[tm.tm_mon] &&
|
||||
tm.tm_hour >= 0 && tm.tm_hour <= 23 &&
|
||||
tm.tm_min >= 0 && tm.tm_min <= 59 &&
|
||||
tm.tm_sec >= 0 && tm.tm_sec <= 60) {
|
||||
#ifndef _WIN32
|
||||
return timegm(&tm);
|
||||
#else
|
||||
return _mkgmtime(&tm);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
throw std::invalid_argument{std::string{"can not parse timestamp: '"} + str + "'"};
|
||||
}
|
||||
|
||||
inline std::time_t parse_timestamp(const char* s) {
|
||||
const char** str = &s;
|
||||
return parse_timestamp(str);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* A timestamp. Internal representation is an unsigned 32bit integer
|
||||
* holding seconds since epoch (1970-01-01T00:00:00Z), so this will
|
||||
* overflow in 2106. We can use an unsigned integer here, because the
|
||||
* OpenStreetMap project was started long after 1970, so there will
|
||||
* never be dates before that.
|
||||
*/
|
||||
class Timestamp {
|
||||
|
||||
uint32_t m_timestamp = 0;
|
||||
|
||||
void to_iso_str(std::string& s) const {
|
||||
std::tm tm; // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
|
||||
const std::time_t sse = seconds_since_epoch();
|
||||
#ifndef NDEBUG
|
||||
auto result =
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
gmtime_r(&sse, &tm);
|
||||
assert(result != nullptr);
|
||||
#else
|
||||
gmtime_s(&tm, &sse);
|
||||
assert(result == 0);
|
||||
#endif
|
||||
|
||||
detail::add_4digit_int_to_string(tm.tm_year + 1900, s);
|
||||
s += '-';
|
||||
detail::add_2digit_int_to_string(tm.tm_mon + 1, s);
|
||||
s += '-';
|
||||
detail::add_2digit_int_to_string(tm.tm_mday, s);
|
||||
s += 'T';
|
||||
detail::add_2digit_int_to_string(tm.tm_hour, s);
|
||||
s += ':';
|
||||
detail::add_2digit_int_to_string(tm.tm_min, s);
|
||||
s += ':';
|
||||
detail::add_2digit_int_to_string(tm.tm_sec, s);
|
||||
s += 'Z';
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default construct an invalid Timestamp.
|
||||
*/
|
||||
constexpr Timestamp() noexcept = default;
|
||||
|
||||
/**
|
||||
* Construct a Timestamp from any integer type containing the seconds
|
||||
* since the epoch. This will not check for overruns, you have to
|
||||
* make sure the value fits into a uint32_t which is used internally
|
||||
* in the Timestamp.
|
||||
*
|
||||
* The constructor is not declared "explicit" so that conversions
|
||||
* like @code node.set_timestamp(123); @endcode work.
|
||||
*/
|
||||
template <typename T, typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
|
||||
constexpr Timestamp(T timestamp) noexcept : // NOLINT(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
m_timestamp(static_cast<uint32_t>(timestamp)) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct timestamp from ISO date/time string in the format
|
||||
* "yyyy-mm-ddThh:mm:ssZ".
|
||||
*
|
||||
* @throws std::invalid_argument if the timestamp can not be parsed.
|
||||
*/
|
||||
explicit Timestamp(const char* timestamp) :
|
||||
m_timestamp(static_cast<uint32_t>(detail::parse_timestamp(timestamp))) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct timestamp from ISO date/time string in the format
|
||||
* "yyyy-mm-ddThh:mm:ssZ".
|
||||
*
|
||||
* @throws std::invalid_argument if the timestamp can not be parsed.
|
||||
*/
|
||||
explicit Timestamp(const std::string& timestamp) :
|
||||
Timestamp(timestamp.c_str()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this timestamp is valid (ie set to something other
|
||||
* than 0).
|
||||
*/
|
||||
bool valid() const noexcept {
|
||||
return m_timestamp != 0;
|
||||
}
|
||||
|
||||
/// Explicit conversion into bool.
|
||||
explicit constexpr operator bool() const noexcept {
|
||||
return m_timestamp != 0;
|
||||
}
|
||||
|
||||
/// Explicit conversion into time_t.
|
||||
constexpr std::time_t seconds_since_epoch() const noexcept {
|
||||
return static_cast<std::time_t>(m_timestamp);
|
||||
}
|
||||
|
||||
/// Explicit conversion into uint32_t.
|
||||
explicit constexpr operator uint32_t() const noexcept {
|
||||
return m_timestamp;
|
||||
}
|
||||
|
||||
/// Explicit conversion into uint64_t.
|
||||
explicit constexpr operator uint64_t() const noexcept {
|
||||
return static_cast<uint64_t>(m_timestamp);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator+=(T time_difference) noexcept {
|
||||
m_timestamp += time_difference;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator-=(T time_difference) noexcept {
|
||||
m_timestamp -= time_difference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the timestamp as string in ISO date/time
|
||||
* ("yyyy-mm-ddThh:mm:ssZ") format. If the timestamp is invalid, an
|
||||
* empty string will be returned.
|
||||
*/
|
||||
std::string to_iso() const {
|
||||
std::string s;
|
||||
|
||||
if (m_timestamp != 0) {
|
||||
to_iso_str(s);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the timestamp as string in ISO date/time
|
||||
* ("yyyy-mm-ddThh:mm:ssZ") format. If the timestamp is invalid, the
|
||||
* string "1970-01-01T00:00:00Z" will be returned.
|
||||
*/
|
||||
std::string to_iso_all() const {
|
||||
std::string s;
|
||||
|
||||
to_iso_str(s);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
}; // class Timestamp
|
||||
|
||||
/**
|
||||
* A special Timestamp guaranteed to be ordered before any other valid
|
||||
* Timestamp.
|
||||
*/
|
||||
inline constexpr Timestamp start_of_time() noexcept {
|
||||
return {1};
|
||||
}
|
||||
|
||||
/**
|
||||
* A special Timestamp guaranteed to be ordered after any other valid
|
||||
* Timestamp.
|
||||
*/
|
||||
inline constexpr Timestamp end_of_time() noexcept {
|
||||
return {std::numeric_limits<uint32_t>::max()};
|
||||
}
|
||||
|
||||
template <typename TChar, typename TTraits>
|
||||
inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, Timestamp timestamp) {
|
||||
out << timestamp.to_iso();
|
||||
return out;
|
||||
}
|
||||
|
||||
inline bool operator==(const Timestamp& lhs, const Timestamp& rhs) noexcept {
|
||||
return static_cast<uint32_t>(lhs) == static_cast<uint32_t>(rhs);
|
||||
}
|
||||
|
||||
inline bool operator!=(const Timestamp& lhs, const Timestamp& rhs) noexcept {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator<(const Timestamp& lhs, const Timestamp& rhs) noexcept {
|
||||
return static_cast<uint32_t>(lhs) < static_cast<uint32_t>(rhs);
|
||||
}
|
||||
|
||||
inline bool operator>(const Timestamp& lhs, const Timestamp& rhs) noexcept {
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator<=(const Timestamp& lhs, const Timestamp& rhs) noexcept {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const Timestamp& lhs, const Timestamp& rhs) noexcept {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline osmium::Timestamp min_op_start_value<osmium::Timestamp>() {
|
||||
return end_of_time();
|
||||
}
|
||||
|
||||
template <>
|
||||
inline osmium::Timestamp max_op_start_value<osmium::Timestamp>() {
|
||||
return start_of_time();
|
||||
}
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_TIMESTAMP_HPP
|
||||
@@ -0,0 +1,75 @@
|
||||
#ifndef OSMIUM_OSM_TYPES_HPP
|
||||
#define OSMIUM_OSM_TYPES_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
/*
|
||||
* The following types are chosen so that they can represent all needed
|
||||
* numbers and still be reasonably space efficient. As the OSM database
|
||||
* needs 64 bit IDs for nodes, this size is used for all object IDs.
|
||||
*/
|
||||
using object_id_type = int64_t; ///< Type for OSM object (node, way, or relation) IDs.
|
||||
using unsigned_object_id_type = uint64_t; ///< Type for OSM object (node, way, or relation) IDs where we only allow positive IDs.
|
||||
using object_version_type = uint32_t; ///< Type for OSM object version number.
|
||||
using changeset_id_type = uint32_t; ///< Type for OSM changeset IDs.
|
||||
using user_id_type = uint32_t; ///< Type for OSM user IDs.
|
||||
using signed_user_id_type = int32_t; ///< Type for signed OSM user IDs.
|
||||
using num_changes_type = uint32_t; ///< Type for changeset num_changes.
|
||||
using num_comments_type = uint32_t; ///< Type for changeset num_comments.
|
||||
|
||||
/**
|
||||
* Size for strings in OSM data such as user names, tag keys, roles, etc.
|
||||
* In Osmium they can be up to 2^16 bytes long, but OSM usually has lower
|
||||
* defined limits.
|
||||
*/
|
||||
using string_size_type = uint16_t;
|
||||
|
||||
/**
|
||||
* This is the size type for the text in a changeset discussion comment.
|
||||
* There is no official limit for this. 16 bit is not enough for existing
|
||||
* OSM changesets, hopefully 32 bit is.
|
||||
*/
|
||||
using changeset_comment_size_type = uint32_t;
|
||||
|
||||
/// Maximum of 256 characters of max 4 bytes each (in UTF-8 encoding)
|
||||
enum {
|
||||
max_osm_string_length = 256 * 4
|
||||
};
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_TYPES_HPP
|
||||
@@ -0,0 +1,197 @@
|
||||
#ifndef OSMIUM_OSM_TYPES_FROM_STRING_HPP
|
||||
#define OSMIUM_OSM_TYPES_FROM_STRING_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/osm/entity_bits.hpp>
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
/**
|
||||
* Convert string with object id to object_id_type.
|
||||
*
|
||||
* @pre @code input != nullptr @endcode
|
||||
*
|
||||
* @param input Input string.
|
||||
*
|
||||
* @throws std::range_error if the value is out of range.
|
||||
*/
|
||||
inline object_id_type string_to_object_id(const char* input) {
|
||||
assert(input);
|
||||
if (*input != '\0' && !std::isspace(*input)) {
|
||||
char* end = nullptr;
|
||||
const auto id = std::strtoll(input, &end, 10);
|
||||
if (id != std::numeric_limits<long long>::min() && // NOLINT(google-runtime-int)
|
||||
id != std::numeric_limits<long long>::max() && // NOLINT(google-runtime-int)
|
||||
*end == '\0') {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
throw std::range_error{std::string{"illegal id: '"} + input + "'"};
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse string with object type identifier followed by object id. This
|
||||
* reads strings like "n1234" and "w10". If there is no type prefix,
|
||||
* the default_type is returned.
|
||||
*
|
||||
* @pre @code input != nullptr @endcode
|
||||
* @pre @code types != osmium::osm_entity_bits::nothing @endcode
|
||||
*
|
||||
* @param input Input string.
|
||||
* @param types Allowed types. Must not be osmium::osm_entity_bits::nothing.
|
||||
* @param default_type Type used when there is no type prefix.
|
||||
*
|
||||
* @returns std::pair of type and id.
|
||||
*
|
||||
* @throws std::range_error if the value is out of range.
|
||||
*/
|
||||
inline std::pair<osmium::item_type, osmium::object_id_type>
|
||||
string_to_object_id(const char* input,
|
||||
osmium::osm_entity_bits::type types,
|
||||
osmium::item_type default_type = osmium::item_type::undefined) {
|
||||
assert(input);
|
||||
assert(types != osmium::osm_entity_bits::nothing);
|
||||
if (*input != '\0') {
|
||||
if (std::isdigit(*input)) {
|
||||
return std::make_pair(default_type, string_to_object_id(input));
|
||||
}
|
||||
const osmium::item_type t = osmium::char_to_item_type(*input);
|
||||
if (osmium::osm_entity_bits::from_item_type(t) & types) {
|
||||
return std::make_pair(t, string_to_object_id(input + 1));
|
||||
}
|
||||
}
|
||||
throw std::range_error{std::string{"not a valid id: '"} + input + "'"};
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
inline uint32_t string_to_ulong(const char* input, const char* name) {
|
||||
if (input[0] == '-' && input[1] == '1' && input[2] == '\0') {
|
||||
return 0;
|
||||
}
|
||||
if (*input != '\0' && *input != '-' && !std::isspace(*input)) {
|
||||
char* end = nullptr;
|
||||
const auto value = std::strtoul(input, &end, 10);
|
||||
if (value < std::numeric_limits<uint32_t>::max() && *end == '\0') {
|
||||
return static_cast<uint32_t>(value);
|
||||
}
|
||||
}
|
||||
throw std::range_error{std::string{"illegal "} + name + ": '" + input + "'"};
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* Convert string with object version to object_version_type.
|
||||
*
|
||||
* @pre input must not be nullptr.
|
||||
*
|
||||
* @param input Input string.
|
||||
*
|
||||
* @throws std::range_error if the value is out of range.
|
||||
*/
|
||||
inline object_version_type string_to_object_version(const char* input) {
|
||||
assert(input);
|
||||
return detail::string_to_ulong(input, "version");
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string with changeset id to changeset_id_type.
|
||||
*
|
||||
* @pre input must not be nullptr.
|
||||
*
|
||||
* @param input Input string.
|
||||
*
|
||||
* @throws std::range_error if the value is out of range.
|
||||
*/
|
||||
inline changeset_id_type string_to_changeset_id(const char* input) {
|
||||
assert(input);
|
||||
return detail::string_to_ulong(input, "changeset");
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string with user id to user_id_type.
|
||||
*
|
||||
* @pre input must not be nullptr.
|
||||
*
|
||||
* @param input Input string.
|
||||
*
|
||||
* @throws std::range_error if the value is out of range.
|
||||
*/
|
||||
inline user_id_type string_to_uid(const char* input) {
|
||||
assert(input);
|
||||
return detail::string_to_ulong(input, "user id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string with number of changes to num_changes_type.
|
||||
*
|
||||
* @pre input must not be nullptr.
|
||||
*
|
||||
* @param input Input string.
|
||||
*
|
||||
* @throws std::range_error if the value is out of range.
|
||||
*/
|
||||
inline num_changes_type string_to_num_changes(const char* input) {
|
||||
assert(input);
|
||||
return detail::string_to_ulong(input, "value for num changes");
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string with number of comments to num_comments_type.
|
||||
*
|
||||
* @pre input must not be nullptr.
|
||||
*
|
||||
* @param input Input string.
|
||||
*
|
||||
* @throws std::range_error if the value is out of range.
|
||||
*/
|
||||
inline num_comments_type string_to_num_comments(const char* input) {
|
||||
assert(input);
|
||||
return detail::string_to_ulong(input, "value for num comments");
|
||||
}
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_TYPES_FROM_STRING_HPP
|
||||
@@ -0,0 +1,92 @@
|
||||
#ifndef OSMIUM_OSM_UNDIRECTED_SEGMENT_HPP
|
||||
#define OSMIUM_OSM_UNDIRECTED_SEGMENT_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/osm/location.hpp>
|
||||
#include <osmium/osm/segment.hpp>
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
/**
|
||||
* Undirected connection between two Locations. The first Location is
|
||||
* always equal or "smaller" than the second Location, ie to the left
|
||||
* and down.
|
||||
*/
|
||||
class UndirectedSegment : public Segment {
|
||||
|
||||
public:
|
||||
|
||||
explicit UndirectedSegment(const osmium::Location& location1, const osmium::Location& location2) :
|
||||
Segment(location1, location2) {
|
||||
if (location2 < location1) {
|
||||
swap_locations();
|
||||
}
|
||||
}
|
||||
|
||||
}; // class UndirectedSegment
|
||||
|
||||
/**
|
||||
* UndirectedSegments are "smaller" if they are to the left and down of another
|
||||
* segment. The first() location is checked first() and only if they have the
|
||||
* same first() location the second() location is taken into account.
|
||||
*/
|
||||
inline bool operator<(const UndirectedSegment& lhs, const UndirectedSegment& rhs) noexcept {
|
||||
return (lhs.first() == rhs.first() && lhs.second() < rhs.second()) || lhs.first() < rhs.first();
|
||||
}
|
||||
|
||||
inline bool operator>(const UndirectedSegment& lhs, const UndirectedSegment& rhs) noexcept {
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator<=(const UndirectedSegment& lhs, const UndirectedSegment& rhs) noexcept {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const UndirectedSegment& lhs, const UndirectedSegment& rhs) noexcept {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output UndirectedSegment to a stream.
|
||||
*/
|
||||
template <typename TChar, typename TTraits>
|
||||
inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const osmium::UndirectedSegment& segment) {
|
||||
return out << segment.first() << "--" << segment.second();
|
||||
}
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_UNDIRECTED_SEGMENT_HPP
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
#ifndef OSMIUM_OSM_WAY_HPP
|
||||
#define OSMIUM_OSM_WAY_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (https://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <osmium/memory/collection.hpp>
|
||||
#include <osmium/memory/item.hpp>
|
||||
#include <osmium/osm/box.hpp>
|
||||
#include <osmium/osm/entity.hpp>
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
#include <osmium/osm/node_ref.hpp>
|
||||
#include <osmium/osm/node_ref_list.hpp>
|
||||
#include <osmium/osm/object.hpp>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
namespace builder {
|
||||
template <typename TDerived, typename T>
|
||||
class OSMObjectBuilder;
|
||||
} // namespace builder
|
||||
|
||||
/**
|
||||
* List of node references (id and location) in a way.
|
||||
*/
|
||||
class WayNodeList : public NodeRefList {
|
||||
|
||||
public:
|
||||
|
||||
static constexpr osmium::item_type itemtype = osmium::item_type::way_node_list;
|
||||
|
||||
constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
|
||||
return t == itemtype;
|
||||
}
|
||||
|
||||
WayNodeList() noexcept :
|
||||
NodeRefList(itemtype) {
|
||||
}
|
||||
|
||||
}; // class WayNodeList
|
||||
|
||||
static_assert(sizeof(WayNodeList) % osmium::memory::align_bytes == 0, "Class osmium::WayNodeList has wrong size to be aligned properly!");
|
||||
|
||||
class Way : public OSMObject {
|
||||
|
||||
template <typename TDerived, typename T>
|
||||
friend class osmium::builder::OSMObjectBuilder;
|
||||
|
||||
Way() noexcept :
|
||||
OSMObject(sizeof(Way), osmium::item_type::way) {
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static constexpr osmium::item_type itemtype = osmium::item_type::way;
|
||||
|
||||
constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
|
||||
return t == itemtype;
|
||||
}
|
||||
|
||||
WayNodeList& nodes() {
|
||||
return osmium::detail::subitem_of_type<WayNodeList>(begin(), end());
|
||||
}
|
||||
|
||||
const WayNodeList& nodes() const {
|
||||
return osmium::detail::subitem_of_type<const WayNodeList>(cbegin(), cend());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all nodes in a way with the ID of the given NodeRef with the
|
||||
* location of the given NodeRef.
|
||||
*/
|
||||
void update_node_location(const NodeRef& new_node_ref) {
|
||||
for (auto& node_ref : nodes()) {
|
||||
if (node_ref.ref() == new_node_ref.ref()) {
|
||||
node_ref.set_location(new_node_ref.location());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the first and last node in the way have the
|
||||
* same ID. The locations are not checked.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*
|
||||
* @pre @code !empty() @endcode
|
||||
*/
|
||||
bool is_closed() const noexcept {
|
||||
return nodes().is_closed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the first and last node in the way have the
|
||||
* same ID. The locations are not checked.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*
|
||||
* @pre @code !empty() @endcode
|
||||
*/
|
||||
bool ends_have_same_id() const noexcept {
|
||||
return nodes().ends_have_same_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the first and last node in the way have the
|
||||
* same location. The IDs are not checked.
|
||||
*
|
||||
* Complexity: Constant.
|
||||
*
|
||||
* @pre @code !empty() @endcode
|
||||
* @pre @code front().location() && back().location() @endcode
|
||||
*/
|
||||
bool ends_have_same_location() const {
|
||||
return nodes().ends_have_same_location();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the envelope of this way. If the locations of the nodes
|
||||
* are not set, the resulting box will be invalid.
|
||||
*
|
||||
* Complexity: Linear in the number of nodes.
|
||||
*/
|
||||
osmium::Box envelope() const noexcept {
|
||||
return nodes().envelope();
|
||||
}
|
||||
|
||||
}; // class Way
|
||||
|
||||
static_assert(sizeof(Way) % osmium::memory::align_bytes == 0, "Class osmium::Way has wrong size to be aligned properly!");
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_OSM_WAY_HPP
|
||||
Reference in new issue
Block a user