diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2019-06-11 15:14:43 +0300 |
---|---|---|
committer | Maksim Andrianov <maksimandrianov1@gmail.com> | 2019-06-11 15:25:19 +0300 |
commit | d6b67e8c34b83a9b9bfcf8955805597261a9ac9e (patch) | |
tree | 8c4ffb580356d3ab7c54f251c43f290f87398aff /generator | |
parent | bed9f4f01efd7adaff19f0a929bfc767dc6731a8 (diff) |
[generator][promo] review fixes
Diffstat (limited to 'generator')
-rw-r--r-- | generator/feature_merger.cpp | 25 | ||||
-rw-r--r-- | generator/feature_processing_layers.cpp | 16 | ||||
-rw-r--r-- | generator/feature_processing_layers.hpp | 2 | ||||
-rw-r--r-- | generator/generator_tool/CMakeLists.txt | 2 | ||||
-rw-r--r-- | generator/promo_catalog_cities.hpp | 43 |
5 files changed, 37 insertions, 51 deletions
diff --git a/generator/feature_merger.cpp b/generator/feature_merger.cpp index 703d86703b..516e27665d 100644 --- a/generator/feature_merger.cpp +++ b/generator/feature_merger.cpp @@ -336,20 +336,20 @@ class RemoveSolver bool m_doNotRemoveSponsoredTypes; public: - RemoveSolver(int lowScale, int upScale, bool leaveSpecialTypes, bool leaveSponsoredTypes = true) - : m_lowScale(lowScale), - m_upScale(upScale), - m_doNotRemoveSpecialTypes(leaveSpecialTypes), - m_doNotRemoveSponsoredTypes(leaveSponsoredTypes) + RemoveSolver(int lowScale, int upScale, bool doNotRemoveSpecialTypes, bool doNotRemoveSponsoredTypes) + : m_lowScale(lowScale) + , m_upScale(upScale) + , m_doNotRemoveSpecialTypes(doNotRemoveSpecialTypes) + , m_doNotRemoveSponsoredTypes(doNotRemoveSponsoredTypes) { } bool operator() (uint32_t type) const { - std::pair<int, int> const range = feature::GetDrawableScaleRange(type); - if (m_doNotRemoveSponsoredTypes && ftypes::IsSponsoredChecker::Instance()(type)) return false; + + std::pair<int, int> const range = feature::GetDrawableScaleRange(type); // We have feature types without any drawing rules. // This case was processed before: // - feature::TypeAlwaysExists; @@ -370,8 +370,11 @@ bool PreprocessForWorldMap(FeatureBuilder & fb) { int const upperScale = scales::GetUpperWorldScale(); - if (fb.RemoveTypesIf(RemoveSolver(0, upperScale, false))) + if (fb.RemoveTypesIf(RemoveSolver(0, upperScale, false /* doNotRemoveSpecialTypes */, + true /* doNotRemoveSponsoredTypes */))) + { return false; + } fb.RemoveNameIfInvisible(0, upperScale); @@ -382,8 +385,12 @@ bool PreprocessForCountryMap(FeatureBuilder & fb) { using namespace scales; - if (fb.RemoveTypesIf(RemoveSolver(GetUpperWorldScale() + 1, GetUpperStyleScale(), true))) + if (fb.RemoveTypesIf(RemoveSolver(GetUpperWorldScale() + 1, GetUpperStyleScale(), + true /* doNotRemoveSpecialTypes */, + true /* doNotRemoveSponsoredTypes */))) + { return false; + } return true; } diff --git a/generator/feature_processing_layers.cpp b/generator/feature_processing_layers.cpp index 6f5cb44bb7..b9e7a52ff4 100644 --- a/generator/feature_processing_layers.cpp +++ b/generator/feature_processing_layers.cpp @@ -245,8 +245,8 @@ void OpentableLayer::Handle(FeatureBuilder & feature) } -PromoCatalogLayer::PromoCatalogLayer(std::string const & filename) - : m_cities(promo::LoadCities(filename)) +PromoCatalogLayer::PromoCatalogLayer(std::string const & citiesFinename) + : m_cities(promo::LoadCities(citiesFinename)) { } @@ -254,18 +254,12 @@ void PromoCatalogLayer::Handle(FeatureBuilder & feature) { if (ftypes::IsCityTownOrVillage(feature.GetTypes())) { - auto const & ids = feature.GetOsmIds(); - - auto const found = std::any_of(ids.cbegin(), ids.cend(), [this](auto const & id) - { - return m_cities.find(id) != m_cities.cend(); - }); - - if (!found) + if (m_cities.find(feature.GetMostGenericOsmId()) == m_cities.cend()) return; + auto static const kPromoType = classif().GetTypeByPath({"sponsored", "promo_catalog"}); FeatureParams & params = feature.GetParams(); - params.AddType(classif().GetTypeByPath({"sponsored", "promo_catalog"})); + params.AddType(kPromoType); } LayerBase::Handle(feature); } diff --git a/generator/feature_processing_layers.hpp b/generator/feature_processing_layers.hpp index 8a1bfd869a..1f2f871d4a 100644 --- a/generator/feature_processing_layers.hpp +++ b/generator/feature_processing_layers.hpp @@ -163,7 +163,7 @@ private: class PromoCatalogLayer : public LayerBase { public: - explicit PromoCatalogLayer(std::string const & filename); + explicit PromoCatalogLayer(std::string const & citiesFinename); // LayerBase overrides: void Handle(feature::FeatureBuilder & feature) override; diff --git a/generator/generator_tool/CMakeLists.txt b/generator/generator_tool/CMakeLists.txt index 97063bdc66..6a81eca3bf 100644 --- a/generator/generator_tool/CMakeLists.txt +++ b/generator/generator_tool/CMakeLists.txt @@ -22,9 +22,7 @@ omim_link_libraries( search storage editor - partners_api indexer - metrics platform geometry coding diff --git a/generator/promo_catalog_cities.hpp b/generator/promo_catalog_cities.hpp index 3239156ada..f3fe2ffe93 100644 --- a/generator/promo_catalog_cities.hpp +++ b/generator/promo_catalog_cities.hpp @@ -16,40 +16,27 @@ using Cities = std::unordered_set<base::GeoObjectId>; inline Cities LoadCities(std::string const & filename) { - std::string src; - try - { - FileReader reader(filename); - reader.ReadAsString(src); - } - catch (Reader::Exception const & e) - { - LOG(LERROR, (filename, e.Msg())); + if (filename.empty()) return {}; - } - Cities result; - try - { - base::Json root(src.c_str()); - auto const dataArray = json_object_get(root.get(), "data"); + std::string src; + FileReader reader(filename); + reader.ReadAsString(src); - auto const size = json_array_size(dataArray); + Cities result; + base::Json root(src.c_str()); + auto const dataArray = json_object_get(root.get(), "data"); - result.reserve(size); - for (size_t i = 0; i < size; ++i) - { - int64_t id = 0; - auto const obj = json_array_get(dataArray, i); - FromJSONObject(obj, "osmid", id); + auto const size = json_array_size(dataArray); - result.emplace(static_cast<uint64_t>(id)); - } - } - catch (base::Json::Exception const & e) + result.reserve(size); + for (size_t i = 0; i < size; ++i) { - LOG(LERROR, (e.Msg())); - result.clear(); + int64_t id = 0; + auto const obj = json_array_get(dataArray, i); + FromJSONObject(obj, "osmid", id); + + result.emplace(static_cast<uint64_t>(id)); } return result; |