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-2025 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::prev
const T & 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::next
const T & next() const noexcept
Definition diff_object.hpp:259
osmium::DiffObjectDerived::curr
const T & curr() const noexcept
Definition diff_object.hpp:255
osmium::DiffObject
Definition diff_object.hpp:66
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::OSMObject
Definition object.hpp:64
osmium::OSMObject::visible
bool visible() const noexcept
Is this object marked visible (ie not deleted)?
Definition object.hpp:152
osmium::OSMObject::version
object_version_type version() const noexcept
Get version of this object.
Definition object.hpp:194
osmium::OSMObject::timestamp
osmium::Timestamp timestamp() const noexcept
Get timestamp when this object last changed.
Definition object.hpp:283
osmium::OSMObject::changeset
changeset_id_type changeset() const noexcept
Get changeset id of this object.
Definition object.hpp:218
osmium::OSMObject::id
object_id_type id() const noexcept
Get ID of this object.
Definition object.hpp:118
osmium::Timestamp
Definition timestamp.hpp:175
osmium::memory::Item::type
item_type type() const noexcept
Definition item.hpp:171
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::object_version_type
uint32_t object_version_type
Type for OSM object version number.
Definition types.hpp:47
osmium::changeset_id_type
uint32_t changeset_id_type
Type for OSM changeset IDs.
Definition types.hpp:48
osmium::object_id_type
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition types.hpp:45
osmium::item_type
item_type
Definition item_type.hpp:45
object.hpp
timestamp.hpp
types.hpp