Revert "fixing line endings"

This reverts commit dc75469e78.
This commit is contained in:
Dennis Luxen
2014-08-15 18:53:00 +02:00
parent dc75469e78
commit 5efa9664db
131 changed files with 0 additions and 21457 deletions
-172
View File
@@ -1,172 +0,0 @@
#ifndef OSMIUM_OSM_AREA_HPP
#define OSMIUM_OSM_AREA_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013,2014 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 <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;
}
/**
* An outer ring of an Area.
*/
class OuterRing : public NodeRefList<osmium::item_type::outer_ring> {
public:
OuterRing():
NodeRefList<osmium::item_type::outer_ring>() {
}
}; // 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<osmium::item_type::inner_ring> {
public:
InnerRing():
NodeRefList<osmium::item_type::inner_ring>() {
}
}; // 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) {
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) {
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 {
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 {
return osmium::area_id_to_object_id(id());
}
/**
* Count the number of outer and inner rings of this area.
*/
std::pair<int, int> num_rings() const {
std::pair<int, int> counter;
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;
default:
break;
}
}
return counter;
}
/**
* Is this area a multipolygon, ie. has it more than one outer ring?
*/
bool is_multipolygon() const {
return num_rings().first > 1;
}
}; // 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
-206
View File
@@ -1,206 +0,0 @@
#ifndef OSMIUM_OSM_BOX_HPP
#define OSMIUM_OSM_BOX_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013,2014 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>
namespace osmium {
/**
* Bounding box.
*/
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() :
m_bottom_left(),
m_top_right() {
}
Box(double minx, double miny, double maxx, double maxy) :
m_bottom_left(minx, miny),
m_top_right(maxx, maxy) {
}
Box(const osmium::Location& bottom_left, const osmium::Location& top_right) :
m_bottom_left(bottom_left),
m_top_right(top_right) {
}
Box(const Box&) = default;
Box(Box&&) = default;
Box& operator=(const Box&) = default;
Box& operator=(Box&&) = default;
~Box() = default;
/**
* Extend this bounding box by the given location. If the
* location is undefined, the bounding box is unchanged.
*/
Box& extend(const Location& location) noexcept {
if (location) {
if (m_bottom_left) {
if (location.x() < m_bottom_left.x()) {
m_bottom_left.x(location.x());
}
if (location.x() > m_top_right.x()) {
m_top_right.x(location.x());
}
if (location.y() < m_bottom_left.y()) {
m_bottom_left.y(location.y());
}
if (location.y() > m_top_right.y()) {
m_top_right.y(location.y());
}
} else {
m_bottom_left = location;
m_top_right = location;
}
}
return *this;
}
/**
* Extend this bounding box by the given box. If the
* box is undefined, the bounding box is unchanged.
*/
Box& extend(const Box& box) noexcept {
extend(box.bottom_left());
extend(box.top_right());
return *this;
}
/**
* Box are defined, ie. contains defined coordinates.
*/
explicit constexpr operator bool() const noexcept {
return static_cast<bool>(m_bottom_left);
}
/**
* Box are 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();
}
/**
* Bottom-left location.
*/
constexpr Location bottom_left() const noexcept {
return m_bottom_left;
}
/**
* Bottom-left location.
*/
Location& bottom_left() noexcept {
return m_bottom_left;
}
/**
* Top-right location.
*/
constexpr Location top_right() const noexcept {
return m_top_right;
}
/**
* Top-right location.
*/
Location& top_right() noexcept {
return m_top_right;
}
/**
* Is the location inside the box?
*/
bool contains(const osmium::Location& location) const {
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.
*
* @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.
*/
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.
*/
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
-325
View File
@@ -1,325 +0,0 @@
#ifndef OSMIUM_OSM_CHANGESET_HPP
#define OSMIUM_OSM_CHANGESET_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013,2014 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 <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/util/operators.hpp>
namespace osmium {
namespace builder {
template <class T> class ObjectBuilder;
}
/**
* An OSM Changeset is of a group of changes made by a single user over a
* short period of time.
*/
class Changeset : public osmium::OSMEntity, osmium::totally_ordered<Changeset> {
friend class osmium::builder::ObjectBuilder<osmium::Changeset>;
osmium::Timestamp m_created_at {};
osmium::Timestamp m_closed_at {};
osmium::Box m_bounds {};
changeset_id_type m_id {0};
num_changes_type m_num_changes {0};
user_id_type m_uid {0};
string_size_type m_user_size;
Changeset() :
OSMEntity(sizeof(Changeset), osmium::item_type::changeset) {
}
void 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);
}
template <class T>
T& subitem_of_type() {
for (iterator it = begin(); it != end(); ++it) {
if (it->type() == T::itemtype) {
return reinterpret_cast<T&>(*it);
}
}
static T subitem;
return subitem;
}
template <class T>
const T& subitem_of_type() const {
for (const_iterator it = cbegin(); it != cend(); ++it) {
if (it->type() == T::itemtype) {
return reinterpret_cast<const T&>(*it);
}
}
static const T subitem;
return subitem;
}
public:
/// Get ID of this changeset
changeset_id_type id() const noexcept {
return m_id;
}
/**
* Set ID of this changeset
*
* @return Reference to changeset to make calls chainable.
*/
Changeset& id(changeset_id_type id) noexcept {
m_id = id;
return *this;
}
/**
* Set ID of this changeset.
*
* @return Reference to object to make calls chainable.
*/
Changeset& id(const char* id) {
return this->id(osmium::string_to_changeset_id(id));
}
/// Get user id.
user_id_type uid() const noexcept {
return m_uid;
}
/**
* Set user id.
*
* @return Reference to changeset to make calls chainable.
*/
Changeset& uid(user_id_type uid) noexcept {
m_uid = uid;
return *this;
}
/**
* Set user id.
* Sets uid to 0 (anonymous) if the given uid is smaller than 0.
*
* @return Reference to changeset to make calls chainable.
*/
Changeset& 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.
*
* @return Reference to changeset to make calls chainable.
*/
Changeset& uid(const char* uid) {
return this->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.
*
* This will return the empty Timestamp when the
* changeset is not yet closed.
*/
osmium::Timestamp closed_at() const noexcept {
return m_closed_at;
}
bool open() const noexcept {
return m_closed_at == osmium::Timestamp();
}
bool closed() const noexcept {
return !open();
}
/**
* Set the timestamp when this changeset was created.
*
* @param timestamp Timestamp
* @return Reference to changeset to make calls chainable.
*/
Changeset& created_at(const osmium::Timestamp timestamp) {
m_created_at = timestamp;
return *this;
}
/**
* Set the timestamp when this changeset was closed.
*
* @param timestamp Timestamp
* @return Reference to changeset to make calls chainable.
*/
Changeset& closed_at(const osmium::Timestamp timestamp) {
m_closed_at = timestamp;
return *this;
}
num_changes_type num_changes() const noexcept {
return m_num_changes;
}
Changeset& num_changes(num_changes_type num_changes) noexcept {
m_num_changes = num_changes;
return *this;
}
Changeset& num_changes(const char* num_changes) noexcept {
return this->num_changes(osmium::string_to_num_changes(num_changes));
}
osmium::Box& bounds() noexcept {
return m_bounds;
}
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.
TagList& tags() {
return subitem_of_type<TagList>();
}
/// Get the list of tags.
const TagList& tags() const {
return subitem_of_type<const TagList>();
}
/**
* 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")) {
id(value);
} else if (!strcmp(attr, "num_changes")) {
num_changes(value);
} else if (!strcmp(attr, "created_at")) {
created_at(osmium::Timestamp(value));
} else if (!strcmp(attr, "closed_at")) {
closed_at(osmium::Timestamp(value));
} else if (!strcmp(attr, "uid")) {
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();
}
}; // 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();
}
/**
* Changesets can be ordered by id.
*/
inline bool operator<(const Changeset& lhs, const Changeset& rhs) {
return lhs.id() < rhs.id();
}
} // namespace osmium
#endif // OSMIUM_OSM_CHANGESET_HPP
-156
View File
@@ -1,156 +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,2014 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <osmium/osm/item_type.hpp>
#include <osmium/osm/object.hpp>
#include <osmium/osm/timestamp.hpp>
#include <osmium/osm/types.hpp>
namespace osmium {
class Node;
class Way;
class Relation;
class DiffObject {
protected:
osmium::OSMObject* m_prev;
osmium::OSMObject* m_curr;
osmium::OSMObject* m_next;
public:
DiffObject() :
m_prev(nullptr),
m_curr(nullptr),
m_next(nullptr) {
}
explicit DiffObject(osmium::OSMObject& prev, osmium::OSMObject& curr, osmium::OSMObject& next) :
m_prev(&prev),
m_curr(&curr),
m_next(&next) {
}
DiffObject(const DiffObject& other) = default;
DiffObject& operator=(const DiffObject& other) = default;
DiffObject(DiffObject&& other) = default;
DiffObject& operator=(DiffObject&& other) = default;
const osmium::OSMObject& prev() const {
return *m_prev;
}
const osmium::OSMObject& curr() const {
return *m_curr;
}
const osmium::OSMObject& next() const {
return *m_next;
}
bool first() const {
return m_prev == m_curr;
}
bool last() const {
return m_curr == m_next;
}
osmium::item_type type() const {
return m_curr->type();
}
osmium::object_id_type id() const {
return m_curr->id();
}
osmium::object_version_type version() const {
return m_curr->version();
}
osmium::changeset_id_type changeset() const {
return m_curr->changeset();
}
const osmium::Timestamp start_time() const {
return m_curr->timestamp();
}
const osmium::Timestamp end_time() const {
return last() ? osmium::Timestamp() : m_next->timestamp();
}
}; // class DiffObject
template <class T>
class DiffObjectDerived : public DiffObject {
public:
DiffObjectDerived(T& prev, T& curr, T& next) :
DiffObject(prev, curr, next) {
}
DiffObjectDerived(const DiffObjectDerived& other) = default;
DiffObjectDerived& operator=(const DiffObjectDerived& other) = default;
DiffObjectDerived(DiffObjectDerived&& other) = default;
DiffObjectDerived& operator=(DiffObjectDerived&& other) = default;
const T& prev() const {
return *static_cast<const T*>(m_prev);
}
const T& curr() const {
return *static_cast<const T*>(m_curr);
}
const T& next() const {
return *static_cast<const T*>(m_next);
}
}; // class DiffObjectDerived
typedef DiffObjectDerived<osmium::Node> DiffNode;
typedef DiffObjectDerived<osmium::Way> DiffWay;
typedef DiffObjectDerived<osmium::Relation> DiffRelation;
} // namespace osmium
#endif // OSMIUM_OSM_DIFF_OBJECT_HPP
-55
View File
@@ -1,55 +0,0 @@
#ifndef OSMIUM_OSM_ENTITY_HPP
#define OSMIUM_OSM_ENTITY_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013,2014 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>
namespace osmium {
/**
* OSMEntity is the parent class for the OSMObject class and the Changeset class.
*/
class OSMEntity : public osmium::memory::Item {
public:
explicit OSMEntity(osmium::memory::item_size_type size, osmium::item_type type) :
Item(size, type) {
}
}; // class OSMEntity
} // namespace osmium
#endif // OSMIUM_OSM_ENTITY_HPP
-93
View File
@@ -1,93 +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,2014 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.
*/
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,
area = 0x08,
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) {
return static_cast<type>(static_cast<int>(lhs) | static_cast<int> (rhs));
}
inline type& operator|=(type& lhs, const type rhs) {
lhs = lhs | rhs;
return lhs;
}
inline type operator&(const type lhs, const type rhs) {
return static_cast<type>(static_cast<int>(lhs) & static_cast<int> (rhs));
}
inline type operator&=(type& lhs, const type rhs) {
lhs = lhs & rhs;
return lhs;
}
} // namespace osm_entity_bits
} // namespace osmium
#endif // OSMIUM_OSM_ENTITY_BITS_HPP
-163
View File
@@ -1,163 +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,2014 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> // 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
}; // enum class item_type
inline item_type char_to_item_type(const char c) {
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;
default:
return item_type::undefined;
}
}
inline char item_type_to_char(const item_type type) {
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';
}
}
inline const char* item_type_to_name(const item_type type) {
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";
}
}
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);
}
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
-287
View File
@@ -1,287 +0,0 @@
#ifndef OSMIUM_OSM_LOCATION_HPP
#define OSMIUM_OSM_LOCATION_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013,2014 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iosfwd>
#include <limits>
#include <stdexcept>
#include <string>
#include <osmium/util/operators.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 {
invalid_location(const std::string& what) :
std::range_error(what) {
}
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 : osmium::totally_ordered<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() :
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) :
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) :
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& x(const int32_t x) noexcept {
m_x = x;
return *this;
}
Location& 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& lon(double lon) noexcept {
m_x = double_to_fix(lon);
return *this;
}
Location& lat(double lat) noexcept {
m_y = double_to_fix(lat);
return *this;
}
static constexpr int coordinate_length =
1 + /* sign */
3 + /* before . */
1 + /* . */
7 + /* after . */
1; /* null byte */
template <typename T>
static T coordinate2string(T iterator, double value) {
char buffer[coordinate_length];
int len = snprintf(buffer, coordinate_length, "%.7f", value);
while (buffer[len-1] == '0') --len;
if (buffer[len-1] == '.') --len;
return std::copy_n(buffer, len, iterator);
}
template <typename T>
T as_string(T iterator, const char separator) const {
iterator = coordinate2string(iterator, lon());
*iterator++ = separator;
return coordinate2string(iterator, lat());
}
}; // 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();
}
/**
* 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();
}
/**
* 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
-80
View File
@@ -1,80 +0,0 @@
#ifndef OSMIUM_OSM_NODE_HPP
#define OSMIUM_OSM_NODE_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013,2014 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 <class T> class ObjectBuilder;
}
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;
const osmium::Location location() const {
return m_location;
}
osmium::Location& location() {
return m_location;
}
Node& 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
-137
View File
@@ -1,137 +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,2014 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 <cstdlib>
#include <iosfwd>
#include <osmium/memory/item.hpp>
#include <osmium/osm/item_type.hpp>
#include <osmium/osm/location.hpp>
#include <osmium/osm/types.hpp>
#include <osmium/util/operators.hpp>
namespace osmium {
/**
* This reference to a node contains a node ID and a (possibly empty)
* location.
*/
class NodeRef : public osmium::memory::detail::ItemHelper, public osmium::totally_ordered<NodeRef> {
osmium::object_id_type m_ref;
osmium::Location m_location;
public:
NodeRef(const osmium::object_id_type ref=0, const osmium::Location& location=Location()) :
m_ref(ref),
m_location(location) {
}
osmium::object_id_type ref() const {
return m_ref;
}
osmium::unsigned_object_id_type positive_ref() const {
return static_cast<osmium::unsigned_object_id_type>(std::abs(m_ref));
}
osmium::Location location() const {
return m_location;
}
double lon() const {
return m_location.lon();
}
double lat() const {
return m_location.lat();
}
void location(const osmium::Location& location) {
m_location = location;
}
}; // class NodeRef
inline bool operator<(const NodeRef& lhs, const NodeRef& rhs) {
return lhs.ref() < rhs.ref();
}
inline bool operator==(const NodeRef& lhs, const NodeRef& rhs) {
return lhs.ref() == rhs.ref();
}
/**
* 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 {
bool operator()(const NodeRef& lhs, const NodeRef& rhs) const {
return lhs.location() == rhs.location();
}
typedef NodeRef first_argument_type;
typedef NodeRef second_argument_type;
typedef bool result_type;
}; // struct location_equal
/**
* Functor to compare NodeRefs by Location instead of id.
*/
struct location_less {
bool operator()(const NodeRef& lhs, const NodeRef& rhs) const {
return lhs.location() < rhs.location();
}
typedef NodeRef first_argument_type;
typedef NodeRef second_argument_type;
typedef bool result_type;
}; // struct location_less
} // namespace osmium
#endif // OSMIUM_OSM_NODE_REF_HPP
-135
View File
@@ -1,135 +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,2014 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 {
/**
* A vector of NodeRef objects. Usually this is not instatiated directly,
* but one of its subclasses are used.
*/
template <osmium::item_type TItemType>
class NodeRefList : public osmium::memory::Item {
public:
static constexpr osmium::item_type itemtype = TItemType;
NodeRefList():
osmium::memory::Item(sizeof(NodeRefList), TItemType) {
}
bool empty() const {
return sizeof(NodeRefList) == byte_size();
}
size_t size() const noexcept {
assert((osmium::memory::Item::byte_size() - sizeof(NodeRefList)) % sizeof(NodeRef) == 0);
return (osmium::memory::Item::byte_size() - sizeof(NodeRefList)) / sizeof(NodeRef);
}
const NodeRef& operator[](size_t n) const {
const NodeRef* node_ref = &*(this->cbegin());
return node_ref[n];
}
const NodeRef& front() const {
return operator[](0);
}
const NodeRef& back() const {
return operator[](size()-1);
}
bool is_closed() const {
return front().ref() == back().ref();
}
bool ends_have_same_id() const {
return front().ref() == back().ref();
}
bool ends_have_same_location() const {
return front().location() == back().location();
}
typedef NodeRef* iterator;
typedef const NodeRef* const_iterator;
typedef std::reverse_iterator<const NodeRef*> const_reverse_iterator;
iterator begin() {
return iterator(data() + sizeof(NodeRefList));
}
iterator end() {
return iterator(data() + byte_size());
}
const_iterator cbegin() const {
return const_iterator(data() + sizeof(NodeRefList));
}
const_iterator cend() const {
return const_iterator(data() + byte_size());
}
const_iterator begin() const {
return cbegin();
}
const_iterator end() const {
return cend();
}
const_reverse_iterator crbegin() const {
return const_reverse_iterator(this->cend());
}
const_reverse_iterator crend() const {
return const_reverse_iterator(this->cbegin());
}
}; // class NodeRefList
} // namespace osmium
#endif // OSMIUM_OSM_NODE_REF_LIST_HPP
-414
View File
@@ -1,414 +0,0 @@
#ifndef OSMIUM_OSM_OBJECT_HPP
#define OSMIUM_OSM_OBJECT_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013,2014 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/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/util/operators.hpp>
namespace osmium {
/**
* OSMObject (Node, Way, Relation, or Area).
*/
class OSMObject : public osmium::OSMEntity, osmium::totally_ordered<OSMObject> {
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 {
return sizeof(OSMObject) + (type() == item_type::node ? sizeof(osmium::Location) : 0) + sizeof(string_size_type);
}
unsigned char* user_position() {
return data() + sizeof_object() - sizeof(string_size_type);
}
const unsigned char* user_position() const {
return data() + sizeof_object() - sizeof(string_size_type);
}
string_size_type user_size() const {
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 user_size(string_size_type size) {
*reinterpret_cast<string_size_type*>(user_position()) = size;
}
template <class T>
T& subitem_of_type() {
for (iterator it = begin(); it != end(); ++it) {
if (it->type() == T::itemtype) {
return reinterpret_cast<T&>(*it);
}
}
static T subitem;
return subitem;
}
template <class T>
const T& subitem_of_type() const {
for (const_iterator it = cbegin(); it != cend(); ++it) {
if (it->type() == T::itemtype) {
return reinterpret_cast<const T&>(*it);
}
}
static const T subitem;
return subitem;
}
public:
/// Get ID of this object.
object_id_type id() const {
return m_id;
}
/// Get absolute value of the ID of this object.
unsigned_object_id_type positive_id() const {
return static_cast<unsigned_object_id_type>(std::abs(m_id));
}
/**
* Set ID of this object.
*
* @return Reference to object to make calls chainable.
*/
OSMObject& id(object_id_type id) {
m_id = id;
return *this;
}
/**
* Set ID of this object.
*
* @return Reference to object to make calls chainable.
*/
OSMObject& id(const char* id) {
return this->id(osmium::string_to_object_id(id));
}
/// Is this object marked as deleted?
bool deleted() const {
return m_deleted;
}
/// Is this object marked visible (ie not deleted)?
bool visible() const {
return !deleted();
}
/**
* Mark this object as deleted (or not).
*
* @return Reference to object to make calls chainable.
*/
OSMObject& deleted(bool deleted) {
m_deleted = deleted;
return *this;
}
/**
* Mark this object as visible (ie not deleted) (or not).
*
* @return Reference to object to make calls chainable.
*/
OSMObject& visible(bool visible) {
m_deleted = !visible;
return *this;
}
/**
* Mark this object as visible (ie not deleted) or deleted.
*
* @param visible Either "true" or "false"
* @return Reference to object to make calls chainable.
*/
OSMObject& visible(const char* visible) {
if (!strcmp("true", visible)) {
this->visible(true);
} else if (!strcmp("false", visible)) {
this->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 {
return m_version;
}
/**
* Set object version.
*
* @return Reference to object to make calls chainable.
*/
OSMObject& version(object_version_type version) {
m_version = version;
return *this;
}
/**
* Set object version.
*
* @return Reference to object to make calls chainable.
*/
OSMObject& version(const char* version) {
return this->version(string_to_object_version(version));
}
/// Get changeset id of this object.
changeset_id_type changeset() const {
return m_changeset;
}
/**
* Set changeset id of this object.
*
* @return Reference to object to make calls chainable.
*/
OSMObject& changeset(changeset_id_type changeset) {
m_changeset = changeset;
return *this;
}
/**
* Set changeset id of this object.
*
* @return Reference to object to make calls chainable.
*/
OSMObject& changeset(const char* changeset) {
return this->changeset(string_to_changeset_id(changeset));
}
/// Get user id of this object.
user_id_type uid() const {
return m_uid;
}
/**
* Set user id of this object.
*
* @return Reference to object to make calls chainable.
*/
OSMObject& uid(user_id_type uid) {
m_uid = uid;
return *this;
}
/**
* Set user id of this object.
* Sets uid to 0 (anonymous) if the given uid is smaller than 0.
*
* @return Reference to object to make calls chainable.
*/
OSMObject& uid_from_signed(signed_user_id_type uid) {
m_uid = uid < 0 ? 0 : static_cast<user_id_type>(uid);
return *this;
}
/**
* Set user id of this object.
*
* @return Reference to object to make calls chainable.
*/
OSMObject& uid(const char* uid) {
return this->uid_from_signed(string_to_user_id(uid));
}
/// Is this user anonymous?
bool user_is_anonymous() const {
return m_uid == 0;
}
/// Get timestamp when this object last changed.
osmium::Timestamp timestamp() const {
return m_timestamp;
}
/**
* Set the timestamp when this object last changed.
*
* @param timestamp Timestamp
* @return Reference to object to make calls chainable.
*/
OSMObject& timestamp(const osmium::Timestamp timestamp) {
m_timestamp = timestamp;
return *this;
}
/// Get user name for this object.
const char* user() const {
return reinterpret_cast<const char*>(data() + sizeof_object());
}
/// Get the list of tags for this object.
TagList& tags() {
return subitem_of_type<TagList>();
}
/// Get the list of tags for this object.
const TagList& tags() const {
return subitem_of_type<const TagList>();
}
/**
* 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")) {
id(value);
} else if (!strcmp(attr, "version")) {
version(value);
} else if (!strcmp(attr, "changeset")) {
changeset(value);
} else if (!strcmp(attr, "timestamp")) {
timestamp(osmium::Timestamp(value));
} else if (!strcmp(attr, "uid")) {
uid(value);
} else if (!strcmp(attr, "visible")) {
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(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();
}
}; // 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 osmium::OSMObject& lhs, const osmium::OSMObject& rhs) {
return lhs.type() == rhs.type() &&
lhs.id() == rhs.id() &&
lhs.version() == rhs.version();
}
/**
* 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 osmium::OSMObject& lhs, const osmium::OSMObject& rhs) {
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();
}
} // namespace osmium
#endif // OSMIUM_OSM_OBJECT_HPP
-110
View File
@@ -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,2014 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 {
return lhs == rhs;
}
bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const {
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 {
return lhs.type() == rhs.type() &&
lhs.id() == rhs.id();
}
bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const {
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 {
return lhs < rhs;
}
bool operator()(const osmium::OSMObject* lhs, const osmium::OSMObject* rhs) const {
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 {
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 {
return operator()(*lhs, *rhs);
}
}; // struct object_order_type_id_reverse_version
} // namespace osmium
#endif // OSMIUM_OSM_OBJECT_COMPARISONS_HPP
-189
View File
@@ -1,189 +0,0 @@
#ifndef OSMIUM_OSM_RELATION_HPP
#define OSMIUM_OSM_RELATION_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013,2014 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 <class> class ObjectBuilder;
class RelationMemberListBuilder;
}
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 <class TMember>
friend class osmium::memory::CollectionIterator;
unsigned char* next() {
if (full_member()) {
return endpos() + reinterpret_cast<osmium::memory::Item*>(endpos())->byte_size();
} else {
return endpos();
}
}
unsigned const char* next() const {
if (full_member()) {
return endpos() + reinterpret_cast<const osmium::memory::Item*>(endpos())->byte_size();
} else {
return endpos();
}
}
void set_role_size(string_size_type size) {
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) :
m_ref(ref),
m_type(type),
m_flags(full ? 1 : 0) {
}
object_id_type ref() const {
return m_ref;
}
RelationMember& ref(object_id_type ref) {
m_ref = ref;
return *this;
}
unsigned_object_id_type positive_ref() const {
return static_cast<unsigned_object_id_type>(std::abs(m_ref));
}
item_type type() const {
return m_type;
}
bool full_member() const {
return m_flags == 1;
}
const char* role() const {
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() :
OSMObject(sizeof(Relation), osmium::item_type::relation) {
}
public:
static constexpr osmium::item_type itemtype = osmium::item_type::relation;
RelationMemberList& members() {
return subitem_of_type<RelationMemberList>();
}
const RelationMemberList& members() const {
return subitem_of_type<const RelationMemberList>();
}
}; // 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
-104
View File
@@ -1,104 +0,0 @@
#ifndef OSMIUM_OSM_SEGMENT_HPP
#define OSMIUM_OSM_SEGMENT_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013,2014 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>
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) :
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 {
return m_first;
}
/// Return second Location of Segment.
constexpr osmium::Location second() const {
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) {
return lhs.first() == rhs.first() && lhs.second() == rhs.second();
}
inline constexpr bool operator!=(const Segment& lhs, const Segment& rhs) {
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
-140
View File
@@ -1,140 +0,0 @@
#ifndef OSMIUM_OSM_TAG_HPP
#define OSMIUM_OSM_TAG_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013,2014 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 <class 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 {
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;
} else {
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
-153
View File
@@ -1,153 +0,0 @@
#ifndef OSMIUM_OSM_TIMESTAMP_HPP
#define OSMIUM_OSM_TIMESTAMP_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013,2014 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 <ctime>
#include <iosfwd>
#include <limits>
#include <stdexcept>
#include <string>
namespace osmium {
/**
* A timestamp. Internal representation is an unsigned 32bit integer
* holding seconds since epoch, so this will overflow in 2038.
*/
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:
constexpr Timestamp() :
m_timestamp(0) {
}
// Not "explicit" so that conversions from time_t work
// like in node.timestamp(123);
constexpr Timestamp(time_t timestamp) :
m_timestamp(static_cast<uint32_t>(timestamp)) {
}
/**
* Construct timestamp from ISO date/time string.
* 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 = _mkgmtime(&tm);
#endif
}
constexpr time_t seconds_since_epoch() const {
return static_cast<time_t>(m_timestamp);
}
constexpr operator time_t() const {
return static_cast<time_t>(m_timestamp);
}
/**
* Return UTC Unix time as string in ISO date/time format.
*/
std::string to_iso() const {
if (m_timestamp == 0) {
return std::string("");
}
struct tm tm {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
time_t sse = seconds_since_epoch();
gmtime_r(&sse, &tm);
std::string s(timestamp_length, '\0');
/* 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
inline constexpr Timestamp start_of_time() {
return Timestamp(1);
}
inline constexpr Timestamp end_of_time() {
return Timestamp(std::numeric_limits<time_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;
}
} // namespace osmium
#endif // OSMIUM_OSM_TIMESTAMP_HPP
-83
View File
@@ -1,83 +0,0 @@
#ifndef OSMIUM_OSM_TYPES_HPP
#define OSMIUM_OSM_TYPES_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013,2014 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>
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.
/**
* 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;
inline object_id_type string_to_object_id(const char* string) {
return std::atoll(string);
}
inline object_version_type string_to_object_version(const char* string) {
return static_cast<object_version_type>(std::atol(string));
}
inline changeset_id_type string_to_changeset_id(const char* string) {
return static_cast<changeset_id_type>(std::atol(string));
}
inline signed_user_id_type string_to_user_id(const char* string) {
return static_cast<signed_user_id_type>(std::atol(string));
}
inline num_changes_type string_to_num_changes(const char* string) {
return static_cast<num_changes_type>(std::atol(string));
}
} // namespace osmium
#endif // OSMIUM_OSM_TYPES_HPP
-89
View File
@@ -1,89 +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,2014 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>
#include <osmium/util/operators.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 : osmium::totally_ordered<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) {
return (lhs.first() == rhs.first() && lhs.second() < rhs.second()) || lhs.first() < rhs.first();
}
/**
* 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
-115
View File
@@ -1,115 +0,0 @@
#ifndef OSMIUM_OSM_WAY_HPP
#define OSMIUM_OSM_WAY_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013,2014 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 <class T> class ObjectBuilder;
}
/**
* List of node references (id and location) in a way.
*/
class WayNodeList : public NodeRefList<osmium::item_type::way_node_list> {
public:
WayNodeList():
NodeRefList<osmium::item_type::way_node_list>() {
}
}; // 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() :
OSMObject(sizeof(Way), osmium::item_type::way) {
}
public:
WayNodeList& nodes() {
return subitem_of_type<WayNodeList>();
}
const WayNodeList& nodes() const {
return subitem_of_type<const WayNodeList>();
}
/**
* 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.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