[generator:geo_object] Fix for review

This commit is contained in:
Anatoly Serdtcev 2019-04-18 13:24:27 +03:00 committed by mpimenov
parent 0fe64f033d
commit 015425a4b8
3 changed files with 21 additions and 14 deletions

View file

@ -108,24 +108,13 @@ std::unique_ptr<char, JSONFreeDeleter> StreetsBuilder::MakeStreetValue(
// static
bool StreetsBuilder::IsStreet(OsmElement const & element)
{
auto const & tags = element.Tags();
auto const hasName = std::any_of(std::cbegin(tags), std::cend(tags), [] (auto const & tag) {
return tag.key == "name";
});
if (!hasName)
if (element.GetTagValue("name", {}).empty())
return false;
auto const isHighway = std::any_of(std::cbegin(tags), std::cend(tags), [] (auto const & tag) {
return tag.key == "highway";
});
if (isHighway && (element.IsWay() || element.IsRelation()))
if (element.HasTag("highway") && (element.IsWay() || element.IsRelation()))
return true;
auto const isSquare = std::any_of(std::cbegin(tags), std::cend(tags), [] (auto const & tag) {
return tag.key == "place" && tag.value == "square";
});
if (isSquare)
if (element.HasTag("highway", "square"))
return true;
return false;

View file

@ -70,6 +70,13 @@ void OsmElement::AddTag(std::string_view const & k, std::string_view const & v)
m_tags.emplace_back(std::string{k}, std::move(value));
}
bool OsmElement::HasTag(std::string_view const & key) const
{
return std::any_of(m_tags.begin(), m_tags.end(), [&](auto const & t) {
return t.key == key;
});
}
bool OsmElement::HasTag(std::string_view const & k, std::string_view const & v) const
{
return std::any_of(m_tags.begin(), m_tags.end(), [&](auto const & t) {
@ -154,6 +161,15 @@ std::string OsmElement::GetTag(std::string const & key) const
return it == m_tags.cend() ? std::string() : it->value;
}
std::string_view OsmElement::GetTagValue(std::string_view const & key,
std::string_view const & defaultValue) const
{
auto const it = std::find_if(m_tags.cbegin(), m_tags.cend(),
[&key](Tag const & tag) { return tag.key == key; });
return it != m_tags.cend() ? it->value : defaultValue;
}
std::string DebugPrint(OsmElement const & e)
{
return e.ToString();

View file

@ -142,6 +142,7 @@ struct OsmElement
}
void AddTag(std::string_view const & k, std::string_view const & v);
bool HasTag(std::string_view const & key) const;
bool HasTag(std::string_view const & k, std::string_view const & v) const;
bool HasAnyTag(std::unordered_multimap<std::string, std::string> const & tags) const;
@ -164,6 +165,7 @@ struct OsmElement
}
std::string GetTag(std::string const & key) const;
std::string_view GetTagValue(std::string_view const & key, std::string_view const & defaultValue) const;
};
base::GeoObjectId GetGeoObjectId(OsmElement const & element);