10#include "kosm_export.h"
26 inline constexpr Element() : m_elem(
nullptr,
static_cast<uint8_t
>(Type::Null)) {}
27 inline Element(
const Node *node) : m_elem(node,
static_cast<uint8_t
>(Type::Node)) {}
28 inline Element(
const Way *way) : m_elem(way,
static_cast<uint8_t
>(Type::Way)) {}
29 inline Element(
const Relation *relation) : m_elem(relation,
static_cast<uint8_t
>(Type::Relation)) {}
31 [[nodiscard]]
inline bool operator==(
Element other)
const {
return m_elem == other.m_elem; }
32 [[nodiscard]]
inline bool operator!=(
Element other)
const {
return m_elem != other.m_elem; }
33 [[nodiscard]]
inline bool operator<(
Element other)
const {
return m_elem < other.m_elem; }
34 [[nodiscard]]
explicit inline operator bool()
const {
return type() != OSM::Type::Null; }
36 [[nodiscard]]
inline Type type()
const {
return static_cast<Type>(m_elem.tag()); }
37 [[nodiscard]]
inline const Node* node()
const {
return static_cast<const Node*
>(m_elem.get()); }
38 [[nodiscard]]
inline const Way* way()
const {
return static_cast<const Way*
>(m_elem.get()); }
39 [[nodiscard]]
inline const Relation* relation()
const {
return static_cast<const Relation*
>(m_elem.get()); }
40 [[nodiscard]]
Id id()
const;
50 template <
typename K,
typename ...Args> [[nodiscard]]
QByteArray tagValue(K key, Args... args)
const;
53 [[nodiscard]]
inline bool hasTags()
const {
return std::distance(tagsBegin(), tagsEnd()) > 0; }
55 [[nodiscard]]
bool hasTag(
TagKey key)
const;
57 [[nodiscard]] std::vector<Tag>::const_iterator tagsBegin()
const;
58 [[nodiscard]] std::vector<Tag>::const_iterator tagsEnd()
const;
59 [[nodiscard]]
QString url()
const;
65 [[nodiscard]] std::vector<const Node*> outerPath(
const DataSet &dataSet)
const;
71 void recomputeBoundingBox(
const DataSet &dataSet);
77template <
typename K,
typename ...Args>
80 const auto v = tagValue(k);
84 return tagValue(args...);
87template <
typename K,
typename ...Args>
90 const auto v = tagValue(languages, key);
94 return tagValue(languages, args...);
109 std::swap(m_element, other.m_element);
116 std::swap(m_element, other.m_element);
120 [[nodiscard]]
explicit inline operator bool()
const {
return m_element.type() != OSM::Type::Null; }
122 [[nodiscard]]
constexpr inline Element element()
const {
return m_element; }
123 [[nodiscard]]
constexpr inline operator Element()
const {
return m_element; }
125 [[nodiscard]]
inline Node* node()
const {
return const_cast<Node*
>(m_element.node()); }
126 [[nodiscard]]
inline Way* way()
const {
return const_cast<Way*
>(m_element.way()); }
127 [[nodiscard]]
inline Relation* relation()
const {
return const_cast<Relation*
>(m_element.relation()); }
142template <
typename ...Args>
143[[nodiscard]]
constexpr Element
coalesce(Element e, Args... args) {
return e ? e :
coalesce(args...); }
152 if (
auto node = dataSet.
node(
id)) {
157 if (
auto way = dataSet.
way(
id)) {
162 if (
auto rel = dataSet.
relation(
id)) {
170enum ForeachFlag : uint8_t {
171 IncludeRelations = 1,
174 IterateAll = IncludeRelations | IncludeWays | IncludeNodes,
177template <
typename Func>
178inline void for_each(
const DataSet &dataSet, Func func, uint8_t flags = IterateAll)
180 if (flags & IncludeRelations) {
181 for (
const auto &rel : dataSet.relations) {
185 if (flags & IncludeWays) {
186 for (
const auto &way : dataSet.ways) {
190 if (flags & IncludeNodes) {
191 for (
const auto &node : dataSet.nodes) {
192 func(Element(&node));
197template <
typename Func>
198inline void for_each_node(
const DataSet &dataSet,
const Way &way, Func func)
200 for (
auto nodeId : way.nodes) {
201 if (
auto node = dataSet.node(nodeId)) {
207template <
typename Func>
208inline void for_each_member(
const DataSet &dataSet,
const Relation &rel, Func func)
210 for (
const auto &mem : rel.members) {
211 if (
auto elem =
lookupElement(dataSet, mem.type(), mem.id); elem.type() != OSM::Type::Null) {
220struct std::hash<
OSM::Element>
224 std::size_t h1 = std::hash<OSM::Id>{}(e.id());
225 std::size_t h2 = std::hash<int>{}(qToUnderlying(e.type()));
226 return h1 ^ (h2 << 1);
Coordinate, stored as 1e7 * degree to avoid floating point precision issues, and offset to unsigned v...
A set of nodes, ways and relations.
const Relation * relation(Id id) const
Find a relation by its id.
const Way * way(Id id) const
Find a way by its id.
const Node * node(Id id) const
Find a node by its id.
A reference to any of OSM::Node/OSM::Way/OSM::Relation.
bool hasTags() const
Returns whether or not this element has any tags set.
Pointer with the lower bits used for compact flag storage.
Languages in preference order to consider when looking up translated tag values.
A std::unique_ptr-like object for OSM element types.
Low-level types and functions to work with raw OSM data as efficiently as possible.
void setTagValue(Elem &elem, TagKey key, QByteArray &&value)
Inserts a new tag, or updates an existing one.
constexpr Element coalesce(Element e)
Utility function similar to SQL COALESCE for OSM::Element, ie.
Element lookupElement(const DataSet &dataSet, OSM::Type type, OSM::Id id)
Lookup element of given type and id in dataSet.
int64_t Id
OSM element identifier.
KOSM_EXPORT UniqueElement copy_element(Element e)
Creates a copy of element.
QByteArray tagValue(const Elem &elem, TagKey key)
Returns the tag value for key of elem.
void removeTag(Elem &elem, TagKey key)
Removes a tag from the given element.