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...); }
145enum ForeachFlag : uint8_t {
146 IncludeRelations = 1,
149 IterateAll = IncludeRelations | IncludeWays | IncludeNodes,
152template <
typename Func>
153inline void for_each(
const DataSet &dataSet, Func func, uint8_t flags = IterateAll)
155 if (flags & IncludeRelations) {
156 for (
const auto &rel : dataSet.relations) {
160 if (flags & IncludeWays) {
161 for (
const auto &way : dataSet.ways) {
165 if (flags & IncludeNodes) {
166 for (
const auto &node : dataSet.nodes) {
167 func(Element(&node));
172template <
typename Func>
173inline void for_each_node(
const DataSet &dataSet,
const Way &way, Func func)
175 for (
auto nodeId : way.nodes) {
176 if (
auto node = dataSet.node(nodeId)) {
182template <
typename Func>
183inline void for_each_member(
const DataSet &dataSet,
const Relation &rel, Func func)
185 for (
const auto &mem : rel.members) {
186 switch (mem.type()) {
190 if (
auto node = dataSet.node(mem.id)) {
195 if (
auto way = dataSet.way(mem.id)) {
200 if (
auto rel = dataSet.relation(mem.id)) {
211struct std::hash<
OSM::Element>
215 std::size_t h1 = std::hash<OSM::Id>{}(e.id());
216 std::size_t h2 = std::hash<int>{}(qToUnderlying(e.type()));
217 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.
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.
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.