diff options
author | tatiana-yan <tatiana.kondakova@gmail.com> | 2019-03-12 15:31:48 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2019-03-18 22:38:39 +0300 |
commit | f1c58fbfcc0fd0bbd98285734e9a2d9e4435a33d (patch) | |
tree | 9c1d71beb7bcb46a3a94e4e9990ed19e5358aa02 /search | |
parent | 2bf94c95dd55f70951a82b5c306b8a29a72a4180 (diff) |
[indexer] Disallow copy and move of FeatureType, remove FeatureType::ParseEverything().
Diffstat (limited to 'search')
-rw-r--r-- | search/cuisine_filter.cpp | 6 | ||||
-rw-r--r-- | search/downloader_search_callback.cpp | 8 | ||||
-rw-r--r-- | search/feature_loader.cpp | 5 | ||||
-rw-r--r-- | search/feature_loader.hpp | 2 | ||||
-rw-r--r-- | search/features_layer_matcher.cpp | 6 | ||||
-rw-r--r-- | search/features_layer_matcher.hpp | 79 | ||||
-rw-r--r-- | search/geocoder.cpp | 63 | ||||
-rw-r--r-- | search/hotels_filter.cpp | 6 | ||||
-rw-r--r-- | search/house_detector.cpp | 10 | ||||
-rw-r--r-- | search/locality_finder.cpp | 16 | ||||
-rw-r--r-- | search/mwm_context.cpp | 16 | ||||
-rw-r--r-- | search/mwm_context.hpp | 8 | ||||
-rw-r--r-- | search/ranker.cpp | 46 | ||||
-rw-r--r-- | search/retrieval.cpp | 6 | ||||
-rw-r--r-- | search/search_integration_tests/processor_test.cpp | 12 | ||||
-rw-r--r-- | search/search_quality/assessment_tool/context.cpp | 6 | ||||
-rw-r--r-- | search/search_quality/assessment_tool/main_model.cpp | 12 | ||||
-rw-r--r-- | search/search_quality/assessment_tool/main_view.cpp | 8 | ||||
-rw-r--r-- | search/search_quality/matcher.cpp | 6 | ||||
-rw-r--r-- | search/search_tests_support/test_with_custom_mwms.hpp | 6 | ||||
-rw-r--r-- | search/street_vicinity_loader.cpp | 18 | ||||
-rw-r--r-- | search/street_vicinity_loader.hpp | 6 |
22 files changed, 181 insertions, 170 deletions
diff --git a/search/cuisine_filter.cpp b/search/cuisine_filter.cpp index e736ff3f42..ae17df3b50 100644 --- a/search/cuisine_filter.cpp +++ b/search/cuisine_filter.cpp @@ -104,9 +104,9 @@ CuisineFilter::Descriptions const & CuisineFilter::GetDescriptions(MwmContext co auto & descriptions = m_descriptions[mwmId]; food.ForEach([&descriptions, &context, &loadFromMetadata](uint64_t bit) { auto const id = base::asserted_cast<uint32_t>(bit); - FeatureType ft; - if (context.GetFeature(id, ft)) - descriptions.emplace_back(id, Description(ft, loadFromMetadata)); + auto ft = context.GetFeature(id); + if (ft) + descriptions.emplace_back(id, Description(*ft, loadFromMetadata)); }); return descriptions; } diff --git a/search/downloader_search_callback.cpp b/search/downloader_search_callback.cpp index f770535ca5..b155049a8b 100644 --- a/search/downloader_search_callback.cpp +++ b/search/downloader_search_callback.cpp @@ -64,19 +64,19 @@ void DownloaderSearchCallback::operator()(search::Results const & results) { FeatureID const & fid = result.GetFeatureID(); FeaturesLoaderGuard loader(m_dataSource, fid.m_mwmId); - FeatureType ft; - if (!loader.GetFeatureByIndex(fid.m_index, ft)) + auto ft = loader.GetFeatureByIndex(fid.m_index); + if (!ft) { LOG(LERROR, ("Feature can't be loaded:", fid)); continue; } - ftypes::Type const type = ftypes::IsLocalityChecker::Instance().GetType(ft); + ftypes::Type const type = ftypes::IsLocalityChecker::Instance().GetType(*ft); if (type == ftypes::COUNTRY || type == ftypes::STATE) { std::string groupFeatureName; - if (GetGroupCountryIdFromFeature(m_storage, ft, groupFeatureName)) + if (GetGroupCountryIdFromFeature(m_storage, *ft, groupFeatureName)) { storage::DownloaderSearchResult downloaderResult(groupFeatureName, result.GetString() /* m_matchedName */); diff --git a/search/feature_loader.cpp b/search/feature_loader.cpp index 0529f246f3..dbb002cde5 100644 --- a/search/feature_loader.cpp +++ b/search/feature_loader.cpp @@ -2,20 +2,21 @@ #include "editor/editable_data_source.hpp" +#include "indexer/feature.hpp" #include "indexer/feature_decl.hpp" namespace search { FeatureLoader::FeatureLoader(DataSource const & dataSource) : m_dataSource(dataSource) {} -bool FeatureLoader::Load(FeatureID const & id, FeatureType & ft) +std::unique_ptr<FeatureType> FeatureLoader::Load(FeatureID const & id) { ASSERT(m_checker.CalledOnOriginalThread(), ()); auto const & mwmId = id.m_mwmId; if (!m_guard || m_guard->GetId() != mwmId) m_guard = std::make_unique<FeaturesLoaderGuard>(m_dataSource, mwmId); - return m_guard->GetFeatureByIndex(id.m_index, ft); + return m_guard->GetFeatureByIndex(id.m_index); } void FeatureLoader::Reset() diff --git a/search/feature_loader.hpp b/search/feature_loader.hpp index a3050ae17b..a24daa64ba 100644 --- a/search/feature_loader.hpp +++ b/search/feature_loader.hpp @@ -20,7 +20,7 @@ class FeatureLoader public: explicit FeatureLoader(DataSource const & dataSource); - WARN_UNUSED_RESULT bool Load(FeatureID const & id, FeatureType & ft); + std::unique_ptr<FeatureType> Load(FeatureID const & id); void Reset(); diff --git a/search/features_layer_matcher.cpp b/search/features_layer_matcher.cpp index 49ec9d61b1..050d4c22c5 100644 --- a/search/features_layer_matcher.cpp +++ b/search/features_layer_matcher.cpp @@ -57,11 +57,11 @@ uint32_t FeaturesLayerMatcher::GetMatchingStreet(uint32_t houseId) if (!entry.second) return entry.first; - FeatureType feature; - if (!GetByIndex(houseId, feature)) + auto feature = GetByIndex(houseId); + if (!feature) return kInvalidId; - return GetMatchingStreet(feature); + return GetMatchingStreet(*feature); } FeaturesLayerMatcher::Streets const & FeaturesLayerMatcher::GetNearbyStreets(FeatureType & feature) diff --git a/search/features_layer_matcher.hpp b/search/features_layer_matcher.hpp index 574e3119ed..a584d6ddf1 100644 --- a/search/features_layer_matcher.hpp +++ b/search/features_layer_matcher.hpp @@ -34,6 +34,7 @@ #include <cstdint> #include <functional> #include <limits> +#include <memory> #include <unordered_map> #include <utility> #include <vector> @@ -122,29 +123,30 @@ private: for (size_t i = 0; i < pois.size(); ++i) { - FeatureType poiFt; - if (GetByIndex(pois[i], poiFt)) - poiCenters.emplace_back(feature::GetCenter(poiFt, FeatureType::WORST_GEOMETRY), i /* id */); + auto poiFt = GetByIndex(pois[i]); + if (poiFt) + poiCenters.emplace_back(feature::GetCenter(*poiFt, FeatureType::WORST_GEOMETRY), + i /* id */); } std::vector<PointRectMatcher::RectIdPair> buildingRects; buildingRects.reserve(buildings.size()); for (size_t i = 0; i < buildings.size(); ++i) { - FeatureType buildingFt; - if (!GetByIndex(buildings[i], buildingFt)) + auto buildingFt = GetByIndex(buildings[i]); + if (!buildingFt) continue; - if (buildingFt.GetFeatureType() == feature::GEOM_POINT) + if (buildingFt->GetFeatureType() == feature::GEOM_POINT) { - auto const center = feature::GetCenter(buildingFt, FeatureType::WORST_GEOMETRY); + auto const center = feature::GetCenter(*buildingFt, FeatureType::WORST_GEOMETRY); buildingRects.emplace_back( MercatorBounds::RectByCenterXYAndSizeInMeters(center, kBuildingRadiusMeters), i /* id */); } else { - buildingRects.emplace_back(buildingFt.GetLimitRect(FeatureType::WORST_GEOMETRY), + buildingRects.emplace_back(buildingFt->GetLimitRect(FeatureType::WORST_GEOMETRY), i /* id */); } } @@ -202,9 +204,10 @@ private: for (size_t i = 0; i < pois.size(); ++i) { - FeatureType poiFt; - if (GetByIndex(pois[i], poiFt)) - poiCenters.emplace_back(feature::GetCenter(poiFt, FeatureType::WORST_GEOMETRY), i /* id */); + auto poiFt = GetByIndex(pois[i]); + if (poiFt) + poiCenters.emplace_back(feature::GetCenter(*poiFt, FeatureType::WORST_GEOMETRY), + i /* id */); } std::vector<PointRectMatcher::RectIdPair> streetRects; @@ -215,33 +218,33 @@ private: for (size_t i = 0; i < streets.size(); ++i) { - FeatureType streetFt; - if (!GetByIndex(streets[i], streetFt)) + auto streetFt = GetByIndex(streets[i]); + if (!streetFt) continue; - streetFt.ParseGeometry(FeatureType::WORST_GEOMETRY); + streetFt->ParseGeometry(FeatureType::WORST_GEOMETRY); m2::RectD inflationRect; // Any point is good enough here, and feature::GetCenter would re-read the geometry. - if (streetFt.GetPointsCount() > 0) + if (streetFt->GetPointsCount() > 0) { - inflationRect = MercatorBounds::RectByCenterXYAndSizeInMeters(streetFt.GetPoint(0), + inflationRect = MercatorBounds::RectByCenterXYAndSizeInMeters(streetFt->GetPoint(0), 0.5 * kStreetRadiusMeters); } - for (size_t j = 0; j + 1 < streetFt.GetPointsCount(); ++j) + for (size_t j = 0; j + 1 < streetFt->GetPointsCount(); ++j) { - auto const & p1 = streetFt.GetPoint(j); - auto const & p2 = streetFt.GetPoint(j + 1); + auto const & p1 = streetFt->GetPoint(j); + auto const & p2 = streetFt->GetPoint(j + 1); m2::RectD rect(p1, p2); rect.Inflate(inflationRect.SizeX(), inflationRect.SizeY()); streetRects.emplace_back(rect, i /* id */); } std::vector<m2::PointD> streetPoints; - streetPoints.reserve(streetFt.GetPointsCount()); - for (size_t j = 0; j < streetFt.GetPointsCount(); ++j) - streetPoints.emplace_back(streetFt.GetPoint(j)); + streetPoints.reserve(streetFt->GetPointsCount()); + for (size_t j = 0; j < streetFt->GetPointsCount(); ++j) + streetPoints.emplace_back(streetFt->GetPoint(j)); streetProjectors.emplace_back(streetPoints); } @@ -289,7 +292,8 @@ private: ParseQuery(child.m_subQuery, child.m_lastTokenIsPrefix, queryParse); uint32_t numFilterInvocations = 0; - auto houseNumberFilter = [&](uint32_t id, FeatureType & feature, bool & loaded) -> bool { + auto houseNumberFilter = [&](uint32_t id, std::unique_ptr<FeatureType> & feature, + bool & loaded) -> bool { ++numFilterInvocations; if ((numFilterInvocations & 0xFF) == 0) BailIfCancelled(m_cancellable); @@ -301,7 +305,10 @@ private: return false; if (!loaded) - loaded = GetByIndex(id, feature); + { + feature = GetByIndex(id); + loaded = feature != nullptr; + } if (!loaded) return false; @@ -309,12 +316,13 @@ private: if (!child.m_hasDelayedFeatures) return false; - strings::UniString const houseNumber(strings::MakeUniString(feature.GetHouseNumber())); + strings::UniString const houseNumber(strings::MakeUniString(feature->GetHouseNumber())); return house_numbers::HouseNumbersMatch(houseNumber, queryParse); }; std::unordered_map<uint32_t, bool> cache; - auto cachingHouseNumberFilter = [&](uint32_t id, FeatureType & feature, bool & loaded) -> bool { + auto cachingHouseNumberFilter = [&](uint32_t id, std::unique_ptr<FeatureType> & feature, + bool & loaded) -> bool { auto const it = cache.find(id); if (it != cache.cend()) return it->second; @@ -333,15 +341,18 @@ private: for (uint32_t houseId : street.m_features) { - FeatureType feature; + std::unique_ptr<FeatureType> feature; bool loaded = false; if (!cachingHouseNumberFilter(houseId, feature, loaded)) continue; - if (!loaded && !GetByIndex(houseId, feature)) + if (!loaded) + feature = GetByIndex(houseId); + + if (!feature) continue; - if (GetMatchingStreet(feature) == streetId) + if (GetMatchingStreet(*feature) == streetId) fn(houseId, streetId); } } @@ -357,16 +368,16 @@ private: Streets const & GetNearbyStreets(FeatureType & feature); - inline bool GetByIndex(uint32_t id, FeatureType & ft) const + std::unique_ptr<FeatureType> GetByIndex(uint32_t id) const { /// @todo Add Cache for feature id -> (point, name / house number). - if (m_context->GetFeature(id, ft)) - return true; + auto res = m_context->GetFeature(id); // It may happen to features deleted by the editor. We do not get them from EditableDataSource // but we still have ids of these features in the search index. - LOG(LWARNING, ("GetFeature() returned false.", id)); - return false; + if (!res) + LOG(LWARNING, ("GetFeature() returned false.", id)); + return res; } MwmContext * m_context; diff --git a/search/geocoder.cpp b/search/geocoder.cpp index b6d1e41854..e3d650c6b0 100644 --- a/search/geocoder.cpp +++ b/search/geocoder.cpp @@ -169,13 +169,13 @@ public: // LocalityScorer::Delegate overrides: void GetNames(uint32_t featureId, vector<string> & names) const override { - FeatureType ft; - if (!m_context.GetFeature(featureId, ft)) + auto ft = m_context.GetFeature(featureId); + if (!ft) return; for (auto const lang : m_params.GetLangs()) { string name; - if (ft.GetName(lang, name)) + if (ft->GetName(lang, name)) names.push_back(name); } } @@ -634,22 +634,21 @@ void Geocoder::FillLocalitiesTable(BaseContext const & ctx) size_t numCountries = 0; for (auto & l : preLocalities) { - FeatureType ft; - if (!m_context->GetFeature(l.m_featureId, ft)) + auto ft = m_context->GetFeature(l.m_featureId); + if (!ft) continue; - auto addRegionMaps = [&](size_t maxCount, Region::Type type, size_t & count) - { - if (count < maxCount && ft.GetFeatureType() == feature::GEOM_POINT) + auto addRegionMaps = [&](size_t maxCount, Region::Type type, size_t & count) { + if (count < maxCount && ft->GetFeatureType() == feature::GEOM_POINT) { string affiliation; - if (!GetAffiliationName(ft, affiliation)) + if (!GetAffiliationName(*ft, affiliation)) return; Region region(l, type); - region.m_center = ft.GetCenter(); + region.m_center = ft->GetCenter(); - ft.GetName(StringUtf8Multilang::kDefaultCode, region.m_defaultName); + ft->GetName(StringUtf8Multilang::kDefaultCode, region.m_defaultName); LOG(LDEBUG, ("Region =", region.m_defaultName)); m_infoGetter.GetMatchedRegions(affiliation, region.m_ids); @@ -664,11 +663,11 @@ void Geocoder::FillLocalitiesTable(BaseContext const & ctx) } }; - switch (m_model.GetType(ft)) + switch (m_model.GetType(*ft)) { case Model::TYPE_CITY: { - if (numCities < kMaxNumCities && ft.GetFeatureType() == feature::GEOM_POINT) + if (numCities < kMaxNumCities && ft->GetFeatureType() == feature::GEOM_POINT) { ++numCities; @@ -676,7 +675,7 @@ void Geocoder::FillLocalitiesTable(BaseContext const & ctx) CitiesBoundariesTable::Boundaries boundaries; bool haveBoundary = false; - if (m_citiesBoundaries.Get(ft.GetID(), boundaries)) + if (m_citiesBoundaries.Get(ft->GetID(), boundaries)) { city.m_rect = boundaries.GetLimitRect(); if (city.m_rect.IsValid()) @@ -685,14 +684,14 @@ void Geocoder::FillLocalitiesTable(BaseContext const & ctx) if (!haveBoundary) { - auto const center = feature::GetCenter(ft); - auto const population = ftypes::GetPopulation(ft); + auto const center = feature::GetCenter(*ft); + auto const population = ftypes::GetPopulation(*ft); auto const radius = ftypes::GetRadiusByPopulation(population); city.m_rect = MercatorBounds::RectByCenterXYAndSizeInMeters(center, radius); } #if defined(DEBUG) - ft.GetName(StringUtf8Multilang::kDefaultCode, city.m_defaultName); + ft->GetName(StringUtf8Multilang::kDefaultCode, city.m_defaultName); LOG(LINFO, ("City =", city.m_defaultName, "rect =", city.m_rect, "rect source:", haveBoundary ? "table" : "population", "sizeX =", @@ -729,24 +728,24 @@ void Geocoder::FillVillageLocalities(BaseContext const & ctx) for (auto & l : preLocalities) { - FeatureType ft; - if (!m_context->GetFeature(l.m_featureId, ft)) + auto ft = m_context->GetFeature(l.m_featureId); + if (!ft) continue; - if (m_model.GetType(ft) != Model::TYPE_VILLAGE) + if (m_model.GetType(*ft) != Model::TYPE_VILLAGE) continue; // We accept lines and areas as village features. - auto const center = feature::GetCenter(ft); + auto const center = feature::GetCenter(*ft); ++numVillages; City village(l, Model::TYPE_VILLAGE); - auto const population = ftypes::GetPopulation(ft); + auto const population = ftypes::GetPopulation(*ft); auto const radius = ftypes::GetRadiusByPopulation(population); village.m_rect = MercatorBounds::RectByCenterXYAndSizeInMeters(center, radius); #if defined(DEBUG) - ft.GetName(StringUtf8Multilang::kDefaultCode, village.m_defaultName); + ft->GetName(StringUtf8Multilang::kDefaultCode, village.m_defaultName); LOG(LDEBUG, ("Village =", village.m_defaultName, "radius =", radius)); #endif @@ -1313,11 +1312,11 @@ void Geocoder::TraceResult(Tracer & tracer, BaseContext const & ctx, MwmSet::Mwm if (mwmId != m_context->GetId()) return; - FeatureType ft; - if (!m_context->GetFeature(ftId, ft)) + auto ft = m_context->GetFeature(ftId); + if (!ft) return; - feature::TypesHolder holder(ft); + feature::TypesHolder holder(*ft); CategoriesInfo catInfo(holder, TokenSlice(m_params, tokenRange), m_params.m_categoryLocales, m_categories); @@ -1463,14 +1462,12 @@ bool Geocoder::GetTypeInGeocoding(BaseContext const & ctx, uint32_t featureId, M return true; } - FeatureType feature; - if (m_context->GetFeature(featureId, feature)) - { - type = m_model.GetType(feature); - return true; - } + auto feature = m_context->GetFeature(featureId); + if (!feature) + return false; - return false; + type = m_model.GetType(*feature); + return true; } } // namespace search diff --git a/search/hotels_filter.cpp b/search/hotels_filter.cpp index 04f15ff0ea..b0c35698e7 100644 --- a/search/hotels_filter.cpp +++ b/search/hotels_filter.cpp @@ -116,11 +116,11 @@ HotelsFilter::Descriptions const & HotelsFilter::GetDescriptions(MwmContext cons auto & descriptions = m_descriptions[mwmId]; hotels.ForEach([&descriptions, &context](uint64_t bit) { auto const id = base::asserted_cast<uint32_t>(bit); - FeatureType ft; Description description; - if (context.GetFeature(id, ft)) - description.FromFeature(ft); + auto ft = context.GetFeature(id); + if (ft) + description.FromFeature(*ft); descriptions.emplace_back(id, description); }); return descriptions; diff --git a/search/house_detector.cpp b/search/house_detector.cpp index abaa22b71f..8f807433c9 100644 --- a/search/house_detector.cpp +++ b/search/house_detector.cpp @@ -887,18 +887,18 @@ int HouseDetector::LoadStreets(vector<FeatureID> const & ids) if (m_id2st.find(ids[i]) != m_id2st.end()) continue; - FeatureType f; - if (!m_loader.Load(ids[i], f)) + auto f = m_loader.Load(ids[i]); + if (!f) { LOG(LWARNING, ("Can't read feature from:", ids[i].m_mwmId)); continue; } - if (f.GetFeatureType() == feature::GEOM_LINE) + if (f->GetFeatureType() == feature::GEOM_LINE) { // Use default name as a primary compare key for merging. string name; - if (!f.GetName(StringUtf8Multilang::kDefaultCode, name)) + if (!f->GetName(StringUtf8Multilang::kDefaultCode, name)) continue; ASSERT(!name.empty(), ()); @@ -906,7 +906,7 @@ int HouseDetector::LoadStreets(vector<FeatureID> const & ids) Street * st = new Street(); st->SetName(name); - f.ForEachPoint(StreetCreator(st), FeatureType::BEST_GEOMETRY); + f->ForEachPoint(StreetCreator(st), FeatureType::BEST_GEOMETRY); if (m_end2st.empty()) { diff --git a/search/locality_finder.cpp b/search/locality_finder.cpp index 8f9f0d932f..c6c855f36a 100644 --- a/search/locality_finder.cpp +++ b/search/locality_finder.cpp @@ -76,15 +76,15 @@ public: if (m_loadedIds.count(id) != 0) return; - FeatureType ft; - if (!m_ctx.GetFeature(id, ft)) + auto ft = m_ctx.GetFeature(id); + if (!ft) return; - if (ft.GetFeatureType() != feature::GEOM_POINT) + if (ft->GetFeatureType() != feature::GEOM_POINT) return; using namespace ftypes; - switch (IsLocalityChecker::Instance().GetType(ft)) + switch (IsLocalityChecker::Instance().GetType(*ft)) { case CITY: case TOWN: @@ -94,15 +94,15 @@ public: return; } - auto const population = ftypes::GetPopulation(ft); + auto const population = ftypes::GetPopulation(*ft); if (population == 0) return; - auto const names = ft.GetNames(); - auto const center = ft.GetCenter(); + auto const names = ft->GetNames(); + auto const center = ft->GetCenter(); CitiesBoundariesTable::Boundaries boundaries; - auto const fid = ft.GetID(); + auto const fid = ft->GetID(); m_boundaries.Get(fid, boundaries); m_holder.Add(LocalityItem(names, center, boundaries, population, fid)); diff --git a/search/mwm_context.cpp b/search/mwm_context.cpp index f32c153dd0..b42726f078 100644 --- a/search/mwm_context.cpp +++ b/search/mwm_context.cpp @@ -22,21 +22,23 @@ MwmContext::MwmContext(MwmSet::MwmHandle handle) { } -bool MwmContext::GetFeature(uint32_t index, FeatureType & ft) const +std::unique_ptr<FeatureType> MwmContext::GetFeature(uint32_t index) const { + std::unique_ptr<FeatureType> ft; switch (GetEditedStatus(index)) { case FeatureStatus::Deleted: case FeatureStatus::Obsolete: - return false; + return ft; case FeatureStatus::Modified: case FeatureStatus::Created: - VERIFY(osm::Editor::Instance().GetEditedFeature(GetId(), index, ft), ()); - return true; + ft = osm::Editor::Instance().GetEditedFeature(FeatureID(GetId(), index)); + CHECK(ft, ()); + return ft; case FeatureStatus::Untouched: - m_vector.GetByIndex(index, ft); - ft.SetID(FeatureID(GetId(), index)); - return true; + ft = m_vector.GetByIndex(index); + ft->SetID(FeatureID(GetId(), index)); + return ft; } UNREACHABLE(); } diff --git a/search/mwm_context.hpp b/search/mwm_context.hpp index 51d6bb5fdc..1489e04ee2 100644 --- a/search/mwm_context.hpp +++ b/search/mwm_context.hpp @@ -64,14 +64,14 @@ public: CoverRect(rect, scale, intervals); ForEachIndexImpl(intervals, scale, [&](uint32_t index) { - FeatureType ft; - if (GetFeature(index, ft)) - fn(ft); + auto ft = GetFeature(index); + if (ft) + fn(*ft); }); } // Returns false if feature was deleted by user. - WARN_UNUSED_RESULT bool GetFeature(uint32_t index, FeatureType & ft) const; + std::unique_ptr<FeatureType> GetFeature(uint32_t index) const; WARN_UNUSED_RESULT inline bool GetCenter(uint32_t index, m2::PointD & center) { diff --git a/search/ranker.cpp b/search/ranker.cpp index 0fd446290d..07e0f6c8e2 100644 --- a/search/ranker.cpp +++ b/search/ranker.cpp @@ -256,26 +256,26 @@ class RankerResultMaker unique_ptr<FeaturesLoaderGuard> m_loader; - bool LoadFeature(FeatureID const & id, FeatureType & ft) + unique_ptr<FeatureType> LoadFeature(FeatureID const & id) { if (!m_loader || m_loader->GetId() != id.m_mwmId) m_loader = make_unique<FeaturesLoaderGuard>(m_dataSource, id.m_mwmId); - if (!m_loader->GetFeatureByIndex(id.m_index, ft)) - return false; - - ft.SetID(id); - return true; + auto ft = m_loader->GetFeatureByIndex(id.m_index); + if (ft) + ft->SetID(id); + return ft; } // For the best performance, incoming ids should be sorted by id.first (mwm file id). - bool LoadFeature(FeatureID const & id, FeatureType & ft, m2::PointD & center, string & name, - string & country) + unique_ptr<FeatureType> LoadFeature(FeatureID const & id, m2::PointD & center, string & name, + string & country) { - if (!LoadFeature(id, ft)) - return false; + auto ft = LoadFeature(id); + if (!ft) + return ft; - center = feature::GetCenter(ft); - m_ranker.GetBestMatchName(ft, name); + center = feature::GetCenter(*ft); + m_ranker.GetBestMatchName(*ft, name); // Country (region) name is a file name if feature isn't from // World.mwm. @@ -285,7 +285,7 @@ class RankerResultMaker else country = m_loader->GetCountryFileName(); - return true; + return ft; } void InitRankingInfo(FeatureType & ft, m2::PointD const & center, PreRankerResult const & res, @@ -316,12 +316,12 @@ class RankerResultMaker preInfo.m_geoParts.m_street != IntersectionResult::kInvalidId) { auto const & mwmId = ft.GetID().m_mwmId; - FeatureType street; - if (LoadFeature(FeatureID(mwmId, preInfo.m_geoParts.m_street), street)) + auto street = LoadFeature(FeatureID(mwmId, preInfo.m_geoParts.m_street)); + if (street) { auto const type = Model::TYPE_STREET; auto const & range = preInfo.m_tokenRange[type]; - auto const nameScores = GetNameScores(street, m_params, range, type); + auto const nameScores = GetNameScores(*street, m_params, range, type); nameScore = min(nameScore, nameScores.m_nameScore); errorsMade += nameScores.m_errorsMade; @@ -330,12 +330,12 @@ class RankerResultMaker if (!Model::IsLocalityType(info.m_type) && preInfo.m_cityId.IsValid()) { - FeatureType city; - if (LoadFeature(preInfo.m_cityId, city)) + auto city = LoadFeature(preInfo.m_cityId); + if (city) { auto const type = Model::TYPE_CITY; auto const & range = preInfo.m_tokenRange[type]; - errorsMade += GetErrorsMade(city, m_params, range, type); + errorsMade += GetErrorsMade(*city, m_params, range, type); } } @@ -386,18 +386,18 @@ public: boost::optional<RankerResult> operator()(PreRankerResult const & preRankerResult) { - FeatureType ft; m2::PointD center; string name; string country; - if (!LoadFeature(preRankerResult.GetId(), ft, center, name, country)) + auto ft = LoadFeature(preRankerResult.GetId(), center, name, country); + if (!ft) return {}; - RankerResult r(ft, center, m_ranker.m_params.m_pivot, name, country); + RankerResult r(*ft, center, m_ranker.m_params.m_pivot, name, country); search::RankingInfo info; - InitRankingInfo(ft, center, preRankerResult, info); + InitRankingInfo(*ft, center, preRankerResult, info); info.m_rank = NormalizeRank(info.m_rank, info.m_type, center, country); r.SetRankingInfo(move(info)); r.m_provenance = move(preRankerResult.GetProvenance()); diff --git a/search/retrieval.cpp b/search/retrieval.cpp index 38d0795239..0116b51361 100644 --- a/search/retrieval.cpp +++ b/search/retrieval.cpp @@ -98,9 +98,9 @@ private: auto & editor = Editor::Instance(); for (auto const index : features) { - FeatureType ft; - VERIFY(editor.GetEditedFeature(m_id, index, ft), ()); - fn(ft, index); + auto ft = editor.GetEditedFeature(FeatureID(m_id, index)); + CHECK(ft, ()); + fn(*ft, index); } } diff --git a/search/search_integration_tests/processor_test.cpp b/search/search_integration_tests/processor_test.cpp index e61d7c62b0..a2f64e1b63 100644 --- a/search/search_integration_tests/processor_test.cpp +++ b/search/search_integration_tests/processor_test.cpp @@ -692,11 +692,11 @@ UNIT_CLASS_TEST(ProcessorTest, TestPostcodes) ++index; FeaturesLoaderGuard loader(m_dataSource, countryId); - FeatureType ft; - TEST(loader.GetFeatureByIndex(base::checked_cast<uint32_t>(index), ft), ()); + auto ft = loader.GetFeatureByIndex(base::checked_cast<uint32_t>(index)); + TEST(ft, ()); auto rule = ExactMatch(countryId, building31); - TEST(rule->Matches(ft), ()); + TEST(rule->Matches(*ft), ()); } { @@ -789,12 +789,12 @@ UNIT_CLASS_TEST(ProcessorTest, TestCategories) for (auto const & result : request->Results()) { FeaturesLoaderGuard loader(m_dataSource, wonderlandId); - FeatureType ft; - TEST(loader.GetFeatureByIndex(result.GetFeatureID().m_index, ft), ()); + auto ft = loader.GetFeatureByIndex(result.GetFeatureID().m_index); + TEST(ft, ()); auto const & info = result.GetRankingInfo(); - if (busStop.Matches(ft)) + if (busStop.Matches(*ft)) { TEST(!info.m_pureCats, (result)); TEST(info.m_falseCats, (result)); diff --git a/search/search_quality/assessment_tool/context.cpp b/search/search_quality/assessment_tool/context.cpp index 9507febd28..ec02b87313 100644 --- a/search/search_quality/assessment_tool/context.cpp +++ b/search/search_quality/assessment_tool/context.cpp @@ -89,9 +89,9 @@ search::Sample Context::MakeSample(search::FeatureLoader & loader) const if (result.GetResultType() != search::Result::Type::Feature) continue; - FeatureType ft; - CHECK(loader.Load(result.GetFeatureID(), ft), ()); - outResults.push_back(search::Sample::Result::Build(ft, *foundEntries[i].m_curr)); + auto ft = loader.Load(result.GetFeatureID()); + CHECK(ft, ()); + outResults.push_back(search::Sample::Result::Build(*ft, *foundEntries[i].m_curr)); } return outSample; diff --git a/search/search_quality/assessment_tool/main_model.cpp b/search/search_quality/assessment_tool/main_model.cpp index a05ac13f4a..e25a736d8f 100644 --- a/search/search_quality/assessment_tool/main_model.cpp +++ b/search/search_quality/assessment_tool/main_model.cpp @@ -290,9 +290,9 @@ void MainModel::AddNonFoundResult(FeatureID const & id) if (resurrected) return; - FeatureType ft; - CHECK(m_loader.Load(id, ft), ("Can't load feature:", id)); - auto const result = search::Sample::Result::Build(ft, search::Sample::Result::Relevance::Vital); + auto ft = m_loader.Load(id); + CHECK(ft, ("Can't load feature:", id)); + auto const result = search::Sample::Result::Build(*ft, search::Sample::Result::Relevance::Vital); context.AddNonFoundResult(result); } @@ -429,8 +429,8 @@ void MainModel::ForAnyMatchingEntry(Context & context, FeatureID const & id, Fn return fn(context.m_foundResultsEdits, i); } - FeatureType ft; - CHECK(m_loader.Load(id, ft), ("Can't load feature:", id)); + auto ft = m_loader.Load(id); + CHECK(ft, ("Can't load feature:", id)); search::Matcher matcher(m_loader); auto const & nonFoundResults = context.m_nonFoundResults; @@ -438,7 +438,7 @@ void MainModel::ForAnyMatchingEntry(Context & context, FeatureID const & id, Fn for (size_t i = 0; i < nonFoundResults.size(); ++i) { auto const & result = context.m_nonFoundResults[i]; - if (matcher.Matches(result, ft)) + if (matcher.Matches(result, *ft)) return fn(context.m_nonFoundResultsEdits, i); } } diff --git a/search/search_quality/assessment_tool/main_view.cpp b/search/search_quality/assessment_tool/main_view.cpp index 5b73db11dd..267320c748 100644 --- a/search/search_quality/assessment_tool/main_view.cpp +++ b/search/search_quality/assessment_tool/main_view.cpp @@ -61,12 +61,12 @@ MainView::MainView(Framework & framework) : m_framework(framework) return; } - FeatureType ft; - if (!m_framework.GetFeatureByID(selectedFeature, ft)) + auto ft = m_framework.GetFeatureByID(selectedFeature); + if (!ft) return; - auto const address = m_framework.GetAddressAtPoint(feature::GetCenter(ft)); - FeatureInfoDialog dialog(this /* parent */, ft, address, m_sampleLocale); + auto const address = m_framework.GetAddressAtPoint(feature::GetCenter(*ft)); + FeatureInfoDialog dialog(this /* parent */, *ft, address, m_sampleLocale); dialog.exec(); }, [this](bool /* switchFullScreenMode */) { m_selectedFeature = FeatureID(); }); diff --git a/search/search_quality/matcher.cpp b/search/search_quality/matcher.cpp index 3a4221232f..f490c587a1 100644 --- a/search/search_quality/matcher.cpp +++ b/search/search_quality/matcher.cpp @@ -90,10 +90,10 @@ bool Matcher::Matches(Sample::Result const & golden, search::Result const & actu if (actual.GetResultType() != Result::Type::Feature) return false; - FeatureType ft; - if (!m_loader.Load(actual.GetFeatureID(), ft)) + auto ft = m_loader.Load(actual.GetFeatureID()); + if (!ft) return false; - return Matches(golden, ft); + return Matches(golden, *ft); } } // namespace search diff --git a/search/search_tests_support/test_with_custom_mwms.hpp b/search/search_tests_support/test_with_custom_mwms.hpp index eeb2f1c698..9e07788ac7 100644 --- a/search/search_tests_support/test_with_custom_mwms.hpp +++ b/search/search_tests_support/test_with_custom_mwms.hpp @@ -32,9 +32,9 @@ public: void EditFeature(FeatureID const & id, EditorFn && fn) { FeaturesLoaderGuard loader(m_dataSource, id.m_mwmId); - FeatureType ft; - CHECK(loader.GetFeatureByIndex(id.m_index, ft), ()); - editor::tests_support::EditFeature(ft, std::forward<EditorFn>(fn)); + auto ft = loader.GetFeatureByIndex(id.m_index); + CHECK(ft, ()); + editor::tests_support::EditFeature(*ft, std::forward<EditorFn>(fn)); } }; } // namespace tests_support diff --git a/search/street_vicinity_loader.cpp b/search/street_vicinity_loader.cpp index fbe9ab5041..06bb2c35fc 100644 --- a/search/street_vicinity_loader.cpp +++ b/search/street_vicinity_loader.cpp @@ -45,25 +45,25 @@ StreetVicinityLoader::Street const & StreetVicinityLoader::GetStreet(uint32_t fe void StreetVicinityLoader::LoadStreet(uint32_t featureId, Street & street) { - FeatureType feature; - if (!m_context->GetFeature(featureId, feature)) + auto feature = m_context->GetFeature(featureId); + if (!feature) return; - bool const isStreet = feature.GetFeatureType() == feature::GEOM_LINE && - ftypes::IsWayChecker::Instance()(feature); - bool const isSquareOrSuburb = ftypes::IsSquareChecker::Instance()(feature) || - ftypes::IsSuburbChecker::Instance()(feature); + bool const isStreet = + feature->GetFeatureType() == feature::GEOM_LINE && ftypes::IsWayChecker::Instance()(*feature); + bool const isSquareOrSuburb = ftypes::IsSquareChecker::Instance()(*feature) || + ftypes::IsSuburbChecker::Instance()(*feature); if (!isStreet && !isSquareOrSuburb) return; vector<m2::PointD> points; - if (feature.GetFeatureType() == feature::GEOM_AREA) + if (feature->GetFeatureType() == feature::GEOM_AREA) { - points = feature.GetTriangesAsPoints(FeatureType::BEST_GEOMETRY); + points = feature->GetTriangesAsPoints(FeatureType::BEST_GEOMETRY); } else { - feature.ForEachPoint(base::MakeBackInsertFunctor(points), FeatureType::BEST_GEOMETRY); + feature->ForEachPoint(base::MakeBackInsertFunctor(points), FeatureType::BEST_GEOMETRY); } ASSERT(!points.empty(), ()); diff --git a/search/street_vicinity_loader.hpp b/search/street_vicinity_loader.hpp index e9a061aa93..ca1f80e25e 100644 --- a/search/street_vicinity_loader.hpp +++ b/search/street_vicinity_loader.hpp @@ -67,11 +67,11 @@ public: if (!std::binary_search(sortedIds.begin(), sortedIds.end(), id)) continue; - FeatureType ft; - if (!m_context->GetFeature(id, ft)) + auto ft = m_context->GetFeature(id); + if (!ft) continue; // Feature was deleted. - if (calculator.GetProjection(feature::GetCenter(ft, FeatureType::WORST_GEOMETRY), proj) && + if (calculator.GetProjection(feature::GetCenter(*ft, FeatureType::WORST_GEOMETRY), proj) && proj.m_distMeters <= offsetMeters) { fn(id); |