Commit 4b2b7448 authored by Volker Krause's avatar Volker Krause
Browse files

Add a helper method to clone an OSM element

parent 7cf6e301
......@@ -257,3 +257,19 @@ void UniqueElement::setTagValue(TagKey key, const QByteArray &value)
break;
}
}
UniqueElement OSM::copy_element(Element e)
{
switch (e.type()) {
case OSM::Type::Null:
return UniqueElement();
case OSM::Type::Node:
return UniqueElement(new Node(*e.node()));
case OSM::Type::Way:
return UniqueElement(new Way(*e.way()));
case OSM::Type::Relation:
return UniqueElement(new Relation(*e.relation()));
}
Q_UNREACHABLE();
return UniqueElement();
}
......@@ -116,6 +116,8 @@ public:
return *this;
}
explicit inline operator bool() const { return m_element.type() != OSM::Type::Null; }
constexpr inline Element element() const { return m_element; }
constexpr inline operator Element() const { return m_element; }
......@@ -125,6 +127,8 @@ private:
Element m_element;
};
/** Creates a copy of @p element. */
KOSM_EXPORT UniqueElement copy_element(Element e);
/** Utility function similar to SQL COALESCE for OSM::Element, ie. this returns the first non-null element passed as argument. */
constexpr Element coalesce(Element e) { return e; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment