Remove libosmium

This commit is contained in:
Patrick Niklaus
2016-03-01 17:54:39 +01:00
parent 042740877c
commit ae85d86d8f
229 changed files with 0 additions and 40229 deletions
-215
View File
@@ -1,215 +0,0 @@
#ifndef OSMIUM_OSM_AREA_HPP
#define OSMIUM_OSM_AREA_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <cassert>
#include <cstdlib>
#include <utility>
#include <osmium/memory/collection.hpp>
#include <osmium/memory/item.hpp>
#include <osmium/osm/item_type.hpp>
#include <osmium/osm/object.hpp>
#include <osmium/osm/types.hpp>
#include <osmium/osm/node_ref_list.hpp>
namespace osmium {
namespace builder {
template <class T> class ObjectBuilder;
} // namespace builder
/**
* An outer ring of an Area.
*/
class OuterRing : public NodeRefList {
public:
static constexpr osmium::item_type itemtype = osmium::item_type::outer_ring;
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;
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 {
friend class osmium::builder::ObjectBuilder<osmium::Area>;
Area() :
OSMObject(sizeof(Area), osmium::item_type::area) {
}
public:
static constexpr osmium::item_type itemtype = osmium::item_type::area;
/**
* Was this area created from a way? (In contrast to areas
* created from a relation and their members.)
*/
bool from_way() const noexcept {
return (positive_id() & 0x1) == 0;
}
/**
* Return the Id of the way or relation this area was created from.
*/
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.
*
* @returns Pair (number outer rings, number inner rings)
*/
std::pair<int, int> num_rings() const {
std::pair<int, int> counter { 0, 0 };
for (auto it = cbegin(); it != cend(); ++it) {
switch (it->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;
}
/**
* Get iterator for iterating over all inner rings in a specified outer
* ring.
*
* @param it Iterator specifying outer ring.
* @returns Iterator to first inner ring in specified outer ring.
*/
osmium::memory::ItemIterator<const osmium::InnerRing> inner_ring_cbegin(const osmium::memory::ItemIterator<const osmium::OuterRing>& it) const {
return it.cast<const osmium::InnerRing>();
}
/**
* Get iterator for iterating over all inner rings in a specified outer
* ring.
*
* @param it Iterator specifying outer ring.
* @returns Iterator one past last inner ring in specified outer ring.
*/
osmium::memory::ItemIterator<const osmium::InnerRing> inner_ring_cend(const osmium::memory::ItemIterator<const osmium::OuterRing>& it) const {
return std::next(it).cast<const osmium::InnerRing>();
}
}; // 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
-253
View File
@@ -1,253 +0,0 @@
#ifndef OSMIUM_OSM_BOX_HPP
#define OSMIUM_OSM_BOX_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <cassert>
#include <iosfwd>
#include <osmium/util/compatibility.hpp>
#include <osmium/osm/location.hpp>
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 :
m_bottom_left(),
m_top_right() {
}
/**
* Create box from minimum and maximum coordinates.
*
* @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())
);
}
Box(const Box&) = default;
Box(Box&&) = default;
Box& operator=(const Box&) = default;
Box& operator=(Box&&) = default;
~Box() = default;
/**
* 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 bool(m_bottom_left) && 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;
}
/**
* 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().lon()
<< ','
<< box.bottom_left().lat()
<< ','
<< box.top_right().lon()
<< ','
<< box.top_right().lat()
<< ')';
} else {
out << "(undefined)";
}
return out;
}
} // namespace osmium
#endif // OSMIUM_OSM_BOX_HPP
-458
View File
@@ -1,458 +0,0 @@
#ifndef OSMIUM_OSM_CHANGESET_HPP
#define OSMIUM_OSM_CHANGESET_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <cstring>
#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>
namespace osmium {
namespace builder {
class ChangesetDiscussionBuilder;
template <typename T> class ObjectBuilder;
} // 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};
string_size_type m_user_size;
string_size_type m_text_size;
ChangesetComment(const ChangesetComment&) = delete;
ChangesetComment(ChangesetComment&&) = delete;
ChangesetComment& operator=(const ChangesetComment&) = delete;
ChangesetComment& operator=(ChangesetComment&&) = delete;
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();
}
unsigned const char* next() const {
return endpos();
}
void set_user_size(string_size_type size) noexcept {
m_user_size = size;
}
void set_text_size(string_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),
m_user_size(0),
m_text_size(0) {
}
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> {
friend class osmium::builder::ObjectBuilder<osmium::Changeset>;
public:
typedef size_t size_type;
ChangesetDiscussion() :
osmium::memory::Collection<ChangesetComment, osmium::item_type::changeset_discussion>() {
}
size_type size() const noexcept {
return static_cast<size_type>(std::distance(begin(), end()));
}
}; // 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::ObjectBuilder<osmium::Changeset>;
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;
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) {
m_user_size = 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:
/// 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) {
return set_uid_from_signed(string_to_user_id(uid));
}
/// 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));
}
/// 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 (!strcmp(attr, "id")) {
set_id(value);
} else if (!strcmp(attr, "num_changes")) {
set_num_changes(value);
} else if (!strcmp(attr, "comments_count")) {
set_num_comments(value);
} else if (!strcmp(attr, "created_at")) {
set_created_at(osmium::Timestamp(value));
} else if (!strcmp(attr, "closed_at")) {
set_closed_at(osmium::Timestamp(value));
} else if (!strcmp(attr, "uid")) {
set_uid(value);
}
}
typedef osmium::memory::CollectionIterator<Item> iterator;
typedef osmium::memory::CollectionIterator<const Item> const_iterator;
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
-242
View File
@@ -1,242 +0,0 @@
#ifndef OSMIUM_OSM_CRC_HPP
#define OSMIUM_OSM_CRC_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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>
#include <osmium/osm/area.hpp>
#include <osmium/osm/changeset.hpp>
#include <osmium/osm/location.hpp>
#include <osmium/osm/node.hpp>
#include <osmium/osm/node_ref_list.hpp>
#include <osmium/osm/relation.hpp>
#include <osmium/osm/way.hpp>
#include <osmium/util/endian.hpp>
namespace osmium {
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
uint64_t val1 = byte_swap_32(value & 0xFFFFFFFF);
uint64_t val2 = byte_swap_32(value >> 32);
return (val1 << 32) | val2;
# endif
}
} // namespace util
template <typename TCRC>
class CRC {
TCRC m_crc;
public:
TCRC& operator()() {
return m_crc;
}
const TCRC& operator()() const {
return m_crc;
}
void update_bool(const bool value) {
m_crc.process_byte(value);
}
void update_int8(const uint8_t value) {
m_crc.process_byte(value);
}
void update_int16(const uint16_t value) {
#if __BYTE_ORDER == __LITTLE_ENDIAN
m_crc.process_bytes(&value, sizeof(uint16_t));
#else
uint16_t v = osmium::util::byte_swap_16(value);
m_crc.process_bytes(&v, sizeof(uint16_t));
#endif
}
void update_int32(const uint32_t value) {
#if __BYTE_ORDER == __LITTLE_ENDIAN
m_crc.process_bytes(&value, sizeof(uint32_t));
#else
uint32_t v = osmium::util::byte_swap_32(value);
m_crc.process_bytes(&v, sizeof(uint32_t));
#endif
}
void update_int64(const uint64_t value) {
#if __BYTE_ORDER == __LITTLE_ENDIAN
m_crc.process_bytes(&value, sizeof(uint64_t));
#else
uint64_t v = osmium::util::byte_swap_64(value);
m_crc.process_bytes(&v, sizeof(uint64_t));
#endif
}
void update_string(const char* str) {
while (*str) {
m_crc.process_byte(*str++);
}
}
void update(const Timestamp& timestamp) {
update_int32(uint32_t(timestamp));
}
void update(const osmium::Location& location) {
update_int32(location.x());
update_int32(location.y());
}
void update(const osmium::Box& box) {
update(box.bottom_left());
update(box.top_right());
}
void update(const NodeRef& node_ref) {
update_int64(node_ref.ref());
}
void update(const NodeRefList& node_refs) {
for (const NodeRef& node_ref : node_refs) {
update(node_ref);
}
}
void update(const TagList& tags) {
for (const Tag& tag : tags) {
update_string(tag.key());
update_string(tag.value());
}
}
void update(const osmium::RelationMember& member) {
update_int64(member.ref());
update_int16(uint16_t(member.type()));
update_string(member.role());
}
void update(const osmium::RelationMemberList& members) {
for (const RelationMember& member : members) {
update(member);
}
}
void update(const osmium::OSMObject& object) {
update_int64(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) {
update(static_cast<const osmium::OSMObject&>(node));
update(node.location());
}
void update(const osmium::Way& way) {
update(static_cast<const osmium::OSMObject&>(way));
update(way.nodes());
}
void update(const osmium::Relation& relation) {
update(static_cast<const osmium::OSMObject&>(relation));
update(relation.members());
}
void update(const osmium::Area& area) {
update(static_cast<const osmium::OSMObject&>(area));
for (auto it = area.cbegin(); it != area.cend(); ++it) {
if (it->type() == osmium::item_type::outer_ring ||
it->type() == osmium::item_type::inner_ring) {
update(static_cast<const osmium::NodeRefList&>(*it));
}
}
}
void update(const osmium::ChangesetDiscussion& discussion) {
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) {
update_int64(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
-272
View File
@@ -1,272 +0,0 @@
#ifndef OSMIUM_OSM_DIFF_OBJECT_HPP
#define OSMIUM_OSM_DIFF_OBJECT_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <cassert>
#include <osmium/fwd.hpp>
#include <osmium/osm/item_type.hpp>
#include <osmium/osm/object.hpp>
#include <osmium/osm/timestamp.hpp>
#include <osmium/osm/types.hpp>
namespace osmium {
/**
* 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;
const osmium::OSMObject* m_curr;
const osmium::OSMObject* m_next;
public:
/**
* Default construct an empty DiffObject. Most methods of this class
* can not be called on empty DiffObjects.
*/
DiffObject() noexcept :
m_prev(nullptr),
m_curr(nullptr),
m_next(nullptr) {
}
/**
* 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.
*/
const 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.
*/
const 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
-80
View File
@@ -1,80 +0,0 @@
#ifndef OSMIUM_OSM_ENTITY_HPP
#define OSMIUM_OSM_ENTITY_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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, TIter end) {
for (; it != end; ++it) {
if (it->type() == TSubitem::itemtype) {
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:
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
-105
View File
@@ -1,105 +0,0 @@
#ifndef OSMIUM_OSM_ENTITY_BITS_HPP
#define OSMIUM_OSM_ENTITY_BITS_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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>
namespace osmium {
/**
* @brief Bitfield 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 {
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 type operator|(const type lhs, const type rhs) noexcept {
return static_cast<type>(static_cast<int>(lhs) | static_cast<int> (rhs));
}
inline type& operator|=(type& lhs, const type rhs) noexcept {
lhs = lhs | rhs;
return lhs;
}
inline type operator&(const type lhs, const type rhs) noexcept {
return static_cast<type>(static_cast<int>(lhs) & static_cast<int> (rhs));
}
inline type operator~(const type value) noexcept {
return static_cast<type>(~static_cast<int>(value));
}
inline type operator&=(type& lhs, const type rhs) noexcept {
lhs = lhs & rhs;
return lhs;
}
inline type from_item_type(osmium::item_type item_type) noexcept {
return static_cast<osmium::osm_entity_bits::type>(0x1 << (static_cast<uint16_t>(item_type) - 1));
}
} // namespace osm_entity_bits
} // namespace osmium
#endif // OSMIUM_OSM_ENTITY_BITS_HPP
-208
View File
@@ -1,208 +0,0 @@
#ifndef OSMIUM_OSM_ITEM_TYPE_HPP
#define OSMIUM_OSM_ITEM_TYPE_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <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 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 {
unsigned int 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 'X':
return item_type::undefined;
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:
return item_type::undefined;
}
}
// avoid g++ false positive
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type"
inline char item_type_to_char(const item_type type) noexcept {
switch (type) {
case item_type::undefined:
return 'X';
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';
}
}
inline const char* item_type_to_name(const item_type type) noexcept {
switch (type) {
case item_type::undefined:
return "undefined";
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";
}
}
#pragma GCC diagnostic pop
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 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
-285
View File
@@ -1,285 +0,0 @@
#ifndef OSMIUM_OSM_LOCATION_HPP
#define OSMIUM_OSM_LOCATION_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <cmath>
#include <cstdint>
#include <iosfwd>
#include <stdexcept>
#include <string>
#include <iostream>
#include <osmium/util/compatibility.hpp>
#include <osmium/util/double.hpp>
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
/**
* 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;
int32_t m_y;
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.
// static constexpr int32_t undefined_coordinate = std::numeric_limits<int32_t>::max();
static constexpr int32_t undefined_coordinate = 2147483647;
static constexpr int coordinate_precision = 10000000;
static int32_t double_to_fix(const double c) noexcept {
return static_cast<int32_t>(std::round(c * coordinate_precision));
}
static constexpr double fix_to_double(const int32_t c) noexcept {
return static_cast<double>(c) / coordinate_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.
*/
Location(const double lon, const double lat) :
m_x(double_to_fix(lon)),
m_y(double_to_fix(lat)) {
}
Location(const Location&) = default;
Location(Location&&) = default;
Location& operator=(const Location&) = default;
Location& operator=(Location&&) = default;
~Location() = default;
/**
* Check whether the coordinates of this location
* are defined.
*/
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).
*/
constexpr bool valid() const noexcept {
return m_x >= -180 * coordinate_precision
&& m_x <= 180 * coordinate_precision
&& m_y >= -90 * coordinate_precision
&& m_y <= 90 * coordinate_precision;
}
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 {
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 {
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;
}
template <typename T>
T as_string(T iterator, const char separator) const {
iterator = osmium::util::double2string(iterator, lon(), 7);
*iterator++ = separator;
return osmium::util::double2string(iterator, lat(), 7);
}
}; // 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.lon() << ',' << location.lat() << ')';
} else {
out << "(undefined,undefined)";
}
return out;
}
} // namespace osmium
#endif // OSMIUM_OSM_LOCATION_HPP
-76
View File
@@ -1,76 +0,0 @@
#ifndef OSMIUM_OSM_NODE_HPP
#define OSMIUM_OSM_NODE_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 T> class ObjectBuilder;
} // namespace builder
class Node : public OSMObject {
friend class osmium::builder::ObjectBuilder<osmium::Node>;
osmium::Location m_location;
Node() :
OSMObject(sizeof(Node), osmium::item_type::node) {
}
public:
static constexpr osmium::item_type itemtype = osmium::item_type::node;
osmium::Location location() const noexcept {
return m_location;
}
Node& set_location(const osmium::Location& location) {
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
-231
View File
@@ -1,231 +0,0 @@
#ifndef OSMIUM_OSM_NODE_REF_HPP
#define OSMIUM_OSM_NODE_REF_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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>
#include <cstdlib>
#include <iosfwd>
#include <osmium/memory/item.hpp>
#include <osmium/osm/location.hpp>
#include <osmium/osm/types.hpp>
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:
constexpr NodeRef(const osmium::object_id_type ref = 0, const osmium::Location& location = Location()) noexcept :
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
@@ -1,187 +0,0 @@
#ifndef OSMIUM_OSM_NODE_REF_LIST_HPP
#define OSMIUM_OSM_NODE_REF_LIST_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <cassert>
#include <cstddef>
#include <iterator>
#include <osmium/memory/item.hpp>
#include <osmium/osm/item_type.hpp>
#include <osmium/osm/node_ref.hpp>
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:
explicit NodeRefList(osmium::item_type itemtype) noexcept :
osmium::memory::Item(sizeof(NodeRefList), itemtype) {
}
/**
* Checks whether the collection is empty.
*/
bool empty() const noexcept {
return sizeof(NodeRefList) == byte_size();
}
/**
* Returns the number of NodeRefs in the collection.
*/
size_t size() const noexcept {
auto size_node_refs = byte_size() - sizeof(NodeRefList);
assert(size_node_refs % sizeof(NodeRef) == 0);
return size_node_refs / sizeof(NodeRef);
}
/**
* Access specified element.
*
* @pre @code n < size() @endcode
*
* @param n Get the n-th element of the collection.
*/
const NodeRef& operator[](size_t n) const noexcept {
assert(n < size());
const NodeRef* node_ref = &*(cbegin());
return node_ref[n];
}
/**
* Access the first element.
*
* @pre @code !empty() @endcode
*/
const NodeRef& front() const noexcept {
assert(!empty());
return operator[](0);
}
/**
* Access the last element.
*
* @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.
*
* @pre @code !empty() @endcode
*/
bool is_closed() const noexcept {
return ends_have_same_id();
}
/**
* Checks whether the first and last node in the collection have the
* same ID. The locations are not checked.
*
* @pre @code !empty() @endcode
*/
bool ends_have_same_id() const noexcept {
return front().ref() == back().ref();
}
/**
* Checks whether the first and last node in the collection have the
* same location. The IDs are not checked.
*
* @pre @code !empty() @endcode
* @pre @code front().location() && back().location() @endcode
*/
bool ends_have_same_location() const {
assert(front().location() && back().location());
return front().location() == back().location();
}
using iterator = NodeRef*;
using const_iterator = const NodeRef*;
using const_reverse_iterator = std::reverse_iterator<const NodeRef*>;
/// Returns an iterator to the beginning.
iterator begin() noexcept {
return iterator(data() + sizeof(NodeRefList));
}
/// Returns an iterator to the end.
iterator end() noexcept {
return iterator(data() + byte_size());
}
/// Returns an iterator to the beginning.
const_iterator cbegin() const noexcept {
return const_iterator(data() + sizeof(NodeRefList));
}
/// Returns an iterator to the end.
const_iterator cend() const noexcept {
return 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
-438
View File
@@ -1,438 +0,0 @@
#ifndef OSMIUM_OSM_OBJECT_HPP
#define OSMIUM_OSM_OBJECT_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <stdexcept>
#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>
namespace osmium {
/**
* OSMObject (Node, Way, Relation, or Area).
*/
class OSMObject : public osmium::OSMEntity {
object_id_type m_id;
bool m_deleted : 1;
object_version_type m_version : 31;
osmium::Timestamp m_timestamp;
user_id_type m_uid;
changeset_id_type m_changeset;
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_id(0),
m_deleted(false),
m_version(0),
m_timestamp(),
m_uid(0),
m_changeset(0) {
}
void set_user_size(string_size_type size) {
*reinterpret_cast<string_size_type*>(user_position()) = size;
}
public:
/// 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 (!strcmp("true", visible)) {
set_visible(true);
} else if (!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) {
return set_uid_from_signed(string_to_user_id(uid));
}
/// 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;
}
/// Get user name for this object.
const char* user() const noexcept {
return reinterpret_cast<const char*>(data() + sizeof_object());
}
/// 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
*/
void set_attribute(const char* attr, const char* value) {
if (!strcmp(attr, "id")) {
set_id(value);
} else if (!strcmp(attr, "version")) {
set_version(value);
} else if (!strcmp(attr, "changeset")) {
set_changeset(value);
} else if (!strcmp(attr, "timestamp")) {
set_timestamp(osmium::Timestamp(value));
} else if (!strcmp(attr, "uid")) {
set_uid(value);
} else if (!strcmp(attr, "visible")) {
set_visible(value);
}
}
typedef osmium::memory::CollectionIterator<Item> iterator;
typedef osmium::memory::CollectionIterator<const Item> const_iterator;
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();
}
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 and version.
* Note that we use the absolute value of the id for a
* better ordering of objects with negative id.
*/
inline bool operator<(const OSMObject& lhs, const OSMObject& rhs) noexcept {
if (lhs.type() != rhs.type()) {
return lhs.type() < rhs.type();
}
return (lhs.id() == rhs.id() && lhs.version() < rhs.version()) ||
lhs.positive_id() < rhs.positive_id();
}
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
@@ -1,110 +0,0 @@
#ifndef OSMIUM_OSM_OBJECT_COMPARISONS_HPP
#define OSMIUM_OSM_OBJECT_COMPARISONS_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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>
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;
}
bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
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();
}
bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
return operator()(*lhs, *rhs);
}
}; // struct object_equal_type_id
/**
* Function object class for ordering OSM objects by type, id, and version.
*/
struct object_order_type_id_version {
bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
return lhs < rhs;
}
bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
return *lhs < *rhs;
}
}; // struct object_order_type_id_version
/**
* Function object class for ordering OSM objects by type, id, and reverse version,
* ie objects are ordered by type and id, but later versions of an object are
* ordered before earlier versions of the same object.
*/
struct object_order_type_id_reverse_version {
bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept {
if (lhs.type() != rhs.type()) {
return lhs.type() < rhs.type();
}
return (lhs.id() == rhs.id() && lhs.version() > rhs.version()) ||
lhs.positive_id() < rhs.positive_id();
}
bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const noexcept {
return operator()(*lhs, *rhs);
}
}; // struct object_order_type_id_reverse_version
} // namespace osmium
#endif // OSMIUM_OSM_OBJECT_COMPARISONS_HPP
-192
View File
@@ -1,192 +0,0 @@
#ifndef OSMIUM_OSM_RELATION_HPP
#define OSMIUM_OSM_RELATION_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <cstddef>
#include <cstdint>
#include <cstdlib>
#include <iterator>
#include <osmium/memory/collection.hpp> // IWYU pragma: keep
#include <osmium/memory/item.hpp>
#include <osmium/osm/item_type.hpp>
#include <osmium/osm/object.hpp>
#include <osmium/osm/types.hpp>
namespace osmium {
namespace builder {
template <typename> class ObjectBuilder;
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};
RelationMember(const RelationMember&) = delete;
RelationMember(RelationMember&&) = delete;
RelationMember& operator=(const RelationMember&) = delete;
RelationMember& operator=(RelationMember&&) = delete;
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();
}
unsigned const 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;
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) {
}
object_id_type ref() const noexcept {
return m_ref;
}
RelationMember& ref(object_id_type ref) noexcept {
m_ref = ref;
return *this;
}
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:
typedef size_t size_type;
RelationMemberList() :
osmium::memory::Collection<RelationMember, osmium::item_type::relation_member_list>() {
}
size_type size() const noexcept {
return static_cast<size_type>(std::distance(begin(), end()));
}
}; // 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 {
friend class osmium::builder::ObjectBuilder<osmium::Relation>;
Relation() noexcept :
OSMObject(sizeof(Relation), osmium::item_type::relation) {
}
public:
static constexpr osmium::item_type itemtype = osmium::item_type::relation;
RelationMemberList& members() {
return osmium::detail::subitem_of_type<RelationMemberList>(begin(), end());
}
const RelationMemberList& members() 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
-105
View File
@@ -1,105 +0,0 @@
#ifndef OSMIUM_OSM_SEGMENT_HPP
#define OSMIUM_OSM_SEGMENT_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <iosfwd>
#include <utility>
#include <osmium/osm/location.hpp>
#include <osmium/util/compatibility.hpp>
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) {
}
constexpr Segment(const Segment&) = default;
constexpr Segment(Segment&&) = default;
Segment& operator=(const Segment&) = default;
Segment& operator=(Segment&&) = default;
~Segment() = default;
/// 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
-139
View File
@@ -1,139 +0,0 @@
#ifndef OSMIUM_OSM_TAG_HPP
#define OSMIUM_OSM_TAG_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <cstddef>
#include <cstring>
#include <iosfwd>
#include <iterator>
#include <osmium/memory/collection.hpp>
#include <osmium/memory/item.hpp>
#include <osmium/osm/item_type.hpp>
namespace osmium {
class Tag : public osmium::memory::detail::ItemHelper {
Tag(const Tag&) = delete;
Tag(Tag&&) = delete;
Tag& operator=(const Tag&) = delete;
Tag& operator=(Tag&&) = delete;
template <typename TMember>
friend class osmium::memory::CollectionIterator;
static unsigned char* after_null(unsigned char* ptr) {
return reinterpret_cast<unsigned char*>(std::strchr(reinterpret_cast<char*>(ptr), 0) + 1);
}
static const unsigned char* after_null(const unsigned char* ptr) {
return reinterpret_cast<const unsigned char*>(std::strchr(reinterpret_cast<const char*>(ptr), 0) + 1);
}
unsigned char* next() {
return after_null(after_null(data()));
}
const unsigned char* next() const {
return after_null(after_null(data()));
}
public:
static constexpr item_type collection_type = item_type::tag_list;
const char* key() const noexcept {
return reinterpret_cast<const char*>(data());
}
const char* value() const {
return reinterpret_cast<const char*>(after_null(data()));
}
}; // class Tag
inline bool operator==(const Tag& a, const Tag& b) {
return !std::strcmp(a.key(), b.key()) && !strcmp(a.value(), b.value());
}
inline bool operator<(const Tag& a, const Tag& b) {
return (!std::strcmp(a.key(), b.key()) && (std::strcmp(a.value(), b.value()) < 0)) || (std::strcmp(a.key(), b.key()) < 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> {
public:
typedef size_t size_type;
TagList() :
osmium::memory::Collection<Tag, osmium::item_type::tag_list>() {
}
size_type size() const noexcept {
return static_cast<size_type>(std::distance(begin(), end()));
}
const char* get_value_by_key(const char* key, const char* default_value = nullptr) const noexcept {
auto result = std::find_if(cbegin(), cend(), [key](const Tag& tag) {
return !strcmp(tag.key(), key);
});
if (result == cend()) {
return default_value;
}
return result->value();
}
const char* operator[](const char* key) const noexcept {
return get_value_by_key(key);
}
}; // 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
-274
View File
@@ -1,274 +0,0 @@
#ifndef OSMIUM_OSM_TIMESTAMP_HPP
#define OSMIUM_OSM_TIMESTAMP_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <cassert>
#include <cstdint>
#include <ctime>
#include <iosfwd>
#include <limits>
#include <stdexcept>
#include <string>
#include <osmium/util/compatibility.hpp>
#include <osmium/util/minmax.hpp> // IWYU pragma: keep
namespace osmium {
/**
* 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 {
// length of ISO timestamp string yyyy-mm-ddThh:mm:ssZ\0
static constexpr int timestamp_length = 20 + 1;
// The timestamp format for OSM timestamps in strftime(3) format.
// This is the ISO-Format "yyyy-mm-ddThh:mm:ssZ".
static const char* timestamp_format() {
static const char f[timestamp_length] = "%Y-%m-%dT%H:%M:%SZ";
return f;
}
uint32_t m_timestamp;
public:
/**
* Default construct an invalid Timestamp.
*/
constexpr Timestamp() noexcept :
m_timestamp(0) {
}
/**
* 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 :
m_timestamp(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) {
#ifndef _WIN32
struct tm tm {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
if (strptime(timestamp, timestamp_format(), &tm) == nullptr) {
throw std::invalid_argument("can't parse timestamp");
}
m_timestamp = static_cast<uint32_t>(timegm(&tm));
#else
struct tm tm;
int n = sscanf(timestamp, "%4d-%2d-%2dT%2d:%2d:%2dZ", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
if (n != 6) {
throw std::invalid_argument("can't parse timestamp");
}
tm.tm_year -= 1900;
tm.tm_mon--;
tm.tm_wday = 0;
tm.tm_yday = 0;
tm.tm_isdst = 0;
m_timestamp = static_cast<uint32_t>(_mkgmtime(&tm));
#endif
}
/**
* 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 time_t seconds_since_epoch() const noexcept {
return time_t(m_timestamp);
}
/// Explicit conversion into uint32_t.
explicit constexpr operator uint32_t() const noexcept {
return uint32_t(m_timestamp);
}
/// Explicit conversion into uint64_t.
explicit constexpr operator uint64_t() const noexcept {
return uint64_t(m_timestamp);
}
/**
* Implicit conversion into time_t.
*
* @deprecated You should call seconds_since_epoch() explicitly instead.
*/
OSMIUM_DEPRECATED constexpr operator time_t() const noexcept {
return static_cast<time_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) {
struct tm tm;
time_t sse = seconds_since_epoch();
#ifndef NDEBUG
auto result =
#endif
#ifndef _MSC_VER
gmtime_r(&sse, &tm);
assert(result != nullptr);
#else
gmtime_s(&tm, &sse);
assert(result == 0);
#endif
s.resize(timestamp_length);
/* This const_cast is ok, because we know we have enough space
in the string for the format we are using (well at least until
the year will have 5 digits). And by setting the size
afterwards from the result of strftime we make sure thats set
right, too. */
s.resize(strftime(const_cast<char*>(s.c_str()), timestamp_length, timestamp_format(), &tm));
}
return s;
}
}; // class Timestamp
/**
* A special Timestamp guaranteed to be ordered before any other valid
* Timestamp.
*/
inline constexpr Timestamp start_of_time() noexcept {
return Timestamp(1);
}
/**
* A special Timestamp guaranteed to be ordered after any other valid
* Timestamp.
*/
inline constexpr Timestamp end_of_time() noexcept {
return Timestamp(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 uint32_t(lhs) == 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 uint32_t(lhs) < 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
-66
View File
@@ -1,66 +0,0 @@
#ifndef OSMIUM_OSM_TYPES_HPP
#define OSMIUM_OSM_TYPES_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 typedefs 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.
*/
typedef int64_t object_id_type; ///< Type for OSM object (node, way, or relation) IDs.
typedef uint64_t unsigned_object_id_type; ///< Type for OSM object (node, way, or relation) IDs where we only allow positive IDs.
typedef uint32_t object_version_type; ///< Type for OSM object version number.
typedef uint32_t changeset_id_type; ///< Type for OSM changeset IDs.
typedef uint32_t user_id_type; ///< Type for OSM user IDs.
typedef int32_t signed_user_id_type; ///< Type for signed OSM user IDs.
typedef uint32_t num_changes_type; ///< Type for changeset num_changes.
typedef uint32_t num_comments_type; ///< 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.
*/
typedef uint16_t string_size_type;
// maximum of 256 characters of max 4 bytes each (in UTF-8 encoding)
constexpr const int max_osm_string_length = 256 * 4;
} // namespace osmium
#endif // OSMIUM_OSM_TYPES_HPP
@@ -1,189 +0,0 @@
#ifndef OSMIUM_OSM_TYPES_FROM_STRING_HPP
#define OSMIUM_OSM_TYPES_FROM_STRING_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <limits>
#include <string>
#include <utility>
#include <osmium/osm/entity_bits.hpp>
#include <osmium/osm/types.hpp>
#include <osmium/util/cast.hpp>
namespace osmium {
/**
* Convert string with object id to object_id_type.
*
* @pre input must not be nullptr.
*
* @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;
auto id = std::strtoll(input, &end, 10);
if (id != std::numeric_limits<long long>::min() && id != std::numeric_limits<long long>::max() && *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".
*
* @pre input must not be nullptr.
*
* @param input Input string.
* @param types Allowed types. Must not be osmium::osm_entity_bits::nothing.
*
* @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) {
assert(input);
assert(types != osmium::osm_entity_bits::nothing);
if (*input != '\0') {
if (std::isdigit(*input)) {
return std::make_pair(osmium::item_type::undefined, string_to_object_id(input));
}
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 unsigned long string_to_ulong(const char* input, const char *name) {
if (*input != '\0' && *input != '-' && !std::isspace(*input)) {
char* end;
auto value = std::strtoul(input, &end, 10);
if (value != std::numeric_limits<unsigned long>::max() && *end == '\0') {
return 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 static_cast_with_assert<object_version_type>(detail::string_to_ulong(input, "version"));
}
/**
* 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 changeset_id_type string_to_changeset_id(const char* input) {
assert(input);
return static_cast_with_assert<changeset_id_type>(detail::string_to_ulong(input, "changeset"));
}
/**
* Convert string with user id to signed_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 signed_user_id_type string_to_user_id(const char* input) {
assert(input);
if (input[0] == '-' && input[1] == '1' && input[2] == '\0') {
return -1;
}
return static_cast_with_assert<signed_user_id_type>(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 static_cast_with_assert<num_changes_type>(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 static_cast_with_assert<num_comments_type>(detail::string_to_ulong(input, "value for num comments"));
}
} // namespace osmium
#endif // OSMIUM_OSM_TYPES_FROM_STRING_HPP
@@ -1,100 +0,0 @@
#ifndef OSMIUM_OSM_UNDIRECTED_SEGMENT_HPP
#define OSMIUM_OSM_UNDIRECTED_SEGMENT_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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 <iosfwd>
#include <osmium/osm/location.hpp>
#include <osmium/osm/segment.hpp>
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();
}
}
UndirectedSegment(const UndirectedSegment&) = default;
UndirectedSegment(UndirectedSegment&&) = default;
UndirectedSegment& operator=(const UndirectedSegment&) = default;
UndirectedSegment& operator=(UndirectedSegment&&) = default;
~UndirectedSegment() = default;
}; // 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
-117
View File
@@ -1,117 +0,0 @@
#ifndef OSMIUM_OSM_WAY_HPP
#define OSMIUM_OSM_WAY_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 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/object.hpp>
#include <osmium/osm/types.hpp>
#include <osmium/osm/node_ref.hpp>
#include <osmium/osm/node_ref_list.hpp>
namespace osmium {
namespace builder {
template <typename T> class ObjectBuilder;
} // 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;
WayNodeList():
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 {
friend class osmium::builder::ObjectBuilder<osmium::Way>;
Way() noexcept :
OSMObject(sizeof(Way), osmium::item_type::way) {
}
public:
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());
}
}
}
/**
* Do the nodes in this way form a closed ring?
*/
bool is_closed() const {
return nodes().is_closed();
}
bool ends_have_same_id() const {
return nodes().ends_have_same_id();
}
bool ends_have_same_location() const {
return nodes().ends_have_same_location();
}
}; // 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