From 2f019d4f5f7c2e330a1a166ed2df882d00394155 Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Mon, 1 Oct 2018 13:21:37 +0300 Subject: [PATCH] [generator] Style fixes for osm2type.cpp --- generator/osm2type.cpp | 116 +++++++++++++++++++++++++---------------- generator/osm2type.hpp | 1 + 2 files changed, 72 insertions(+), 45 deletions(-) diff --git a/generator/osm2type.cpp b/generator/osm2type.cpp index a534140465..585cde17c8 100644 --- a/generator/osm2type.cpp +++ b/generator/osm2type.cpp @@ -5,7 +5,6 @@ #include "indexer/classificator.hpp" #include "indexer/feature_impl.hpp" -#include "indexer/feature_visibility.hpp" #include "geometry/mercator.hpp" @@ -13,8 +12,6 @@ #include "base/stl_helpers.hpp" #include "base/string_utils.hpp" -#include -#include #include #include #include @@ -75,10 +72,10 @@ bool IgnoreTag(string const & k, string const & v) return false; } -template -TResult ForEachTag(OsmElement * p, ToDo && toDo) +template +Result ForEachTag(OsmElement * p, ToDo && toDo) { - TResult res = TResult(); + Result res = {}; for (auto & e : p->m_tags) { if (IgnoreTag(e.key, e.value)) @@ -91,20 +88,20 @@ TResult ForEachTag(OsmElement * p, ToDo && toDo) return res; } -template -TResult ForEachTagEx(OsmElement * p, set & skipTags, ToDo && toDo) +template +Result ForEachTagEx(OsmElement * p, set & skipTags, ToDo && toDo) { int id = 0; - return ForEachTag(p, [&](string const & k, string const & v) { + return ForEachTag(p, [&](string const & k, string const & v) { int currentId = id++; if (skipTags.count(currentId) != 0) - return TResult(); + return Result(); if (string::npos != k.find("name")) { skipTags.insert(currentId); - return TResult(); + return Result(); } - TResult res = toDo(k, v); + Result res = toDo(k, v); if (res) skipTags.insert(currentId); return res; @@ -113,9 +110,6 @@ TResult ForEachTagEx(OsmElement * p, set & skipTags, ToDo && toDo) class NamesExtractor { - set m_savedNames; - FeatureParams & m_params; - public: NamesExtractor(FeatureParams & params) : m_params(params) {} @@ -161,11 +155,18 @@ public: v.clear(); return false; } + +private: + set m_savedNames; + FeatureParams & m_params; }; class TagProcessor { - template +public: + TagProcessor(OsmElement * elem) : m_element(elem) {} + + template struct Rule { char const * key; @@ -173,24 +174,11 @@ class TagProcessor // ! - take only negative values // ~ - take only positive values char const * value; - function func; + function func; }; - static bool IsNegative(string const & value) - { - for (char const * s : {"no", "none", "false"}) - if (value == s) - return true; - return false; - } - - OsmElement * m_element; - -public: - TagProcessor(OsmElement * elem) : m_element(elem) {} - - template - void ApplyRules(initializer_list> const & rules) const + template + void ApplyRules(initializer_list> const & rules) const { for (auto & e : m_element->m_tags) { @@ -207,26 +195,36 @@ public: take = !IsNegative(e.value); if (take || e.value == rule.value) - call(rule.func, e.key, e.value); + Call(rule.func, e.key, e.value); } } } protected: - static void call(function const & f, string &, string &) { f(); } - static void call(function const & f, string & k, string & v) + static void Call(function const & f, string &, string &) { f(); } + static void Call(function const & f, string & k, string & v) { f(k, v); } + +private: + static bool IsNegative(string const & value) + { + for (char const * s : {"no", "none", "false"}) + { + if (value == s) + return true; + } + return false; + } + + OsmElement * m_element; }; -} // namespace class CachedTypes { - buffer_vector m_types; - public: - enum EType + enum Type { ENTRANCE, HIGHWAY, @@ -287,7 +285,7 @@ public: m_types.push_back(c.GetTypeByPath(e)); } - uint32_t Get(EType t) const { return m_types[t]; } + uint32_t Get(Type t) const { return m_types[t]; } bool IsHighway(uint32_t t) const { @@ -302,6 +300,9 @@ public: ftype::TruncValue(t, 3); return t == Get(RW_STATION_SUBWAY); } + +private: + buffer_vector m_types; }; void MatchTypes(OsmElement * p, FeatureParams & params, function filterDrawableType) @@ -359,11 +360,10 @@ void MatchTypes(OsmElement * p, FeatureParams & params, function { path.push_back(pObj); } - else + else if (!ForEachTagEx(p, skipRows, matchTagToClassificator)) { // If no - try find object by key (in case of k = "area", v = "yes"). - if (!ForEachTagEx(p, skipRows, matchTagToClassificator)) - break; + break; } } while (true); @@ -446,7 +446,7 @@ string MatchCity(OsmElement const * p) if (city.second.IsPointInside(pt)) return city.first; } - return string(); + return {}; } string DetermineSurface(OsmElement * p) @@ -469,7 +469,7 @@ string DetermineSurface(OsmElement * p) } if (!isHighway || (surface.empty() && smoothness.empty())) - return string(); + return {}; static base::StringIL pavedSurfaces = { "paved", "asphalt", "cobblestone", "cobblestone:flattened", "sett", @@ -487,28 +487,40 @@ string DetermineSurface(OsmElement * p) if (!surface.empty()) { for (auto const & value : pavedSurfaces) + { if (surface == value) isPaved = true; + } } else + { isPaved = smoothness == "excellent" || smoothness == "good"; + } if (!smoothness.empty()) { for (auto const & value : badSmoothness) + { if (smoothness == value) isGood = false; + } if (smoothness == "bad" && !isPaved) isGood = true; } else if (surface_grade == "0" || surface_grade == "1") + { isGood = false; + } else { if (surface_grade != "3") + { for (auto const & value : badSurfaces) + { if (surface == value) isGood = false; + } + } } string psurface = isPaved ? "paved_" : "unpaved_"; @@ -566,7 +578,9 @@ void PreprocessElement(OsmElement * p) p->AddTag("highway", "platform"); } else if (tag.value == "stop_position" && isTram && p->type == OsmElement::EntityType::Node) + { p->AddTag("railway", "tram_stop"); + } break; } } @@ -594,22 +608,33 @@ void PreprocessElement(OsmElement * p) } if (value == "blue_plaque" || value == "stolperstein") + { value = "plaque"; + } else if (value == "war_memorial" || value == "stele" || value == "obelisk" || value == "stone" || value == "cross") + { value = "sculpture"; + } else if (value == "bust" || value == "person") + { value = "statue"; + } }); p->UpdateTag("castle_type", [](string & value) { if (value.empty()) return; + if (value == "fortress" || value == "kremlin" || value == "castrum" || value == "shiro" || value == "citadel") + { value = "defensive"; + } else if (value == "manor" || value == "palace") + { value = "stately"; + } }); p->UpdateTag("attraction", [](string & value) { @@ -749,6 +774,7 @@ void PostprocessElement(OsmElement * p, FeatureParams & params) } } } +} // namespace void GetNameAndType(OsmElement * p, FeatureParams & params, function filterDrawableType) diff --git a/generator/osm2type.hpp b/generator/osm2type.hpp index 72a6782969..3ad74865da 100644 --- a/generator/osm2type.hpp +++ b/generator/osm2type.hpp @@ -3,6 +3,7 @@ #include "indexer/feature_data.hpp" #include "indexer/feature_visibility.hpp" +#include #include struct OsmElement;