Loading...
Searching...
No Matches
diff_object.hpp
Go to the documentation of this file.
#ifndef OSMIUM_OSM_DIFF_OBJECT_HPP
#define OSMIUM_OSM_DIFF_OBJECT_HPP
/*
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2026 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <osmium/osm/item_type.hpp>
#include <osmium/osm/object.hpp>
#include <osmium/osm/timestamp.hpp>
#include <osmium/osm/types.hpp>
#include <cassert>
namespace osmium {
class Node;
class Way;
class Relation;
class DiffObject {
const osmium::OSMObject* m_prev = nullptr;
const osmium::OSMObject* m_curr = nullptr;
const osmium::OSMObject* m_next = nullptr;
public:
DiffObject() noexcept = default;
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());
}
bool empty() const noexcept {
return m_prev == nullptr;
}
const osmium::OSMObject& prev() const noexcept {
assert(m_prev && m_curr && m_next);
return *m_prev;
}
const osmium::OSMObject& curr() const noexcept {
assert(m_prev && m_curr && m_next);
return *m_curr;
}
const osmium::OSMObject& next() const noexcept {
assert(m_prev && m_curr && m_next);
return *m_next;
}
bool first() const noexcept {
assert(m_prev && m_curr && m_next);
return m_prev == m_curr;
}
bool last() const noexcept {
assert(m_prev && m_curr && m_next);
return m_curr == m_next;
}
osmium::item_type type() const noexcept {
assert(m_prev && m_curr && m_next);
return m_curr->type();
}
osmium::object_id_type id() const noexcept {
assert(m_prev && m_curr && m_next);
return m_curr->id();
}
osmium::object_version_type version() const noexcept {
assert(m_prev && m_curr && m_next);
return m_curr->version();
}
osmium::changeset_id_type changeset() const noexcept {
assert(m_prev && m_curr && m_next);
return m_curr->changeset();
}
osmium::Timestamp start_time() const noexcept {
assert(m_prev && m_curr && m_next);
return m_curr->timestamp();
}
osmium::Timestamp end_time() const noexcept {
assert(m_prev && m_curr && m_next);
return last() ? osmium::end_of_time() : m_next->timestamp();
}
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));
}
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
osmium::DiffObjectDerived
Definition diff_object.hpp:243
osmium::DiffObjectDerived< osmium::Node >::prev
const osmium::Node & prev() const noexcept
Definition diff_object.hpp:251
osmium::DiffObjectDerived::DiffObjectDerived
DiffObjectDerived(const T &prev, const T &curr, const T &next) noexcept
Definition diff_object.hpp:247
osmium::DiffObjectDerived< osmium::Node >::next
const osmium::Node & next() const noexcept
Definition diff_object.hpp:259
osmium::DiffObjectDerived< osmium::Node >::curr
const osmium::Node & curr() const noexcept
Definition diff_object.hpp:255
osmium::DiffObject::end_time
osmium::Timestamp end_time() const noexcept
Definition diff_object.hpp:209
osmium::DiffObject::is_visible_at
bool is_visible_at(const osmium::Timestamp &timestamp) const noexcept
Definition diff_object.hpp:235
osmium::DiffObject::type
osmium::item_type type() const noexcept
Definition diff_object.hpp:155
osmium::DiffObject::empty
bool empty() const noexcept
Definition diff_object.hpp:96
osmium::DiffObject::DiffObject
DiffObject() noexcept=default
osmium::DiffObject::start_time
osmium::Timestamp start_time() const noexcept
Definition diff_object.hpp:195
osmium::DiffObject::changeset
osmium::changeset_id_type changeset() const noexcept
Definition diff_object.hpp:185
osmium::DiffObject::next
const osmium::OSMObject & next() const noexcept
Definition diff_object.hpp:125
osmium::DiffObject::m_curr
const osmium::OSMObject * m_curr
Definition diff_object.hpp:69
osmium::DiffObject::m_prev
const osmium::OSMObject * m_prev
Definition diff_object.hpp:68
osmium::DiffObject::curr
const osmium::OSMObject & curr() const noexcept
Definition diff_object.hpp:115
osmium::DiffObject::id
osmium::object_id_type id() const noexcept
Definition diff_object.hpp:165
osmium::DiffObject::m_next
const osmium::OSMObject * m_next
Definition diff_object.hpp:70
osmium::DiffObject::first
bool first() const noexcept
Definition diff_object.hpp:135
osmium::DiffObject::prev
const osmium::OSMObject & prev() const noexcept
Definition diff_object.hpp:105
osmium::DiffObject::is_between
bool is_between(const osmium::Timestamp &from, const osmium::Timestamp &to) const noexcept
Definition diff_object.hpp:223
osmium::DiffObject::last
bool last() const noexcept
Definition diff_object.hpp:145
osmium::DiffObject::version
osmium::object_version_type version() const noexcept
Definition diff_object.hpp:175
osmium::Node
Definition node.hpp:48
osmium::OSMObject
Definition object.hpp:64
osmium::Relation
Definition relation.hpp:161
osmium::Timestamp
Definition timestamp.hpp:175
osmium::Way
Definition way.hpp:72
item_type.hpp
osmium
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
osmium::end_of_time
constexpr Timestamp end_of_time() noexcept
Definition timestamp.hpp:328
osmium::DiffNode
DiffObjectDerived< osmium::Node > DiffNode
Definition diff_object.hpp:265
osmium::changeset_id_type
uint32_t changeset_id_type
Type for OSM changeset IDs.
Definition types.hpp:48
osmium::DiffWay
DiffObjectDerived< osmium::Way > DiffWay
Definition diff_object.hpp:266
osmium::item_type
item_type
Definition item_type.hpp:45
osmium::object_id_type
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition types.hpp:45
osmium::object_version_type
uint32_t object_version_type
Type for OSM object version number.
Definition types.hpp:47
osmium::DiffRelation
DiffObjectDerived< osmium::Relation > DiffRelation
Definition diff_object.hpp:267
object.hpp
timestamp.hpp
types.hpp