From 570b2b0b35df1fad001460eccf35da31e334b8b0 Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Tue, 26 Jun 2018 10:51:37 +0300 Subject: [indexer] DataSource refactoring --- android/jni/com/mapswithme/maps/Framework.cpp | 2 +- android/jni/com/mapswithme/maps/Framework.hpp | 4 +- editor/CMakeLists.txt | 1 - editor/editable_data_source.hpp | 7 - editor/editable_feature_source.hpp | 13 +- editor/editor_tests/osm_editor_test.cpp | 5 +- editor/editor_tests/osm_editor_test.hpp | 5 +- feature_list/feature_list.cpp | 6 +- generator/cities_boundaries_builder.cpp | 2 +- generator/generator_tests/altitude_test.cpp | 7 +- .../test_with_custom_mwms.hpp | 6 +- generator/search_index_builder.cpp | 2 +- generator/sponsored_dataset_inl.hpp | 2 +- generator/utils.cpp | 3 +- generator/utils.hpp | 6 +- generator/viator_dataset.cpp | 1 + indexer/altitude_loader.cpp | 2 +- indexer/altitude_loader.hpp | 4 +- indexer/data_source.cpp | 244 +++++++++++++++++- indexer/data_source.hpp | 281 +++------------------ indexer/data_source_helpers.cpp | 2 +- indexer/data_source_helpers.hpp | 4 +- indexer/feature_source.hpp | 10 + indexer/indexer_tests/data_source_test.cpp | 6 +- indexer/indexer_tests/features_vector_test.cpp | 2 +- indexer/indexer_tests/index_builder_test.cpp | 2 +- indexer/indexer_tests/rank_table_test.cpp | 2 +- .../indexer_tests/scale_index_reading_tests.cpp | 2 +- indexer/mwm_set.hpp | 6 +- map/booking_availability_filter.cpp | 14 +- map/booking_filter.hpp | 4 +- map/booking_filter_processor.cpp | 10 +- map/booking_filter_processor.hpp | 8 +- map/discovery/discovery_manager.cpp | 9 +- map/discovery/discovery_manager.hpp | 6 +- map/feature_vec_model.cpp | 4 +- map/feature_vec_model.hpp | 9 +- map/framework.cpp | 30 ++- map/framework.hpp | 2 +- map/local_ads_manager.hpp | 2 - map/map_tests/address_tests.cpp | 2 +- map/map_tests/booking_filter_test.cpp | 2 +- map/routing_manager.hpp | 4 +- map/search_api.cpp | 2 +- map/search_api.hpp | 6 +- map/transit/transit_reader.cpp | 7 +- map/transit/transit_reader.hpp | 11 +- openlr/candidate_points_getter.hpp | 4 +- openlr/decoded_path.cpp | 4 +- openlr/decoded_path.hpp | 4 +- openlr/graph.cpp | 4 +- openlr/graph.hpp | 4 +- openlr/openlr_decoder.cpp | 10 +- openlr/openlr_decoder.hpp | 4 +- .../openlr_assessment_tool/mainwindow.cpp | 2 +- .../openlr_assessment_tool/traffic_mode.cpp | 3 +- .../openlr_assessment_tool/traffic_mode.hpp | 5 +- openlr/openlr_stat/openlr_stat.cpp | 10 +- openlr/openlr_tests/decoded_path_test.cpp | 4 +- openlr/road_info_getter.cpp | 4 +- openlr/road_info_getter.hpp | 6 +- routing/bicycle_directions.cpp | 10 +- routing/bicycle_directions.hpp | 10 +- routing/cross_mwm_graph.cpp | 2 +- routing/cross_mwm_graph.hpp | 9 +- routing/cross_mwm_index_graph.hpp | 5 +- routing/features_road_graph.cpp | 13 +- routing/features_road_graph.hpp | 8 +- routing/geometry.cpp | 17 +- routing/geometry.hpp | 4 +- routing/index_graph_loader.cpp | 10 +- routing/index_graph_loader.hpp | 4 +- routing/index_road_graph.cpp | 7 +- routing/index_road_graph.hpp | 4 +- routing/index_router.cpp | 7 +- routing/index_router.hpp | 9 +- routing/loaded_path_segment.hpp | 2 +- routing/routing_benchmarks/helpers.cpp | 5 +- .../get_altitude_test.cpp | 2 +- .../routing_integration_tests/road_graph_tests.cpp | 2 +- .../routing_test_tools.cpp | 6 +- .../routing_test_tools.hpp | 2 +- routing/routing_session.cpp | 5 +- routing/routing_session.hpp | 6 +- routing/routing_tests/routing_session_test.cpp | 6 +- routing/speed_camera.cpp | 2 +- routing/speed_camera.hpp | 4 +- routing/transit_graph_loader.cpp | 9 +- routing/transit_graph_loader.hpp | 4 +- routing/turns_generator.hpp | 2 +- search/cities_boundaries_table.hpp | 6 +- search/city_finder.cpp | 8 +- search/city_finder.hpp | 4 +- search/downloader_search_callback.cpp | 10 +- search/downloader_search_callback.hpp | 6 +- search/editor_delegate.cpp | 7 +- search/editor_delegate.hpp | 6 +- search/engine.cpp | 2 +- search/engine.hpp | 4 +- search/feature_loader.cpp | 7 +- search/feature_loader.hpp | 9 +- search/features_layer_matcher.cpp | 2 +- search/features_layer_matcher.hpp | 4 +- search/geocoder.cpp | 2 +- search/geocoder.hpp | 6 +- search/house_detector.cpp | 2 +- search/house_detector.hpp | 4 +- search/locality_finder.cpp | 3 +- search/locality_finder.hpp | 6 +- search/mwm_context.hpp | 2 +- search/nested_rects_cache.cpp | 2 +- search/nested_rects_cache.hpp | 6 +- search/pre_ranker.cpp | 2 +- search/pre_ranker.hpp | 6 +- search/processor.cpp | 2 +- search/processor.hpp | 4 +- search/rank_table_cache.cpp | 2 +- search/rank_table_cache.hpp | 4 +- search/ranker.cpp | 15 +- search/ranker.hpp | 6 +- search/retrieval.cpp | 2 - search/reverse_geocoder.cpp | 2 +- search/reverse_geocoder.hpp | 10 +- .../downloader_search_test.cpp | 4 +- search/search_integration_tests/generate_tests.cpp | 2 +- .../search_integration_tests/pre_ranker_test.cpp | 8 +- search/search_integration_tests/processor_test.cpp | 8 +- .../search_quality/assessment_tool/main_model.hpp | 4 +- .../features_collector_tool.cpp | 2 +- .../search_quality_tool/search_quality_tool.cpp | 8 +- search/search_tests/house_detector_tests.cpp | 9 +- search/search_tests/locality_finder_test.cpp | 7 +- .../search_tests_support/test_results_matching.cpp | 6 +- .../search_tests_support/test_results_matching.hpp | 8 +- search/search_tests_support/test_search_engine.cpp | 8 +- search/search_tests_support/test_search_engine.hpp | 6 +- .../search_tests_support/test_with_custom_mwms.hpp | 5 +- search/utils.cpp | 5 +- search/utils.hpp | 8 +- track_analyzing/track_matcher.cpp | 7 +- track_analyzing/track_matcher.hpp | 3 +- ugc/api.cpp | 2 +- ugc/api.hpp | 4 +- ugc/loader.cpp | 2 +- ugc/loader.hpp | 6 +- ugc/storage.cpp | 5 +- ugc/storage.hpp | 6 +- ugc/ugc_tests/storage_tests.cpp | 7 +- xcode/editor/editor.xcodeproj/project.pbxproj | 2 - 149 files changed, 697 insertions(+), 623 deletions(-) delete mode 100644 editor/editable_data_source.hpp diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 9979a1181e..2713a02746 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -284,7 +284,7 @@ Storage & Framework::GetStorage() return m_work.GetStorage(); } -DataSourceBase const & Framework::GetDataSource() { return m_work.GetDataSource(); } +DataSource const & Framework::GetDataSource() { return m_work.GetDataSource(); } void Framework::ShowNode(TCountryId const & idx, bool zoomToDownloadButton) { diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index bb75b5c2ad..d49f38435c 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -33,7 +33,7 @@ #include #include -class DataSourceBase; +class DataSource; struct FeatureID; namespace search @@ -81,7 +81,7 @@ namespace android Framework(); storage::Storage & GetStorage(); - DataSourceBase const & GetDataSource(); + DataSource const & GetDataSource(); void ShowNode(storage::TCountryId const & countryId, bool zoomToDownloadButton); diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index 3d502a887b..987054b5c7 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -6,7 +6,6 @@ set( changeset_wrapper.hpp config_loader.cpp config_loader.hpp - editable_data_source.hpp editable_feature_source.cpp editable_feature_source.hpp editor_config.cpp diff --git a/editor/editable_data_source.hpp b/editor/editable_data_source.hpp deleted file mode 100644 index fdb0841d2b..0000000000 --- a/editor/editable_data_source.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "editor/editable_feature_source.hpp" - -#include "indexer/data_source.hpp" - -using EditableDataSource = DataSourceImpl; diff --git a/editor/editable_feature_source.hpp b/editor/editable_feature_source.hpp index 3dcb30e107..3dadf59801 100644 --- a/editor/editable_feature_source.hpp +++ b/editor/editable_feature_source.hpp @@ -8,6 +8,7 @@ #include #include +#include class EditableFeatureSource final : public FeatureSource { @@ -21,4 +22,14 @@ public: std::function const & fn) const override; void ForEachInRectAndScale(m2::RectD const & rect, int scale, std::function const & fn) const override; -}; // class EditableFeatureSource +}; + +class EditableFeatureSourceFactory : public FeatureSourceFactory +{ +public: + // FeatureSourceFactory overrides: + std::unique_ptr operator()(MwmSet::MwmHandle const & handle) const override + { + return std::make_unique(handle); + } +}; diff --git a/editor/editor_tests/osm_editor_test.cpp b/editor/editor_tests/osm_editor_test.cpp index c5224b6c6c..7886882c24 100644 --- a/editor/editor_tests/osm_editor_test.cpp +++ b/editor/editor_tests/osm_editor_test.cpp @@ -1,5 +1,6 @@ #include "testing/testing.hpp" +#include "editor/editable_feature_source.hpp" #include "editor/editor_storage.hpp" #include "editor/editor_tests/osm_editor_test.hpp" #include "editor/editor_tests_support/helpers.hpp" @@ -53,7 +54,7 @@ public: }; template -void ForEachCafeAtPoint(DataSourceBase & dataSource, m2::PointD const & mercator, TFn && fn) +void ForEachCafeAtPoint(DataSource & dataSource, m2::PointD const & mercator, TFn && fn) { m2::RectD const rect = MercatorBounds::RectByCenterXYAndSizeInMeters(mercator, 0.2 /* rect width */); @@ -136,7 +137,7 @@ namespace editor { namespace testing { -EditorTest::EditorTest() +EditorTest::EditorTest() : m_dataSource(make_unique()) { try { diff --git a/editor/editor_tests/osm_editor_test.hpp b/editor/editor_tests/osm_editor_test.hpp index a0c7829bd5..8382178e63 100644 --- a/editor/editor_tests/osm_editor_test.hpp +++ b/editor/editor_tests/osm_editor_test.hpp @@ -5,8 +5,7 @@ #include "generator/generator_tests_support/test_feature.hpp" #include "generator/generator_tests_support/test_mwm_builder.hpp" -#include "editor/editable_data_source.hpp" - +#include "indexer/data_source.hpp" #include "indexer/mwm_set.hpp" #include "storage/country_info_getter.hpp" @@ -79,7 +78,7 @@ private: void Cleanup(platform::LocalCountryFile const & map); bool RemoveMwm(MwmSet::MwmId const & mwmId); - EditableDataSource m_dataSource; + DataSource m_dataSource; storage::CountryInfoGetterForTesting m_infoGetter; vector m_mwmFiles; }; diff --git a/feature_list/feature_list.cpp b/feature_list/feature_list.cpp index 0ef127a163..022515d20a 100644 --- a/feature_list/feature_list.cpp +++ b/feature_list/feature_list.cpp @@ -178,7 +178,7 @@ class Processor search::LocalityFinder m_finder; public: - Processor(DataSourceBase const & dataSource) + Processor(DataSource const & dataSource) : m_geocoder(dataSource) , m_boundariesTable(dataSource) , m_villagesCache(m_cancellable) @@ -324,7 +324,7 @@ int main(int argc, char ** argv) classificator::Load(); classif().SortClassificator(); - DataSource dataSource; + DataSource dataSource(make_unique()); vector mwms; platform::FindAllLocalMapsAndCleanup(numeric_limits::max() /* the latest version */, mwms); @@ -353,7 +353,7 @@ int main(int argc, char ** argv) map featureIdToOsmId; ParseFeatureIdToOsmIdMapping(osmToFeatureFile, featureIdToOsmId); MwmSet::MwmId mwmId(mwmInfo); - DataSource::FeaturesLoaderGuard loader(dataSource, mwmId); + DataSource::FeaturesLoaderGuard loader(dataSource, mwmId, FeatureSourceFactory()); for (uint32_t ftIndex = 0; ftIndex < loader.GetNumFeatures(); ftIndex++) { FeatureType ft; diff --git a/generator/cities_boundaries_builder.cpp b/generator/cities_boundaries_builder.cpp index 1f8a09ece6..8da3152b42 100644 --- a/generator/cities_boundaries_builder.cpp +++ b/generator/cities_boundaries_builder.cpp @@ -67,7 +67,7 @@ bool ParseFeatureIdToTestIdMapping(string const & path, map()); auto const result = dataSource.Register(platform::LocalCountryFile::MakeTemporary(dataPath)); CHECK_EQUAL(result.second, MwmSet::RegResult::Success, ("Can't register", dataPath)); diff --git a/generator/generator_tests/altitude_test.cpp b/generator/generator_tests/altitude_test.cpp index 8bfc8d682b..a420803f42 100644 --- a/generator/generator_tests/altitude_test.cpp +++ b/generator/generator_tests/altitude_test.cpp @@ -131,8 +131,9 @@ void BuildMwmWithoutAltitudes(vector const & roads, LocalCountryFi builder.Add(generator::tests_support::TestStreet(ExtractPoints(geom3D), std::string(), std::string())); } -void TestAltitudes(DataSourceBase const & dataSource, MwmSet::MwmId const & mwmId, std::string const & mwmPath, - bool hasAltitudeExpected, AltitudeGetter & expectedAltitudes) +void TestAltitudes(DataSource const & dataSource, MwmSet::MwmId const & mwmId, + std::string const & mwmPath, bool hasAltitudeExpected, + AltitudeGetter & expectedAltitudes) { AltitudeLoader loader(dataSource, mwmId); TEST_EQUAL(loader.HasAltitudes(), hasAltitudeExpected, ()); @@ -181,7 +182,7 @@ void TestAltitudesBuilding(vector const & roads, bool hasAltitudeE BuildRoadAltitudes(mwmPath, altitudeGetter); // Reading from mwm and testing altitude information. - DataSource dataSource; + DataSource dataSource(make_unique()); auto const regResult = dataSource.RegisterMap(country); TEST_EQUAL(regResult.second, MwmSet::RegResult::Success, ()); diff --git a/generator/generator_tests_support/test_with_custom_mwms.hpp b/generator/generator_tests_support/test_with_custom_mwms.hpp index 06409815c3..6ceebfa1e4 100644 --- a/generator/generator_tests_support/test_with_custom_mwms.hpp +++ b/generator/generator_tests_support/test_with_custom_mwms.hpp @@ -3,9 +3,10 @@ #include "generator/generator_tests_support/test_mwm_builder.hpp" #include "generator/generator_tests_support/test_with_classificator.hpp" -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" #include "indexer/data_header.hpp" +#include "indexer/data_source.hpp" #include "indexer/feature.hpp" #include "indexer/mwm_set.hpp" @@ -26,6 +27,7 @@ namespace tests_support class TestWithCustomMwms : public TestWithClassificator { public: + TestWithCustomMwms() : m_dataSource(make_unique()) {} ~TestWithCustomMwms() override; // Creates a physical country file on a disk, which will be removed @@ -88,7 +90,7 @@ protected: virtual void OnMwmBuilt(MwmInfo const & /* info */) {} - EditableDataSource m_dataSource; + DataSource m_dataSource; std::vector m_files; }; } // namespace tests_support diff --git a/generator/search_index_builder.cpp b/generator/search_index_builder.cpp index f1fe253d77..b4e1ede9a8 100644 --- a/generator/search_index_builder.cpp +++ b/generator/search_index_builder.cpp @@ -323,7 +323,7 @@ void BuildAddressTable(FilesContainerR & container, Writer & writer) uint32_t address = 0, missing = 0; map bounds; - DataSource dataSource; + DataSource dataSource(make_unique()); /// @ todo Make some better solution, or legalize MakeTemporary. auto const res = dataSource.RegisterMap(platform::LocalCountryFile::MakeTemporary(container.GetFileName())); ASSERT_EQUAL(res.second, MwmSet::RegResult::Success, ()); diff --git a/generator/sponsored_dataset_inl.hpp b/generator/sponsored_dataset_inl.hpp index 09dcd46dcc..d35c1843c7 100644 --- a/generator/sponsored_dataset_inl.hpp +++ b/generator/sponsored_dataset_inl.hpp @@ -18,7 +18,7 @@ namespace generator class AddressMatcher { public: - AddressMatcher() + AddressMatcher() : m_dataSource(make_unique()) { LoadDataSource(m_dataSource); m_coder = make_unique(m_dataSource); diff --git a/generator/utils.cpp b/generator/utils.cpp index 235fe2c175..8068785e45 100644 --- a/generator/utils.cpp +++ b/generator/utils.cpp @@ -11,6 +11,7 @@ namespace generator { // SingleMwmDataSource ----------------------------------------------------------------------------- SingleMwmDataSource::SingleMwmDataSource(std::string const & mwmPath) + : m_dataSource(make_unique()) { m_countryFile = platform::LocalCountryFile::MakeTemporary(mwmPath); m_countryFile.SyncWithDisk(); @@ -24,7 +25,7 @@ SingleMwmDataSource::SingleMwmDataSource(std::string const & mwmPath) m_mwmId = result.first; } -void LoadDataSource(DataSourceBase & dataSource) +void LoadDataSource(DataSource & dataSource) { vector localFiles; diff --git a/generator/utils.hpp b/generator/utils.hpp index 037eee5d84..00b7d11bc8 100644 --- a/generator/utils.hpp +++ b/generator/utils.hpp @@ -18,14 +18,14 @@ namespace generator { -/// \brief This class is wrapper around |DataSourceBase| if only one mwm is registered in DataSourceBase. +/// \brief This class is wrapper around |DataSource| if only one mwm is registered in DataSource. class SingleMwmDataSource { public: /// \param mwmPath is a path to mwm which should be registerd in DataSource. explicit SingleMwmDataSource(std::string const & mwmPath); - DataSourceBase & GetDataSource() { return m_dataSource; } + DataSource & GetDataSource() { return m_dataSource; } std::string GetPath(MapOptions file) const { return m_countryFile.GetPath(file); } MwmSet::MwmId const & GetMwmId() const { return m_mwmId; } @@ -35,7 +35,7 @@ private: MwmSet::MwmId m_mwmId; }; -void LoadDataSource(DataSourceBase & dataSource); +void LoadDataSource(DataSource & dataSource); template bool ForEachOsmId2FeatureId(std::string const & path, ToDo && toDo) diff --git a/generator/viator_dataset.cpp b/generator/viator_dataset.cpp index 07fdda0edf..b31790fc00 100644 --- a/generator/viator_dataset.cpp +++ b/generator/viator_dataset.cpp @@ -55,6 +55,7 @@ ostream & operator<<(ostream & s, ViatorCity const & h) // ViatorDataset ---------------------------------------------------------------------------------- ViatorDataset::ViatorDataset(std::string const & dataPath) : m_storage(3000.0 /* distanceLimitMeters */, 3 /* maxSelectedElements */) + , m_dataSource(make_unique()) { LoadDataSource(m_dataSource); m_cityFinder = make_unique(m_dataSource); diff --git a/indexer/altitude_loader.cpp b/indexer/altitude_loader.cpp index 8e54d52034..a1387a1f8e 100644 --- a/indexer/altitude_loader.cpp +++ b/indexer/altitude_loader.cpp @@ -31,7 +31,7 @@ void LoadAndMap(size_t dataSize, ReaderSource & src, T namespace feature { -AltitudeLoader::AltitudeLoader(DataSourceBase const & dataSource, MwmSet::MwmId const & mwmId) +AltitudeLoader::AltitudeLoader(DataSource const & dataSource, MwmSet::MwmId const & mwmId) : m_handle(dataSource.GetMwmHandleById(mwmId)) { if (!m_handle.IsAlive()) diff --git a/indexer/altitude_loader.hpp b/indexer/altitude_loader.hpp index ceb089e7e2..3ef738abd0 100644 --- a/indexer/altitude_loader.hpp +++ b/indexer/altitude_loader.hpp @@ -10,14 +10,14 @@ #include "3party/succinct/rs_bit_vector.hpp" -class DataSourceBase; +class DataSource; namespace feature { class AltitudeLoader { public: - AltitudeLoader(DataSourceBase const & dataSource, MwmSet::MwmId const & mwmId); + AltitudeLoader(DataSource const & dataSource, MwmSet::MwmId const & mwmId); /// \returns altitude of feature with |featureId|. All items of the returned vector are valid /// or the returned vector is empty. diff --git a/indexer/data_source.cpp b/indexer/data_source.cpp index bb6b7ea3ed..fffe4650d7 100644 --- a/indexer/data_source.cpp +++ b/indexer/data_source.cpp @@ -2,15 +2,172 @@ #include "base/logging.hpp" +#include +#include + using platform::CountryFile; using platform::LocalCountryFile; using namespace std; -////////////////////////////////////////////////////////////////////////////////// -// DataSourceBase implementation -////////////////////////////////////////////////////////////////////////////////// +namespace +{ +template +class ReadMWMFunctor +{ +public: + using Fn = function; + + ReadMWMFunctor(Fn const & fn, FeatureSourceFactory const & factory) : m_fn(fn), m_factory(factory) + { + } + + template + enable_if_t::value> ProcessElement(FeatureSource & src, + uint32_t index) const + { + if (FeatureStatus::Deleted == src.GetFeatureStatus(index)) + return; + + m_fn(src.GetFeatureId(index)); + } + + template + enable_if_t::value> ProcessElement(FeatureSource & src, + uint32_t index) const + { + FeatureType feature; + switch (src.GetFeatureStatus(index)) + { + case FeatureStatus::Created: CHECK(false, ("Created features index should be generated.")); + case FeatureStatus::Deleted: + case FeatureStatus::Obsolete: return; + case FeatureStatus::Modified: + { + VERIFY(src.GetModifiedFeature(index, feature), ()); + break; + } + case FeatureStatus::Untouched: + { + src.GetOriginalFeature(index, feature); + break; + } + } + m_fn(feature); + } + + // Reads features visible at |scale| covered by |cov| from mwm and applies |m_fn| to it. + // Feature reading process consists of two steps: untouched (original) features reading and + // touched (created, edited etc.) features reading. + void operator()(MwmSet::MwmHandle const & handle, covering::CoveringGetter & cov, int scale) const + { + auto src = m_factory(handle); + + MwmValue const * pValue = handle.GetValue(); + if (pValue) + { + // Untouched (original) features reading. Applies covering |cov| to geometry index, gets + // feature ids from it, gets untouched features by ids from |src| and applies |m_fn| by + // ProcessElement. + feature::DataHeader const & header = pValue->GetHeader(); + CheckUniqueIndexes checkUnique(header.GetFormat() >= version::Format::v5); + + // In case of WorldCoasts we should pass correct scale in ForEachInIntervalAndScale. + auto const lastScale = header.GetLastScale(); + if (scale > lastScale) + scale = lastScale; + + // Use last coding scale for covering (see index_builder.cpp). + covering::Intervals const & intervals = cov.Get(lastScale); + ScaleIndex index(pValue->m_cont.GetReader(INDEX_FILE_TAG), pValue->m_factory); + + // iterate through intervals + for (auto const & i : intervals) + { + index.ForEachInIntervalAndScale(i.first, i.second, scale, [&](uint32_t index) { + if (!checkUnique(index)) + return; + ProcessElement(*src, index); + }); + } + } + // Check created features container. + // Need to do it on a per-mwm basis, because Drape relies on features in a sorted order. + // Touched (created, edited) features reading. + src->ForEachInRectAndScale(cov.GetRect(), scale, m_fn); + } + +private: + Fn m_fn; + FeatureSourceFactory const & m_factory; +}; +} // namespace + +//------------------------- DataSource::FeaturesLoaderGuard ---------------------- + +string DataSource::FeaturesLoaderGuard::GetCountryFileName() const +{ + if (!m_handle.IsAlive()) + return string(); + + return m_handle.GetValue()->GetCountryFileName(); +} + +bool DataSource::FeaturesLoaderGuard::IsWorld() const +{ + if (!m_handle.IsAlive()) + return false; + + return m_handle.GetValue()->GetHeader().GetType() == feature::DataHeader::world; +} + +unique_ptr DataSource::FeaturesLoaderGuard::GetOriginalFeatureByIndex( + uint32_t index) const +{ + auto feature = make_unique(); + if (GetOriginalFeatureByIndex(index, *feature)) + return feature; + + return {}; +} -unique_ptr DataSourceBase::CreateInfo(platform::LocalCountryFile const & localFile) const +unique_ptr DataSource::FeaturesLoaderGuard::GetOriginalOrEditedFeatureByIndex( + uint32_t index) const +{ + auto feature = make_unique(); + if (!m_handle.IsAlive()) + return {}; + + ASSERT_NOT_EQUAL(m_source->GetFeatureStatus(index), FeatureStatus::Created, ()); + if (GetFeatureByIndex(index, *feature)) + return feature; + + return {}; +} + +/// Everyone, except Editor core, should use this method. +WARN_UNUSED_RESULT bool DataSource::FeaturesLoaderGuard::GetFeatureByIndex(uint32_t index, + FeatureType & ft) const +{ + if (!m_handle.IsAlive()) + return false; + + ASSERT_NOT_EQUAL(FeatureStatus::Deleted, m_source->GetFeatureStatus(index), + ("Deleted feature was cached. It should not be here. Please review your code.")); + if (m_source->GetModifiedFeature(index, ft)) + return true; + return GetOriginalFeatureByIndex(index, ft); +} + +/// Editor core only method, to get 'untouched', original version of feature. +WARN_UNUSED_RESULT bool DataSource::FeaturesLoaderGuard::GetOriginalFeatureByIndex( + uint32_t index, FeatureType & ft) const +{ + return m_handle.IsAlive() ? m_source->GetOriginalFeature(index, ft) : false; +} + +//---------------- DataSource ----------------------------------------------- + +unique_ptr DataSource::CreateInfo(platform::LocalCountryFile const & localFile) const { MwmValue value(localFile); @@ -32,7 +189,7 @@ unique_ptr DataSourceBase::CreateInfo(platform::LocalCountryFile const return unique_ptr(move(info)); } -unique_ptr DataSourceBase::CreateValue(MwmInfo & info) const +unique_ptr DataSource::CreateValue(MwmInfo & info) const { // Create a section with rank table if it does not exist. platform::LocalCountryFile const & localFile = info.GetLocalFile(); @@ -42,15 +199,15 @@ unique_ptr DataSourceBase::CreateValue(MwmInfo & info) con return unique_ptr(move(p)); } -pair DataSourceBase::RegisterMap(LocalCountryFile const & localFile) +pair DataSource::RegisterMap(LocalCountryFile const & localFile) { return Register(localFile); } -bool DataSourceBase::DeregisterMap(CountryFile const & countryFile) { return Deregister(countryFile); } +bool DataSource::DeregisterMap(CountryFile const & countryFile) { return Deregister(countryFile); } -void DataSourceBase::ForEachInIntervals(ReaderCallback const & fn, covering::CoveringMode mode, - m2::RectD const & rect, int scale) const +void DataSource::ForEachInIntervals(ReaderCallback const & fn, covering::CoveringMode mode, + m2::RectD const & rect, int scale) const { vector> mwms; GetMwmsInfo(mwms); @@ -80,3 +237,72 @@ void DataSourceBase::ForEachInIntervals(ReaderCallback const & fn, covering::Cov if (worldID[1].IsAlive()) fn(GetMwmHandleById(worldID[1]), cov, scale); } + +void DataSource::ForEachFeatureIDInRect(FeatureIdCallback const & f, m2::RectD const & rect, + int scale) const +{ + ReadMWMFunctor readFunctor(f, *m_factory); + ForEachInIntervals(readFunctor, covering::LowLevelsOnly, rect, scale); +} + +void DataSource::ForEachInRect(FeatureCallback const & f, m2::RectD const & rect, int scale) const +{ + ReadMWMFunctor readFunctor(f, *m_factory); + ForEachInIntervals(readFunctor, covering::ViewportWithLowLevels, rect, scale); +} + +void DataSource::ForEachInScale(FeatureCallback const & f, int scale) const +{ + ReadMWMFunctor readFunctor(f, *m_factory); + ForEachInIntervals(readFunctor, covering::FullCover, m2::RectD::GetInfiniteRect(), scale); +} + +void DataSource::ForEachInRectForMWM(FeatureCallback const & f, m2::RectD const & rect, int scale, + MwmId const & id) const +{ + MwmHandle const handle = GetMwmHandleById(id); + if (handle.IsAlive()) + { + covering::CoveringGetter cov(rect, covering::ViewportWithLowLevels); + ReadMWMFunctor readFunctor(f, *m_factory); + readFunctor(handle, cov, scale); + } +} + +void DataSource::ReadFeatures(FeatureConstCallback const & fn, + vector const & features) const +{ + ASSERT(is_sorted(features.begin(), features.end()), ()); + + auto fidIter = features.begin(); + auto const endIter = features.end(); + while (fidIter != endIter) + { + MwmId const & id = fidIter->m_mwmId; + MwmHandle const handle = GetMwmHandleById(id); + if (handle.IsAlive()) + { + // Prepare features reading. + auto src = (*m_factory)(handle); + do + { + auto const fts = src->GetFeatureStatus(fidIter->m_index); + ASSERT_NOT_EQUAL( + FeatureStatus::Deleted, fts, + ("Deleted feature was cached. It should not be here. Please review your code.")); + FeatureType featureType; + if (fts == FeatureStatus::Modified || fts == FeatureStatus::Created) + VERIFY(src->GetModifiedFeature(fidIter->m_index, featureType), ()); + else + src->GetOriginalFeature(fidIter->m_index, featureType); + fn(featureType); + } while (++fidIter != endIter && id == fidIter->m_mwmId); + } + else + { + // Skip unregistered mwm files. + while (++fidIter != endIter && id == fidIter->m_mwmId) + ; + } + } +} diff --git a/indexer/data_source.hpp b/indexer/data_source.hpp index 8e8edfb2d0..484f1efa23 100644 --- a/indexer/data_source.hpp +++ b/indexer/data_source.hpp @@ -17,109 +17,50 @@ #include #include #include -#include #include -#include #include #include #include "defines.hpp" -template -class ReadMWMFunctor final +class DataSource : public MwmSet { public: - using Fn = std::function; - - explicit ReadMWMFunctor(Fn const & fn) : m_fn(fn) {} - - template - std::enable_if_t::value> ProcessElement(FeatureSource & src, - uint32_t index) const - { - if (FeatureStatus::Deleted == src.GetFeatureStatus(index)) - return; - - m_fn(src.GetFeatureId(index)); - } + using FeatureConstCallback = std::function; + using FeatureCallback = std::function; + using FeatureIdCallback = std::function; - template - std::enable_if_t::value> ProcessElement(FeatureSource & src, - uint32_t index) const + explicit DataSource(std::unique_ptr factory) : m_factory(std::move(factory)) { - FeatureType feature; - switch (src.GetFeatureStatus(index)) - { - case FeatureStatus::Created: CHECK(false, ("Created features index should be generated.")); - case FeatureStatus::Deleted: - case FeatureStatus::Obsolete: return; - case FeatureStatus::Modified: - { - VERIFY(src.GetModifiedFeature(index, feature), ()); - break; - } - case FeatureStatus::Untouched: - { - src.GetOriginalFeature(index, feature); - break; - } - } - m_fn(feature); } + ~DataSource() override = default; - // Reads features visible at |scale| covered by |cov| from mwm and applies |m_fn| to it. - // Feature reading process consists of two steps: untouched (original) features reading and - // touched (created, edited etc.) features reading. - void operator()(MwmSet::MwmHandle const & handle, covering::CoveringGetter & cov, int scale) const + /// Guard for loading features from particular MWM by demand. + /// @note This guard is suitable when mwm is loaded. + class FeaturesLoaderGuard { - FeatureSource src(handle); - - MwmValue const * pValue = handle.GetValue(); - if (pValue) + public: + FeaturesLoaderGuard(DataSource const & dataSource, MwmId const & id, + FeatureSourceFactory const & factory) + : m_handle(dataSource.GetMwmHandleById(id)), m_source(factory(m_handle)) { - // Untouched (original) features reading. Applies covering |cov| to geometry index, gets - // feature ids from it, gets untouched features by ids from |src| and applies |m_fn| by - // ProcessElement. - feature::DataHeader const & header = pValue->GetHeader(); - CheckUniqueIndexes checkUnique(header.GetFormat() >= version::Format::v5); - - // In case of WorldCoasts we should pass correct scale in ForEachInIntervalAndScale. - auto const lastScale = header.GetLastScale(); - if (scale > lastScale) - scale = lastScale; - - // Use last coding scale for covering (see index_builder.cpp). - covering::Intervals const & intervals = cov.Get(lastScale); - ScaleIndex index(pValue->m_cont.GetReader(INDEX_FILE_TAG), pValue->m_factory); - - // iterate through intervals - for (auto const & i : intervals) - { - index.ForEachInIntervalAndScale(i.first, i.second, scale, [&](uint32_t index) { - if (!checkUnique(index)) - return; - ProcessElement(src, index); - }); - } } - // Check created features container. - // Need to do it on a per-mwm basis, because Drape relies on features in a sorted order. - // Touched (created, edited) features reading. - src.ForEachInRectAndScale(cov.GetRect(), scale, m_fn); - } - -private: - Fn m_fn; -}; -class DataSourceBase : public MwmSet -{ -public: - using FeatureConstCallback = std::function; - using FeatureCallback = std::function; - using FeatureIdCallback = std::function; + MwmSet::MwmId const & GetId() const { return m_handle.GetId(); } + std::string GetCountryFileName() const; + bool IsWorld() const; + std::unique_ptr GetOriginalFeatureByIndex(uint32_t index) const; + std::unique_ptr GetOriginalOrEditedFeatureByIndex(uint32_t index) const; + /// Everyone, except Editor core, should use this method. + WARN_UNUSED_RESULT bool GetFeatureByIndex(uint32_t index, FeatureType & ft) const; + /// Editor core only method, to get 'untouched', original version of feature. + WARN_UNUSED_RESULT bool GetOriginalFeatureByIndex(uint32_t index, FeatureType & ft) const; + size_t GetNumFeatures() const { return m_source->GetNumFeatures(); } - ~DataSourceBase() override = default; + private: + MwmHandle m_handle; + std::unique_ptr m_source; + }; /// Registers a new map. std::pair RegisterMap(platform::LocalCountryFile const & localFile); @@ -131,16 +72,13 @@ public: /// now, returns false. bool DeregisterMap(platform::CountryFile const & countryFile); - virtual void ForEachFeatureIDInRect(FeatureIdCallback const & f, m2::RectD const & rect, - int scale) const = 0; - virtual void ForEachInRect(FeatureCallback const & f, m2::RectD const & rect, - int scale) const = 0; - virtual void ForEachInScale(FeatureCallback const & f, int scale) const = 0; - virtual void ForEachInRectForMWM(FeatureCallback const & f, m2::RectD const & rect, int scale, - MwmId const & id) const = 0; + void ForEachFeatureIDInRect(FeatureIdCallback const & f, m2::RectD const & rect, int scale) const; + void ForEachInRect(FeatureCallback const & f, m2::RectD const & rect, int scale) const; + void ForEachInScale(FeatureCallback const & f, int scale) const; + void ForEachInRectForMWM(FeatureCallback const & f, m2::RectD const & rect, int scale, + MwmId const & id) const; // "features" must be sorted using FeatureID::operator< as predicate. - virtual void ReadFeatures(FeatureConstCallback const & fn, - std::vector const & features) const = 0; + void ReadFeatures(FeatureConstCallback const & fn, std::vector const & features) const; void ReadFeature(FeatureConstCallback const & fn, FeatureID const & feature) const { @@ -157,157 +95,8 @@ protected: /// MwmSet overrides: std::unique_ptr CreateInfo(platform::LocalCountryFile const & localFile) const override; std::unique_ptr CreateValue(MwmInfo & info) const override; -}; -template -class DataSourceImpl : public DataSourceBase -{ -public: - void ForEachFeatureIDInRect(FeatureIdCallback const & f, m2::RectD const & rect, - int scale) const override - { - ReadMWMFunctor readFunctor(f); - ForEachInIntervals(readFunctor, covering::LowLevelsOnly, rect, scale); - } - - void ForEachInRect(FeatureCallback const & f, m2::RectD const & rect, int scale) const override - { - ReadMWMFunctor readFunctor(f); - ForEachInIntervals(readFunctor, covering::ViewportWithLowLevels, rect, scale); - } - - void ForEachInScale(FeatureCallback const & f, int scale) const override - { - ReadMWMFunctor readFunctor(f); - ForEachInIntervals(readFunctor, covering::FullCover, m2::RectD::GetInfiniteRect(), scale); - } - - void ForEachInRectForMWM(FeatureCallback const & f, m2::RectD const & rect, int scale, - MwmId const & id) const override - { - MwmHandle const handle = GetMwmHandleById(id); - if (handle.IsAlive()) - { - covering::CoveringGetter cov(rect, covering::ViewportWithLowLevels); - ReadMWMFunctor readFunctor(f); - readFunctor(handle, cov, scale); - } - } - - void ReadFeatures(FeatureConstCallback const & fn, - std::vector const & features) const override - { - ASSERT(std::is_sorted(features.begin(), features.end()), ()); - - auto fidIter = features.begin(); - auto const endIter = features.end(); - while (fidIter != endIter) - { - MwmId const & id = fidIter->m_mwmId; - MwmHandle const handle = GetMwmHandleById(id); - if (handle.IsAlive()) - { - // Prepare features reading. - FeatureSource src(handle); - do - { - auto const fts = src.GetFeatureStatus(fidIter->m_index); - ASSERT_NOT_EQUAL( - FeatureStatus::Deleted, fts, - ("Deleted feature was cached. It should not be here. Please review your code.")); - FeatureType featureType; - if (fts == FeatureStatus::Modified || fts == FeatureStatus::Created) - VERIFY(src.GetModifiedFeature(fidIter->m_index, featureType), ()); - else - src.GetOriginalFeature(fidIter->m_index, featureType); - fn(featureType); - } while (++fidIter != endIter && id == fidIter->m_mwmId); - } - else - { - // Skip unregistered mwm files. - while (++fidIter != endIter && id == fidIter->m_mwmId) - ; - } - } - } - - /// Guard for loading features from particular MWM by demand. - /// @note This guard is suitable when mwm is loaded. - class FeaturesLoaderGuard - { - public: - FeaturesLoaderGuard(DataSourceBase const & dataSource, MwmId const & id) - : m_handle(dataSource.GetMwmHandleById(id)), m_source(m_handle) - { - } - - MwmSet::MwmId const & GetId() const { return m_handle.GetId(); } - - std::string GetCountryFileName() const - { - if (!m_handle.IsAlive()) - return string(); - - return m_handle.GetValue()->GetCountryFileName(); - } - - bool IsWorld() const - { - if (!m_handle.IsAlive()) - return false; - - return m_handle.GetValue()->GetHeader().GetType() == feature::DataHeader::world; - } - - std::unique_ptr GetOriginalFeatureByIndex(uint32_t index) const - { - auto feature = make_unique(); - if (GetOriginalFeatureByIndex(index, *feature)) - return feature; - - return {}; - } - - std::unique_ptr GetOriginalOrEditedFeatureByIndex(uint32_t index) const - { - auto feature = make_unique(); - if (!m_handle.IsAlive()) - return {}; - - ASSERT_NOT_EQUAL(m_source.GetFeatureStatus(index), FeatureStatus::Created, ()); - if (GetFeatureByIndex(index, *feature)) - return feature; - - return {}; - } - - /// Everyone, except Editor core, should use this method. - WARN_UNUSED_RESULT bool GetFeatureByIndex(uint32_t index, FeatureType & ft) const - { - if (!m_handle.IsAlive()) - return false; - - ASSERT_NOT_EQUAL( - FeatureStatus::Deleted, m_source.GetFeatureStatus(index), - ("Deleted feature was cached. It should not be here. Please review your code.")); - if (m_source.GetModifiedFeature(index, ft)) - return true; - return GetOriginalFeatureByIndex(index, ft); - } - - /// Editor core only method, to get 'untouched', original version of feature. - WARN_UNUSED_RESULT bool GetOriginalFeatureByIndex(uint32_t index, FeatureType & ft) const - { - return m_handle.IsAlive() ? m_source.GetOriginalFeature(index, ft) : false; - } - - size_t GetNumFeatures() const { return m_source.GetNumFeatures(); } - - private: - MwmHandle m_handle; - FeatureSource m_source; - }; +private: + std::unique_ptr m_factory; }; -using DataSource = DataSourceImpl; diff --git a/indexer/data_source_helpers.cpp b/indexer/data_source_helpers.cpp index 210a0af1e9..f17f22072f 100644 --- a/indexer/data_source_helpers.cpp +++ b/indexer/data_source_helpers.cpp @@ -6,7 +6,7 @@ namespace indexer { -void ForEachFeatureAtPoint(DataSourceBase const & dataSource, function && fn, +void ForEachFeatureAtPoint(DataSource const & dataSource, function && fn, m2::PointD const & mercator, double toleranceInMeters) { double constexpr kSelectRectWidthInMeters = 1.1; diff --git a/indexer/data_source_helpers.hpp b/indexer/data_source_helpers.hpp index f7dc7a4582..f638e5e5a7 100644 --- a/indexer/data_source_helpers.hpp +++ b/indexer/data_source_helpers.hpp @@ -4,11 +4,11 @@ #include "std/function.hpp" -class DataSourceBase; +class DataSource; class FeatureType; namespace indexer { -void ForEachFeatureAtPoint(DataSourceBase const & dataSource, function && fn, +void ForEachFeatureAtPoint(DataSource const & dataSource, function && fn, m2::PointD const & mercator, double toleranceInMeters = 0.0); } diff --git a/indexer/feature_source.hpp b/indexer/feature_source.hpp index 19bc3d6fb4..96f56e8725 100644 --- a/indexer/feature_source.hpp +++ b/indexer/feature_source.hpp @@ -50,3 +50,13 @@ protected: MwmSet::MwmHandle const & m_handle; std::unique_ptr m_vector; }; // class FeatureSource + +class FeatureSourceFactory +{ +public: + virtual ~FeatureSourceFactory() = default; + virtual std::unique_ptr operator()(MwmSet::MwmHandle const & handle) const + { + return std::make_unique(handle); + } +}; diff --git a/indexer/indexer_tests/data_source_test.cpp b/indexer/indexer_tests/data_source_test.cpp index c5b64905da..6bf21c0024 100644 --- a/indexer/indexer_tests/data_source_test.cpp +++ b/indexer/indexer_tests/data_source_test.cpp @@ -2,6 +2,7 @@ #include "indexer/data_header.hpp" #include "indexer/data_source.hpp" +#include "indexer/feature_source.hpp" #include "indexer/mwm_set.hpp" #include "coding/file_name_utils.hpp" @@ -28,7 +29,10 @@ namespace class DataSourceTest : public MwmSet::Observer { public: - DataSourceTest() { TEST(m_dataSource.AddObserver(*this), ()); } + DataSourceTest() : m_dataSource(make_unique()) + { + TEST(m_dataSource.AddObserver(*this), ()); + } ~DataSourceTest() override { TEST(m_dataSource.RemoveObserver(*this), ()); } diff --git a/indexer/indexer_tests/features_vector_test.cpp b/indexer/indexer_tests/features_vector_test.cpp index ed0fdb80e6..1599d939cb 100644 --- a/indexer/indexer_tests/features_vector_test.cpp +++ b/indexer/indexer_tests/features_vector_test.cpp @@ -50,7 +50,7 @@ UNIT_TEST(FeaturesVectorTest_ParseMetadata) LocalCountryFile localFile = LocalCountryFile::MakeForTesting(kCountryName); - DataSource dataSource; + DataSource dataSource(make_unique()); auto result = dataSource.RegisterMap(localFile); TEST_EQUAL(result.second, MwmSet::RegResult::Success, ()); diff --git a/indexer/indexer_tests/index_builder_test.cpp b/indexer/indexer_tests/index_builder_test.cpp index aa60d56f1a..1be95727a2 100644 --- a/indexer/indexer_tests/index_builder_test.cpp +++ b/indexer/indexer_tests/index_builder_test.cpp @@ -52,7 +52,7 @@ UNIT_TEST(BuildIndexTest) { // Check that index actually works. - DataSource dataSource; + DataSource dataSource(make_unique()); UNUSED_VALUE(dataSource.Register(platform::LocalCountryFile::MakeForTesting("build_index_test"))); // Make sure that index is actually parsed. diff --git a/indexer/indexer_tests/rank_table_test.cpp b/indexer/indexer_tests/rank_table_test.cpp index 54f9a78b62..2436eb514c 100644 --- a/indexer/indexer_tests/rank_table_test.cpp +++ b/indexer/indexer_tests/rank_table_test.cpp @@ -97,7 +97,7 @@ UNIT_TEST(RankTableBuilder_EndToEnd) search::RankTableBuilder::Create(ranks, wcont); } - DataSource dataSource; + DataSource dataSource(make_unique()); auto regResult = dataSource.RegisterMap(localFile); TEST_EQUAL(regResult.second, MwmSet::RegResult::Success, ()); diff --git a/indexer/indexer_tests/scale_index_reading_tests.cpp b/indexer/indexer_tests/scale_index_reading_tests.cpp index 4718f14445..0693f084ac 100644 --- a/indexer/indexer_tests/scale_index_reading_tests.cpp +++ b/indexer/indexer_tests/scale_index_reading_tests.cpp @@ -54,7 +54,7 @@ public: [&](uint32_t index) { indices.push_back(index); }); } - DataSource::FeaturesLoaderGuard loader(m_dataSource, id); + DataSource::FeaturesLoaderGuard loader(m_dataSource, id, FeatureSourceFactory()); Names names; for (auto const & index : indices) diff --git a/indexer/mwm_set.hpp b/indexer/mwm_set.hpp index 9e193f31e7..62d708734f 100644 --- a/indexer/mwm_set.hpp +++ b/indexer/mwm_set.hpp @@ -29,7 +29,7 @@ class MwmInfo { public: - friend class DataSourceBase; + friend class DataSource; friend class MwmSet; enum MwmTypeT @@ -91,7 +91,7 @@ protected: class MwmInfoEx : public MwmInfo { private: - friend class DataSourceBase; + friend class DataSource; friend class MwmValue; // weak_ptr is needed here to access offsets table in already @@ -315,7 +315,7 @@ public: MwmHandle GetMwmHandleById(MwmId const & id); /// Now this function looks like workaround, but it allows to avoid ugly const_cast everywhere.. - /// Client code usually holds const reference to DataSourceBase, but implementation is non-const. + /// Client code usually holds const reference to DataSource, but implementation is non-const. /// @todo Actually, we need to define, is this behaviour (getting Handle) const or non-const. MwmHandle GetMwmHandleById(MwmId const & id) const { diff --git a/map/booking_availability_filter.cpp b/map/booking_availability_filter.cpp index 723c6630da..298755c553 100644 --- a/map/booking_availability_filter.cpp +++ b/map/booking_availability_filter.cpp @@ -4,8 +4,9 @@ #include "partners_api/booking_api.hpp" -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" +#include "indexer/data_source.hpp" #include "indexer/feature_decl.hpp" #include "platform/platform.hpp" @@ -14,7 +15,7 @@ #include #include -using LoaderGuard = EditableDataSource::FeaturesLoaderGuard; +using LoaderGuard = DataSource::FeaturesLoaderGuard; using namespace booking::filter; @@ -88,7 +89,7 @@ void FillResults(HotelToResults && hotelToResults, std::vector cons } } -void PrepareData(DataSourceBase const & dataSource, search::Results const & results, +void PrepareData(DataSource const & dataSource, search::Results const & results, HotelToResults & hotelToResults, availability::Cache & cache, booking::AvailabilityParams & p) { @@ -111,7 +112,8 @@ void PrepareData(DataSourceBase const & dataSource, search::Results const & resu { if (mwmId != featureId.m_mwmId) { - guard = my::make_unique(dataSource, featureId.m_mwmId); + guard = my::make_unique(dataSource, featureId.m_mwmId, + EditableFeatureSourceFactory()); mwmId = featureId.m_mwmId; } @@ -228,8 +230,8 @@ void AvailabilityFilter::GetFeaturesFromCache(search::Results const & results, { if (mwmId != featureId.m_mwmId) { - guard = - my::make_unique(GetDelegate().GetDataSource(), featureId.m_mwmId); + guard = my::make_unique(GetDelegate().GetDataSource(), featureId.m_mwmId, + EditableFeatureSourceFactory()); mwmId = featureId.m_mwmId; } diff --git a/map/booking_filter.hpp b/map/booking_filter.hpp index bf4fbf71ba..a15e2cd387 100644 --- a/map/booking_filter.hpp +++ b/map/booking_filter.hpp @@ -7,7 +7,7 @@ #include struct FeatureID; -class DataSourceBase; +class DataSource; namespace search { @@ -28,7 +28,7 @@ public: public: virtual ~Delegate() = default; - virtual DataSourceBase const & GetDataSource() const = 0; + virtual DataSource const & GetDataSource() const = 0; virtual Api const & GetApi() const = 0; }; diff --git a/map/booking_filter_processor.cpp b/map/booking_filter_processor.cpp index 22d1cf0f28..0a732ad8fb 100644 --- a/map/booking_filter_processor.cpp +++ b/map/booking_filter_processor.cpp @@ -7,9 +7,8 @@ namespace booking { namespace filter { -FilterProcessor::FilterProcessor(DataSourceBase const & dataSource, booking::Api const & api) - : m_dataSource(dataSource) - , m_api(api) +FilterProcessor::FilterProcessor(DataSource const & dataSource, booking::Api const & api) + : m_dataSource(dataSource), m_api(api) { m_filters.emplace(Type::Deals, std::make_unique(*this)); m_filters.emplace(Type::Availability, std::make_unique(*this)); @@ -60,10 +59,7 @@ void FilterProcessor::GetFeaturesFromCache(Types const & types, search::Results }); } -DataSourceBase const & FilterProcessor::GetDataSource() const -{ - return m_dataSource; -} +DataSource const & FilterProcessor::GetDataSource() const { return m_dataSource; } Api const & FilterProcessor::GetApi() const { diff --git a/map/booking_filter_processor.hpp b/map/booking_filter_processor.hpp index 0b0a91aa35..d99fe7b625 100644 --- a/map/booking_filter_processor.hpp +++ b/map/booking_filter_processor.hpp @@ -12,7 +12,7 @@ #include #include -class DataSourceBase; +class DataSource; namespace search { @@ -46,7 +46,7 @@ using FillSearchMarksCallback = class FilterProcessor : public FilterBase::Delegate { public: - FilterProcessor(DataSourceBase const & dataSource, booking::Api const & api); + FilterProcessor(DataSource const & dataSource, booking::Api const & api); void ApplyFilters(search::Results const & results, TasksInternal && tasks, ApplicationMode const mode); @@ -57,14 +57,14 @@ public: FillSearchMarksCallback const & callback); // FilterInterface::Delegate overrides: - DataSourceBase const & GetDataSource() const override; + DataSource const & GetDataSource() const override; Api const & GetApi() const override; private: void ApplyConsecutively(search::Results const & results, TasksInternal & tasks); void ApplyIndependently(search::Results const & results, TasksInternal const & tasks); - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; Api const & m_api; std::unordered_map m_filters; diff --git a/map/discovery/discovery_manager.cpp b/map/discovery/discovery_manager.cpp index 13693bb942..b8bdc895b4 100644 --- a/map/discovery/discovery_manager.cpp +++ b/map/discovery/discovery_manager.cpp @@ -1,6 +1,8 @@ #include "map/discovery/discovery_manager.hpp" -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" + +#include "indexer/data_source.hpp" #include @@ -23,7 +25,7 @@ std::string GetQuery(discovery::ItemType const type) namespace discovery { -Manager::Manager(DataSourceBase const & dataSource, search::CityFinder & cityFinder, APIs const & apis) +Manager::Manager(DataSource const & dataSource, search::CityFinder & cityFinder, APIs const & apis) : m_dataSource(dataSource) , m_cityFinder(cityFinder) , m_searchApi(apis.m_search) @@ -69,7 +71,8 @@ std::string Manager::GetCityViatorId(m2::PointD const & point) const if (!fid.IsValid()) return {}; - EditableDataSource::FeaturesLoaderGuard const guard(m_dataSource, fid.m_mwmId); + DataSource::FeaturesLoaderGuard const guard(m_dataSource, fid.m_mwmId, + EditableFeatureSourceFactory()); FeatureType ft; if (!guard.GetFeatureByIndex(fid.m_index, ft)) { diff --git a/map/discovery/discovery_manager.hpp b/map/discovery/discovery_manager.hpp index c6010fda04..bb489ec202 100644 --- a/map/discovery/discovery_manager.hpp +++ b/map/discovery/discovery_manager.hpp @@ -23,7 +23,7 @@ #include #include -class DataSourceBase; +class DataSource; namespace discovery { @@ -54,7 +54,7 @@ public: using ErrorCalback = std::function; - Manager(DataSourceBase const & dataSource, search::CityFinder & cityFinder, APIs const & apis); + Manager(DataSource const & dataSource, search::CityFinder & cityFinder, APIs const & apis); template uint32_t Discover(Params && params, ResultCallback const & onResult, ErrorCalback const & onError) @@ -153,7 +153,7 @@ private: static search::DiscoverySearchParams GetSearchParams(Manager::Params const & params, ItemType const type); std::string GetCityViatorId(m2::PointD const & point) const; - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; search::CityFinder & m_cityFinder; SearchAPI & m_searchApi; viator::Api const & m_viatorApi; diff --git a/map/feature_vec_model.cpp b/map/feature_vec_model.cpp index d265a178a3..c8c1d57290 100644 --- a/map/feature_vec_model.cpp +++ b/map/feature_vec_model.cpp @@ -1,5 +1,7 @@ #include "map/feature_vec_model.hpp" +#include "editor/editable_feature_source.hpp" + #include "platform/platform.hpp" #include "indexer/cell_coverer.hpp" @@ -16,7 +18,7 @@ using platform::LocalCountryFile; namespace model { -FeaturesFetcher::FeaturesFetcher() +FeaturesFetcher::FeaturesFetcher() : m_dataSource(make_unique()) { m_dataSource.AddObserver(*this); } diff --git a/map/feature_vec_model.hpp b/map/feature_vec_model.hpp index c3e397563d..37b24f4bb9 100644 --- a/map/feature_vec_model.hpp +++ b/map/feature_vec_model.hpp @@ -1,8 +1,7 @@ #pragma once -#include "editor/editable_data_source.hpp" - #include "indexer/data_header.hpp" +#include "indexer/data_source.hpp" #include "indexer/mwm_set.hpp" #include "geometry/rect2d.hpp" @@ -31,7 +30,7 @@ class FeaturesFetcher : public MwmSet::Observer private: m2::RectD m_rect; - EditableDataSource m_dataSource; + DataSource m_dataSource; TMapDeregisteredCallback m_onMapDeregistered; @@ -91,8 +90,8 @@ class FeaturesFetcher : public MwmSet::Observer } //@} - DataSourceBase const & GetDataSource() const { return m_dataSource; } - DataSourceBase & GetDataSource() { return m_dataSource; } + DataSource const & GetDataSource() const { return m_dataSource; } + DataSource & GetDataSource() { return m_dataSource; } m2::RectD GetWorldRect() const; }; } diff --git a/map/framework.cpp b/map/framework.cpp index c10d0baa0b..a6b0818b20 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -39,11 +39,12 @@ #include "drape/constants.hpp" -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" #include "indexer/categories_holder.hpp" #include "indexer/classificator.hpp" #include "indexer/classificator_loader.hpp" +#include "indexer/data_source.hpp" #include "indexer/drawing_rules.hpp" #include "indexer/editable_map_object.hpp" #include "indexer/feature.hpp" @@ -371,7 +372,7 @@ Framework::Framework(FrameworkParams const & params) bind(&Framework::GetMwmsByRect, this, _1, false /* rough */)) , m_routingManager( RoutingManager::Callbacks( - [this]() -> DataSourceBase & { return m_model.GetDataSource(); }, + [this]() -> DataSource & { return m_model.GetDataSource(); }, [this]() -> storage::CountryInfoGetter & { return GetCountryInfoGetter(); }, [this](string const & id) -> string { return m_storage.GetParentIdFor(id); }, [this]() -> StringsBundle const & { return m_stringsBundle; }), @@ -749,7 +750,8 @@ void Framework::FillFeatureInfo(FeatureID const & fid, place_page::Info & info) return; } - EditableDataSource::FeaturesLoaderGuard const guard(m_model.GetDataSource(), fid.m_mwmId); + DataSource::FeaturesLoaderGuard const guard(m_model.GetDataSource(), fid.m_mwmId, + EditableFeatureSourceFactory()); FeatureType ft; if (!guard.GetFeatureByIndex(fid.m_index, ft)) { @@ -2085,7 +2087,8 @@ bool Framework::GetFeatureByID(FeatureID const & fid, FeatureType & ft) const { ASSERT(fid.IsValid(), ()); - EditableDataSource::FeaturesLoaderGuard guard(m_model.GetDataSource(), fid.m_mwmId); + DataSource::FeaturesLoaderGuard guard(m_model.GetDataSource(), fid.m_mwmId, + EditableFeatureSourceFactory()); if (!guard.GetFeatureByIndex(fid.m_index, ft)) return false; @@ -2604,7 +2607,8 @@ vector Framework::GetSelectedFeatureTriangles() const if (!m_selectedFeature.IsValid()) return triangles; - EditableDataSource::FeaturesLoaderGuard const guard(m_model.GetDataSource(), m_selectedFeature.m_mwmId); + DataSource::FeaturesLoaderGuard const guard(m_model.GetDataSource(), m_selectedFeature.m_mwmId, + EditableFeatureSourceFactory()); FeatureType ft; if (!guard.GetFeatureByIndex(m_selectedFeature.m_index, ft)) return triangles; @@ -2738,10 +2742,10 @@ bool Framework::ParseEditorDebugCommand(search::SearchParams const & params) namespace { -WARN_UNUSED_RESULT bool LocalizeStreet(DataSourceBase const & dataSource, FeatureID const & fid, +WARN_UNUSED_RESULT bool LocalizeStreet(DataSource const & dataSource, FeatureID const & fid, osm::LocalizedStreet & result) { - EditableDataSource::FeaturesLoaderGuard g(dataSource, fid.m_mwmId); + DataSource::FeaturesLoaderGuard g(dataSource, fid.m_mwmId, EditableFeatureSourceFactory()); FeatureType ft; if (!g.GetFeatureByIndex(fid.m_index, ft)) return false; @@ -2754,7 +2758,7 @@ WARN_UNUSED_RESULT bool LocalizeStreet(DataSourceBase const & dataSource, Featur } vector TakeSomeStreetsAndLocalize( - vector const & streets, DataSourceBase const & dataSource) + vector const & streets, DataSource const & dataSource) { vector results; @@ -2783,7 +2787,7 @@ vector TakeSomeStreetsAndLocalize( return results; } -void SetStreet(search::ReverseGeocoder const & coder, DataSourceBase const & dataSource, +void SetStreet(search::ReverseGeocoder const & coder, DataSource const & dataSource, FeatureType & ft, osm::EditableMapObject & emo) { auto const & editor = osm::Editor::Instance(); @@ -2850,7 +2854,7 @@ void SetStreet(search::ReverseGeocoder const & coder, DataSourceBase const & dat emo.SetNearbyStreets(move(localizedStreets)); } -void SetHostingBuildingAddress(FeatureID const & hostingBuildingFid, DataSourceBase const & dataSource, +void SetHostingBuildingAddress(FeatureID const & hostingBuildingFid, DataSource const & dataSource, search::ReverseGeocoder const & coder, osm::EditableMapObject & emo) { if (!hostingBuildingFid.IsValid()) @@ -2858,7 +2862,8 @@ void SetHostingBuildingAddress(FeatureID const & hostingBuildingFid, DataSourceB FeatureType hostingBuildingFeature; - EditableDataSource::FeaturesLoaderGuard g(dataSource, hostingBuildingFid.m_mwmId); + DataSource::FeaturesLoaderGuard g(dataSource, hostingBuildingFid.m_mwmId, + EditableFeatureSourceFactory()); if (!g.GetFeatureByIndex(hostingBuildingFid.m_index, hostingBuildingFeature)) return; @@ -2952,7 +2957,8 @@ osm::Editor::SaveResult Framework::SaveEditedMapObject(osm::EditableMapObject em { auto const isCreatedFeature = editor.IsCreatedFeature(emo.GetID()); - EditableDataSource::FeaturesLoaderGuard g(m_model.GetDataSource(), emo.GetID().m_mwmId); + DataSource::FeaturesLoaderGuard g(m_model.GetDataSource(), emo.GetID().m_mwmId, + EditableFeatureSourceFactory()); FeatureType originalFeature; if (!isCreatedFeature) { diff --git a/map/framework.hpp b/map/framework.hpp index 24f6f0233c..bd2619eebf 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -311,7 +311,7 @@ public: storage::CountryInfoGetter & GetCountryInfoGetter() { return *m_infoGetter; } StorageDownloadingPolicy & GetDownloadingPolicy() { return m_storageDownloadingPolicy; } - DataSourceBase const & GetDataSource() const { return m_model.GetDataSource(); } + DataSource const & GetDataSource() const { return m_model.GetDataSource(); } SearchAPI & GetSearchAPI(); SearchAPI const & GetSearchAPI() const; diff --git a/map/local_ads_manager.hpp b/map/local_ads_manager.hpp index 983940a8af..b790918c06 100644 --- a/map/local_ads_manager.hpp +++ b/map/local_ads_manager.hpp @@ -25,8 +25,6 @@ #include #include -class DataSourceBase; - namespace feature { class TypesHolder; diff --git a/map/map_tests/address_tests.cpp b/map/map_tests/address_tests.cpp index 2b54ef1fba..91834155a4 100644 --- a/map/map_tests/address_tests.cpp +++ b/map/map_tests/address_tests.cpp @@ -33,7 +33,7 @@ UNIT_TEST(ReverseGeocoder_Smoke) LocalCountryFile file = LocalCountryFile::MakeForTesting("minsk-pass"); - DataSource dataSource; + DataSource dataSource(make_unique()); TEST_EQUAL(dataSource.RegisterMap(file).second, MwmSet::RegResult::Success, ()); ReverseGeocoder coder(dataSource); diff --git a/map/map_tests/booking_filter_test.cpp b/map/map_tests/booking_filter_test.cpp index 4c4aa7bb0d..8664127383 100644 --- a/map/map_tests/booking_filter_test.cpp +++ b/map/map_tests/booking_filter_test.cpp @@ -29,7 +29,7 @@ class TestMwmEnvironment : public TestWithCustomMwms, public FilterBase::Delegate { public: - DataSourceBase const & GetDataSource() const override { return m_dataSource; } + DataSource const & GetDataSource() const override { return m_dataSource; } booking::Api const & GetApi() const override { return m_api; } diff --git a/map/routing_manager.hpp b/map/routing_manager.hpp index 5e6ed26bca..70f4f5772d 100644 --- a/map/routing_manager.hpp +++ b/map/routing_manager.hpp @@ -41,7 +41,7 @@ namespace routing class NumMwmIds; } -class DataSourceBase; +class DataSource; struct RoutePointInfo { @@ -67,7 +67,7 @@ public: struct Callbacks { - using DataSourceGetterFn = std::function; + using DataSourceGetterFn = std::function; using CountryInfoGetterFn = std::function; using CountryParentNameGetterFn = std::function; using GetStringsBundleFn = std::function; diff --git a/map/search_api.cpp b/map/search_api.cpp index 6a8a41667b..18b8b85fd4 100644 --- a/map/search_api.cpp +++ b/map/search_api.cpp @@ -116,7 +116,7 @@ private: }; } // namespace -SearchAPI::SearchAPI(DataSourceBase & dataSource, storage::Storage const & storage, +SearchAPI::SearchAPI(DataSource & dataSource, storage::Storage const & storage, storage::CountryInfoGetter const & infoGetter, Delegate & delegate) : m_dataSource(dataSource) , m_storage(storage) diff --git a/map/search_api.hpp b/map/search_api.hpp index 257bad307f..11e39d0dbf 100644 --- a/map/search_api.hpp +++ b/map/search_api.hpp @@ -25,7 +25,7 @@ #include -class DataSourceBase; +class DataSource; namespace search { @@ -87,7 +87,7 @@ public: virtual search::ProductInfo GetProductInfo(search::Result const & result) const { return {}; }; }; - SearchAPI(DataSourceBase & dataSource, storage::Storage const & storage, + SearchAPI(DataSource & dataSource, storage::Storage const & storage, storage::CountryInfoGetter const & infoGetter, Delegate & delegate); virtual ~SearchAPI() = default; @@ -155,7 +155,7 @@ private: bool QueryMayBeSkipped(search::SearchParams const & prevParams, search::SearchParams const & currParams) const; - DataSourceBase & m_dataSource; + DataSource & m_dataSource; storage::Storage const & m_storage; storage::CountryInfoGetter const & m_infoGetter; Delegate & m_delegate; diff --git a/map/transit/transit_reader.cpp b/map/transit/transit_reader.cpp index 6c039ca436..6a6ee0fe43 100644 --- a/map/transit/transit_reader.cpp +++ b/map/transit/transit_reader.cpp @@ -137,11 +137,10 @@ unique_ptr && ReadTransitTask::GetTransitInfo() return move(m_transitInfo); } -TransitReadManager::TransitReadManager(DataSourceBase & dataSource, TReadFeaturesFn const & readFeaturesFn, +TransitReadManager::TransitReadManager(DataSource & dataSource, + TReadFeaturesFn const & readFeaturesFn, GetMwmsByRectFn const & getMwmsByRectFn) - : m_dataSource(dataSource) - , m_readFeaturesFn(readFeaturesFn) - , m_getMwmsByRectFn(getMwmsByRectFn) + : m_dataSource(dataSource), m_readFeaturesFn(readFeaturesFn), m_getMwmsByRectFn(getMwmsByRectFn) { Start(); } diff --git a/map/transit/transit_reader.hpp b/map/transit/transit_reader.hpp index 2df70dda9d..4b6a8c81b1 100644 --- a/map/transit/transit_reader.hpp +++ b/map/transit/transit_reader.hpp @@ -23,7 +23,7 @@ #include #include -class DataSourceBase; +class DataSource; using FeatureCallback = std::function; using TReadFeaturesFn = std::function const &)>; @@ -31,8 +31,7 @@ using TReadFeaturesFn = std::function(m2::RectD const &)>; using TransitStateChangedFn = function; - TransitReadManager(DataSourceBase & dataSource, TReadFeaturesFn const & readFeaturesFn, + TransitReadManager(DataSource & dataSource, TReadFeaturesFn const & readFeaturesFn, GetMwmsByRectFn const & getMwmsByRectFn); ~TransitReadManager(); @@ -122,7 +121,7 @@ private: uint64_t m_nextTasksGroupId = 0; std::map m_tasksGroups; - DataSourceBase & m_dataSource; + DataSource & m_dataSource; TReadFeaturesFn m_readFeaturesFn; df::DrapeEngineSafePtr m_drapeEngine; diff --git a/openlr/candidate_points_getter.hpp b/openlr/candidate_points_getter.hpp index 618ddea02f..3b1e7de5f6 100644 --- a/openlr/candidate_points_getter.hpp +++ b/openlr/candidate_points_getter.hpp @@ -17,7 +17,7 @@ class CandidatePointsGetter { public: CandidatePointsGetter(size_t const maxJunctionCandidates, size_t const maxProjectionCandidates, - DataSourceBase const & dataSource, Graph & graph) + DataSource const & dataSource, Graph & graph) : m_maxJunctionCandidates(maxJunctionCandidates) , m_maxProjectionCandidates(maxProjectionCandidates) , m_dataSource(dataSource) @@ -38,7 +38,7 @@ private: size_t const m_maxJunctionCandidates; size_t const m_maxProjectionCandidates; - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; Graph & m_graph; }; } // namespace openlr diff --git a/openlr/decoded_path.cpp b/openlr/decoded_path.cpp index 33642c2567..1871e10b6d 100644 --- a/openlr/decoded_path.cpp +++ b/openlr/decoded_path.cpp @@ -45,7 +45,7 @@ void LatLonFromXML(pugi::xml_node const & node, ms::LatLon & latLon) latLon.lon = node.child("lon").text().as_double(); } -void FeatureIdFromXML(pugi::xml_node const & node, DataSourceBase const & dataSource, FeatureID & fid) +void FeatureIdFromXML(pugi::xml_node const & node, DataSource const & dataSource, FeatureID & fid) { THROW_IF_NODE_IS_EMPTY(node, openlr::DecodedPathLoadError, ("Can't parse CountryName")); auto const countryName = node.child("CountryName").text().as_string(); @@ -109,7 +109,7 @@ void WriteAsMappingForSpark(std::ostream & ost, std::vector const & } } -void PathFromXML(pugi::xml_node const & node, DataSourceBase const & dataSource, Path & p) +void PathFromXML(pugi::xml_node const & node, DataSource const & dataSource, Path & p) { auto const edges = node.select_nodes("RoadEdge"); for (auto const xmlE : edges) diff --git a/openlr/decoded_path.hpp b/openlr/decoded_path.hpp index 18875937f3..19a66a1409 100644 --- a/openlr/decoded_path.hpp +++ b/openlr/decoded_path.hpp @@ -11,7 +11,7 @@ #include "3party/pugixml/src/pugixml.hpp" -class DataSourceBase; +class DataSource; namespace openlr { @@ -33,7 +33,7 @@ struct DecodedPath void WriteAsMappingForSpark(std::string const & fileName, std::vector const & paths); void WriteAsMappingForSpark(std::ostream & ost, std::vector const & paths); -void PathFromXML(pugi::xml_node const & node, DataSourceBase const & dataSource, Path & path); +void PathFromXML(pugi::xml_node const & node, DataSource const & dataSource, Path & path); void PathToXML(Path const & path, pugi::xml_node & node); } // namespace openlr diff --git a/openlr/graph.cpp b/openlr/graph.cpp index c2da01d639..cad486d404 100644 --- a/openlr/graph.cpp +++ b/openlr/graph.cpp @@ -1,7 +1,5 @@ #include "openlr/graph.hpp" -class DataSourceBase; - using namespace routing; namespace openlr @@ -30,7 +28,7 @@ void GetRegularEdges(Junction const & junction, IRoadGraph const & graph, } } // namespace -Graph::Graph(DataSourceBase const & dataSource, shared_ptr carModelFactory) +Graph::Graph(DataSource const & dataSource, shared_ptr carModelFactory) : m_graph(dataSource, IRoadGraph::Mode::ObeyOnewayTag, carModelFactory) { } diff --git a/openlr/graph.hpp b/openlr/graph.hpp index 7a5863a4d2..5196f08273 100644 --- a/openlr/graph.hpp +++ b/openlr/graph.hpp @@ -12,7 +12,7 @@ #include #include -class DataSourceBase; +class DataSource; namespace openlr { @@ -24,7 +24,7 @@ public: using EdgeVector = routing::FeaturesRoadGraph::TEdgeVector; using Junction = routing::Junction; - Graph(DataSourceBase const & dataSource, std::shared_ptr carModelFactory); + Graph(DataSource const & dataSource, std::shared_ptr carModelFactory); // Appends edges such as that edge.GetStartJunction() == junction to the |edges|. void GetOutgoingEdges(routing::Junction const & junction, EdgeVector & edges); diff --git a/openlr/openlr_decoder.cpp b/openlr/openlr_decoder.cpp index 42adfb9689..8c6c12ddd2 100644 --- a/openlr/openlr_decoder.cpp +++ b/openlr/openlr_decoder.cpp @@ -81,7 +81,7 @@ struct alignas(kCacheLineSize) Stats bool IsRealVertex(m2::PointD const & p, FeatureID const & fid, DataSource const & dataSource) { - DataSource::FeaturesLoaderGuard g(dataSource, fid.m_mwmId); + DataSource::FeaturesLoaderGuard g(dataSource, fid.m_mwmId, FeatureSourceFactory()); auto const ft = g.GetOriginalFeatureByIndex(fid.m_index); bool matched = false; ft->ForEachPoint( @@ -189,7 +189,7 @@ void CopyWithoutOffsets(InputIterator const start, InputIterator const stop, Out class SegmentsDecoderV1 { public: - SegmentsDecoderV1(DataSourceBase const & dataSource, unique_ptr cmf) + SegmentsDecoderV1(DataSource const & dataSource, unique_ptr cmf) : m_roadGraph(dataSource, IRoadGraph::Mode::ObeyOnewayTag, move(cmf)) , m_infoGetter(dataSource) , m_router(m_roadGraph, m_infoGetter) @@ -378,7 +378,7 @@ bool OpenLRDecoder::SegmentsFilter::Matches(LinearSegment const & segment) const } // OpenLRDecoder ----------------------------------------------------------------------------- -OpenLRDecoder::OpenLRDecoder(vector const & dataSources, +OpenLRDecoder::OpenLRDecoder(vector> const & dataSources, CountryParentNameGetter const & countryParentNameGetter) : m_dataSources(dataSources), m_countryParentNameGetter(countryParentNameGetter) { @@ -430,9 +430,9 @@ void OpenLRDecoder::Decode(vector const & segments, vector stats(numThreads); vector workers; for (size_t i = 1; i < numThreads; ++i) - workers.emplace_back(worker, i, ref(m_dataSources[i]), ref(stats[i])); + workers.emplace_back(worker, i, ref(*m_dataSources[i]), ref(stats[i])); - worker(0 /* threadNum */, m_dataSources[0], stats[0]); + worker(0 /* threadNum */, *m_dataSources[0], stats[0]); for (auto & worker : workers) worker.join(); diff --git a/openlr/openlr_decoder.hpp b/openlr/openlr_decoder.hpp index f893217718..a50cd08247 100644 --- a/openlr/openlr_decoder.hpp +++ b/openlr/openlr_decoder.hpp @@ -40,7 +40,7 @@ public: bool const m_multipointsOnly; }; - OpenLRDecoder(std::vector const & dataSources, + OpenLRDecoder(std::vector> const & dataSources, CountryParentNameGetter const & countryParentNameGetter); // Maps partner segments to mwm paths. |segments| should be sorted by partner id. @@ -55,7 +55,7 @@ private: void Decode(std::vector const & segments, uint32_t const numThreads, std::vector & paths); - std::vector const & m_dataSources; + std::vector> const & m_dataSources; CountryParentNameGetter m_countryParentNameGetter; }; } // namespace openlr diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp b/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp index 8cb93fc125..1ee4a5f296 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp @@ -229,7 +229,7 @@ public: private: Framework & m_framework; - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; routing::FeaturesRoadGraph m_roadGraph; }; } // namespace diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.cpp b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.cpp index 1c8fe93757..e1fbe1929f 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.cpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.cpp @@ -102,8 +102,7 @@ void RoadPointCandidate::SetActivePoint(FeatureID const & fid) namespace openlr { // TrafficMode ------------------------------------------------------------------------------------- -TrafficMode::TrafficMode(std::string const & dataFileName, - DataSourceBase const & dataSource, +TrafficMode::TrafficMode(std::string const & dataFileName, DataSource const & dataSource, std::unique_ptr drawerDelegate, std::unique_ptr pointsDelegate, QObject * parent) diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.hpp b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.hpp index 42ad40cd24..4d7c88654d 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.hpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.hpp @@ -67,8 +67,7 @@ class TrafficMode : public QAbstractTableModel public: // TODO(mgsergio): Check we are on the right mwm. I.e. right mwm version and everything. - TrafficMode(std::string const & dataFileName, - DataSourceBase const & dataSource, + TrafficMode(std::string const & dataFileName, DataSource const & dataSource, std::unique_ptr drawerDelegate, std::unique_ptr pointsDelegate, QObject * parent = Q_NULLPTR); @@ -114,7 +113,7 @@ private: void HandlePoint(m2::PointD clickPoint, Qt::MouseButton const button); bool StartBuildingPathChecks() const; - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; std::vector m_segments; // Non-owning pointer to an element of m_segments. SegmentCorrespondence * m_currentSegment = nullptr; diff --git a/openlr/openlr_stat/openlr_stat.cpp b/openlr/openlr_stat/openlr_stat.cpp index 705d1d17d0..7b34a6ad99 100644 --- a/openlr/openlr_stat/openlr_stat.cpp +++ b/openlr/openlr_stat/openlr_stat.cpp @@ -58,7 +58,8 @@ int32_t const kMinNumThreads = 1; int32_t const kMaxNumThreads = 128; int32_t const kHandleAllSegments = -1; -void LoadDataSources(std::string const & pathToMWMFolder, std::vector & dataSources) +void LoadDataSources(std::string const & pathToMWMFolder, + std::vector> & dataSources) { CHECK(Platform::IsDirectory(pathToMWMFolder), (pathToMWMFolder, "must be a directory.")); @@ -84,7 +85,7 @@ void LoadDataSources(std::string const & pathToMWMFolder, std::vectorRegisterMap(localFile); CHECK_EQUAL(result.second, MwmSet::RegResult::Success, ("Can't register mwm:", localFile)); auto const & info = result.first.GetInfo(); @@ -259,7 +260,10 @@ int main(int argc, char * argv[]) auto const numThreads = static_cast(FLAGS_num_threads); - std::vector dataSources(numThreads); + std::vector> dataSources(numThreads); + for (size_t i = 0; i < numThreads; ++i) + dataSources.push_back(std::make_unique(std::make_unique())); + LoadDataSources(FLAGS_mwms_path, dataSources); OpenLRDecoder decoder(dataSources, storage::CountryParentGetter(FLAGS_countries_filename, diff --git a/openlr/openlr_tests/decoded_path_test.cpp b/openlr/openlr_tests/decoded_path_test.cpp index 9f1753bb21..01c12a4015 100644 --- a/openlr/openlr_tests/decoded_path_test.cpp +++ b/openlr/openlr_tests/decoded_path_test.cpp @@ -133,14 +133,14 @@ void WithRoad(vector const & points, Func && fn) builder.Add(TestRoad(points, "Interstate 60", "en")); } - DataSource dataSource; + DataSource dataSource(make_unique()); auto const regResult = dataSource.RegisterMap(country); TEST_EQUAL(regResult.second, MwmSet::RegResult::Success, ()); MwmSet::MwmHandle mwmHandle = dataSource.GetMwmHandleById(regResult.first); TEST(mwmHandle.IsAlive(), ()); - DataSource::FeaturesLoaderGuard const guard(dataSource, regResult.first); + DataSource::FeaturesLoaderGuard const guard(dataSource, regResult.first, FeatureSourceFactory()); FeatureType road; TEST(guard.GetFeatureByIndex(0, road), ()); road.ParseEverything(); diff --git a/openlr/road_info_getter.cpp b/openlr/road_info_getter.cpp index 96ffac93aa..bce9bb9c47 100644 --- a/openlr/road_info_getter.cpp +++ b/openlr/road_info_getter.cpp @@ -10,7 +10,7 @@ namespace openlr { -RoadInfoGetter::RoadInfoGetter(DataSourceBase const & dataSource) +RoadInfoGetter::RoadInfoGetter(DataSource const & dataSource) : m_dataSource(dataSource), m_c(classif()) { } @@ -21,7 +21,7 @@ RoadInfoGetter::RoadInfo RoadInfoGetter::Get(FeatureID const & fid) if (it != end(m_cache)) return it->second; - DataSource::FeaturesLoaderGuard g(m_dataSource, fid.m_mwmId); + DataSource::FeaturesLoaderGuard g(m_dataSource, fid.m_mwmId, FeatureSourceFactory()); FeatureType ft; CHECK(g.GetOriginalFeatureByIndex(fid.m_index, ft), ()); diff --git a/openlr/road_info_getter.hpp b/openlr/road_info_getter.hpp index 45c7f69060..9a83343623 100644 --- a/openlr/road_info_getter.hpp +++ b/openlr/road_info_getter.hpp @@ -8,7 +8,7 @@ #include "std/map.hpp" class Classificator; -class DataSourceBase; +class DataSource; namespace feature { @@ -28,7 +28,7 @@ public: FormOfWay m_fow = FormOfWay::NotAValue; }; - RoadInfoGetter(DataSourceBase const & dataSource); + RoadInfoGetter(DataSource const & dataSource); RoadInfo Get(FeatureID const & fid); @@ -36,7 +36,7 @@ public: FunctionalRoadClass GetFunctionalRoadClass(feature::TypesHolder const & types) const; FormOfWay GetFormOfWay(feature::TypesHolder const & types) const; - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; Classificator const & m_c; TrunkChecker const m_trunkChecker; diff --git a/routing/bicycle_directions.cpp b/routing/bicycle_directions.cpp index ff04e15bb4..994a84ef09 100644 --- a/routing/bicycle_directions.cpp +++ b/routing/bicycle_directions.cpp @@ -12,7 +12,7 @@ #include "routing_common/car_model.hpp" -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" #include "indexer/ftypes_matcher.hpp" #include "indexer/scales.hpp" @@ -158,7 +158,8 @@ bool BicycleDirectionsEngine::AdjacentEdges::IsAlmostEqual(AdjacentEdges const & } // BicycleDirectionsEngine ------------------------------------------------------------------------ -BicycleDirectionsEngine::BicycleDirectionsEngine(DataSourceBase const & dataSource, shared_ptr numMwmIds) +BicycleDirectionsEngine::BicycleDirectionsEngine(DataSource const & dataSource, + shared_ptr numMwmIds) : m_dataSource(dataSource), m_numMwmIds(numMwmIds) { CHECK(m_numMwmIds, ()); @@ -210,10 +211,11 @@ bool BicycleDirectionsEngine::Generate(IndexRoadGraph const & graph, vectorGetId()) - m_loader = make_unique(m_dataSource, id); + m_loader = make_unique(m_dataSource, id, + EditableFeatureSourceFactory()); return *m_loader; } diff --git a/routing/bicycle_directions.hpp b/routing/bicycle_directions.hpp index a95d79898e..7a82d999c7 100644 --- a/routing/bicycle_directions.hpp +++ b/routing/bicycle_directions.hpp @@ -7,7 +7,7 @@ #include "routing_common/num_mwm_id.hpp" -#include "editor/editable_data_source.hpp" +#include "indexer/data_source.hpp" #include #include @@ -28,7 +28,7 @@ public: using AdjacentEdgesMap = std::map; - BicycleDirectionsEngine(DataSourceBase const & dataSource, std::shared_ptr numMwmIds); + BicycleDirectionsEngine(DataSource const & dataSource, std::shared_ptr numMwmIds); // IDirectionsEngine override: bool Generate(IndexRoadGraph const & graph, vector const & path, @@ -37,7 +37,7 @@ public: vector & segments) override; private: - EditableDataSource::FeaturesLoaderGuard & GetLoader(MwmSet::MwmId const & id); + DataSource::FeaturesLoaderGuard & GetLoader(MwmSet::MwmId const & id); void LoadPathAttributes(FeatureID const & featureId, LoadedPathSegment & pathSegment); void GetSegmentRangeAndAdjacentEdges(IRoadGraph::TEdgeVector const & outgoingEdges, Edge const & inEdge, uint32_t startSegId, uint32_t endSegId, @@ -56,8 +56,8 @@ private: AdjacentEdgesMap m_adjacentEdges; TUnpackedPathSegments m_pathSegments; - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; std::shared_ptr m_numMwmIds; - std::unique_ptr m_loader; + std::unique_ptr m_loader; }; } // namespace routing diff --git a/routing/cross_mwm_graph.cpp b/routing/cross_mwm_graph.cpp index 7351265c5e..1ee17c701e 100644 --- a/routing/cross_mwm_graph.cpp +++ b/routing/cross_mwm_graph.cpp @@ -50,7 +50,7 @@ CrossMwmGraph::CrossMwmGraph(shared_ptr numMwmIds, shared_ptr> numMwmTree, shared_ptr vehicleModelFactory, VehicleType vehicleType, CourntryRectFn const & countryRectFn, - DataSourceBase & dataSource) + DataSource & dataSource) : m_dataSource(dataSource) , m_numMwmIds(numMwmIds) , m_numMwmTree(numMwmTree) diff --git a/routing/cross_mwm_graph.hpp b/routing/cross_mwm_graph.hpp index 601ff16ad6..c5f5a8888d 100644 --- a/routing/cross_mwm_graph.hpp +++ b/routing/cross_mwm_graph.hpp @@ -20,7 +20,7 @@ #include #include -class DataSourceBase; +class DataSource; namespace routing { @@ -36,8 +36,9 @@ public: }; CrossMwmGraph(std::shared_ptr numMwmIds, shared_ptr> numMwmTree, - std::shared_ptr vehicleModelFactory, VehicleType vehicleType, - CourntryRectFn const & countryRectFn, DataSourceBase & dataSource); + std::shared_ptr vehicleModelFactory, + VehicleType vehicleType, CourntryRectFn const & countryRectFn, + DataSource & dataSource); /// \brief Transition segment is a segment which is crossed by mwm border. That means /// start and finish of such segment have to lie in different mwms. If a segment is @@ -148,7 +149,7 @@ private: void DeserializeTransitions(std::vector const & mwmIds); void DeserializeTransitTransitions(std::vector const & mwmIds); - DataSourceBase & m_dataSource; + DataSource & m_dataSource; std::shared_ptr m_numMwmIds; std::shared_ptr> m_numMwmTree; std::shared_ptr m_vehicleModelFactory; diff --git a/routing/cross_mwm_index_graph.hpp b/routing/cross_mwm_index_graph.hpp index eb69f9bb1d..9c265ee342 100644 --- a/routing/cross_mwm_index_graph.hpp +++ b/routing/cross_mwm_index_graph.hpp @@ -66,7 +66,8 @@ class CrossMwmIndexGraph final public: using ReaderSourceFile = ReaderSource; - CrossMwmIndexGraph(DataSourceBase & dataSource, std::shared_ptr numMwmIds, VehicleType vehicleType) + CrossMwmIndexGraph(DataSource & dataSource, std::shared_ptr numMwmIds, + VehicleType vehicleType) : m_dataSource(dataSource), m_numMwmIds(numMwmIds), m_vehicleType(vehicleType) { } @@ -193,7 +194,7 @@ private: return it->second; } - DataSourceBase & m_dataSource; + DataSource & m_dataSource; std::shared_ptr m_numMwmIds; VehicleType m_vehicleType; diff --git a/routing/features_road_graph.cpp b/routing/features_road_graph.cpp index 459b88d843..fd4da18fc2 100644 --- a/routing/features_road_graph.cpp +++ b/routing/features_road_graph.cpp @@ -4,9 +4,10 @@ #include "routing_common/vehicle_model.hpp" -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" #include "indexer/classificator.hpp" +#include "indexer/data_source.hpp" #include "indexer/ftypes_matcher.hpp" #include "indexer/scales.hpp" @@ -30,7 +31,7 @@ double constexpr kMwmCrossingNodeEqualityRadiusMeters = 100.0; double GetRoadCrossingRadiusMeters() { return kMwmRoadCrossingRadiusMeters; } -FeaturesRoadGraph::Value::Value(DataSourceBase const & dataSource, MwmSet::MwmHandle handle) +FeaturesRoadGraph::Value::Value(DataSource const & dataSource, MwmSet::MwmHandle handle) : m_mwmHandle(move(handle)) { if (!m_mwmHandle.IsAlive()) @@ -111,7 +112,7 @@ void FeaturesRoadGraph::RoadInfoCache::Clear() { m_cache.clear(); } -FeaturesRoadGraph::FeaturesRoadGraph(DataSourceBase const & dataSource, IRoadGraph::Mode mode, +FeaturesRoadGraph::FeaturesRoadGraph(DataSource const & dataSource, IRoadGraph::Mode mode, shared_ptr vehicleModelFactory) : m_dataSource(dataSource), m_mode(mode), m_vehicleModel(vehicleModelFactory) { @@ -205,7 +206,8 @@ void FeaturesRoadGraph::FindClosestEdges(m2::PointD const & point, uint32_t coun void FeaturesRoadGraph::GetFeatureTypes(FeatureID const & featureId, feature::TypesHolder & types) const { FeatureType ft; - EditableDataSource::FeaturesLoaderGuard loader(m_dataSource, featureId.m_mwmId); + DataSource::FeaturesLoaderGuard loader(m_dataSource, featureId.m_mwmId, + EditableFeatureSourceFactory()); if (!loader.GetFeatureByIndex(featureId.m_index, ft)) return; @@ -306,7 +308,8 @@ IRoadGraph::RoadInfo const & FeaturesRoadGraph::GetCachedRoadInfo(FeatureID cons FeatureType ft; - EditableDataSource::FeaturesLoaderGuard loader(m_dataSource, featureId.m_mwmId); + DataSource::FeaturesLoaderGuard loader(m_dataSource, featureId.m_mwmId, + EditableFeatureSourceFactory()); if (!loader.GetFeatureByIndex(featureId.m_index, ft)) return ri; diff --git a/routing/features_road_graph.hpp b/routing/features_road_graph.hpp index 59bcc98567..4214fa72ce 100644 --- a/routing/features_road_graph.hpp +++ b/routing/features_road_graph.hpp @@ -16,7 +16,7 @@ #include "std/unique_ptr.hpp" #include "std/vector.hpp" -class DataSourceBase; +class DataSource; class FeatureType; namespace routing @@ -63,7 +63,7 @@ private: }; public: - FeaturesRoadGraph(DataSourceBase const & dataSource, IRoadGraph::Mode mode, + FeaturesRoadGraph(DataSource const & dataSource, IRoadGraph::Mode mode, shared_ptr vehicleModelFactory); static int GetStreetReadScale(); @@ -89,7 +89,7 @@ private: struct Value { Value() = default; - Value(DataSourceBase const & dataSource, MwmSet::MwmHandle handle); + Value(DataSource const & dataSource, MwmSet::MwmHandle handle); bool IsAlive() const { return m_mwmHandle.IsAlive(); } @@ -112,7 +112,7 @@ private: Value const & LockMwm(MwmSet::MwmId const & mwmId) const; - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; IRoadGraph::Mode const m_mode; mutable RoadInfoCache m_cache; mutable CrossCountryVehicleModel m_vehicleModel; diff --git a/routing/geometry.cpp b/routing/geometry.cpp index 6b78be91b1..a1adeedc60 100644 --- a/routing/geometry.cpp +++ b/routing/geometry.cpp @@ -2,9 +2,10 @@ #include "routing/routing_exceptions.hpp" -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" #include "indexer/altitude_loader.hpp" +#include "indexer/data_source.hpp" #include "geometry/mercator.hpp" @@ -25,7 +26,7 @@ size_t constexpr kRoadsCacheSize = 5000; class GeometryLoaderImpl final : public GeometryLoader { public: - GeometryLoaderImpl(DataSourceBase const & dataSource, MwmSet::MwmHandle const & handle, + GeometryLoaderImpl(DataSource const & dataSource, MwmSet::MwmHandle const & handle, shared_ptr vehicleModel, bool loadAltitudes); // GeometryLoader overrides: @@ -33,16 +34,18 @@ public: private: shared_ptr m_vehicleModel; - EditableDataSource::FeaturesLoaderGuard m_guard; + DataSource::FeaturesLoaderGuard m_guard; string const m_country; feature::AltitudeLoader m_altitudeLoader; bool const m_loadAltitudes; }; -GeometryLoaderImpl::GeometryLoaderImpl(DataSourceBase const & dataSource, MwmSet::MwmHandle const & handle, - shared_ptr vehicleModel, bool loadAltitudes) +GeometryLoaderImpl::GeometryLoaderImpl(DataSource const & dataSource, + MwmSet::MwmHandle const & handle, + shared_ptr vehicleModel, + bool loadAltitudes) : m_vehicleModel(move(vehicleModel)) - , m_guard(dataSource, handle.GetId()) + , m_guard(dataSource, handle.GetId(), EditableFeatureSourceFactory()) , m_country(handle.GetInfo()->GetCountryName()) , m_altitudeLoader(dataSource, handle.GetId()) , m_loadAltitudes(loadAltitudes) @@ -161,7 +164,7 @@ RoadGeometry const & Geometry::GetRoad(uint32_t featureId) } // static -unique_ptr GeometryLoader::Create(DataSourceBase const & dataSource, +unique_ptr GeometryLoader::Create(DataSource const & dataSource, MwmSet::MwmHandle const & handle, shared_ptr vehicleModel, bool loadAltitudes) diff --git a/routing/geometry.hpp b/routing/geometry.hpp index 5ea0b2cfa8..71593904be 100644 --- a/routing/geometry.hpp +++ b/routing/geometry.hpp @@ -16,7 +16,7 @@ #include #include -class DataSourceBase; +class DataSource; namespace routing { @@ -79,7 +79,7 @@ public: virtual void Load(uint32_t featureId, RoadGeometry & road) = 0; // handle should be alive: it is caller responsibility to check it. - static std::unique_ptr Create(DataSourceBase const & dataSource, + static std::unique_ptr Create(DataSource const & dataSource, MwmSet::MwmHandle const & handle, std::shared_ptr vehicleModel, bool loadAltitudes); diff --git a/routing/index_graph_loader.cpp b/routing/index_graph_loader.cpp index e0221fd623..c5e865615c 100644 --- a/routing/index_graph_loader.cpp +++ b/routing/index_graph_loader.cpp @@ -22,7 +22,7 @@ class IndexGraphLoaderImpl final : public IndexGraphLoader public: IndexGraphLoaderImpl(VehicleType vehicleType, bool loadAltitudes, shared_ptr numMwmIds, shared_ptr vehicleModelFactory, - shared_ptr estimator, DataSourceBase & dataSource); + shared_ptr estimator, DataSource & dataSource); // IndexGraphLoader overrides: Geometry & GetGeometry(NumMwmId numMwmId) override; @@ -41,7 +41,7 @@ private: VehicleType m_vehicleType; bool m_loadAltitudes; - DataSourceBase & m_dataSource; + DataSource & m_dataSource; shared_ptr m_numMwmIds; shared_ptr m_vehicleModelFactory; shared_ptr m_estimator; @@ -51,7 +51,7 @@ private: IndexGraphLoaderImpl::IndexGraphLoaderImpl( VehicleType vehicleType, bool loadAltitudes, shared_ptr numMwmIds, shared_ptr vehicleModelFactory, - shared_ptr estimator, DataSourceBase & dataSource) + shared_ptr estimator, DataSource & dataSource) : m_vehicleType(vehicleType) , m_loadAltitudes(loadAltitudes) , m_dataSource(dataSource) @@ -148,8 +148,8 @@ namespace routing // static unique_ptr IndexGraphLoader::Create( VehicleType vehicleType, bool loadAltitudes, shared_ptr numMwmIds, - shared_ptr vehicleModelFactory, shared_ptr estimator, - DataSourceBase & dataSource) + shared_ptr vehicleModelFactory, + shared_ptr estimator, DataSource & dataSource) { return make_unique(vehicleType, loadAltitudes, numMwmIds, vehicleModelFactory, estimator, dataSource); diff --git a/routing/index_graph_loader.hpp b/routing/index_graph_loader.hpp index e46b64f33a..db95d66d7c 100644 --- a/routing/index_graph_loader.hpp +++ b/routing/index_graph_loader.hpp @@ -10,7 +10,7 @@ #include class MwmValue; -class DataSourceBase; +class DataSource; namespace routing { @@ -26,7 +26,7 @@ public: static std::unique_ptr Create( VehicleType vehicleType, bool loadAltitudes, std::shared_ptr numMwmIds, std::shared_ptr vehicleModelFactory, - std::shared_ptr estimator, DataSourceBase & dataSource); + std::shared_ptr estimator, DataSource & dataSource); }; void DeserializeIndexGraph(MwmValue const & mwmValue, VehicleType vehicleType, IndexGraph & graph); diff --git a/routing/index_road_graph.cpp b/routing/index_road_graph.cpp index 5d50fd2f38..21bad0a23e 100644 --- a/routing/index_road_graph.cpp +++ b/routing/index_road_graph.cpp @@ -3,7 +3,7 @@ #include "routing/routing_exceptions.hpp" #include "routing/transit_graph.hpp" -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" #include @@ -13,7 +13,7 @@ namespace routing { IndexRoadGraph::IndexRoadGraph(shared_ptr numMwmIds, IndexGraphStarter & starter, vector const & segments, vector const & junctions, - DataSourceBase & dataSource) + DataSource & dataSource) : m_dataSource(dataSource), m_numMwmIds(numMwmIds), m_starter(starter), m_segments(segments) { // j0 j1 j2 j3 @@ -60,7 +60,8 @@ void IndexRoadGraph::GetEdgeTypes(Edge const & edge, feature::TypesHolder & type FeatureID const featureId = edge.GetFeatureId(); FeatureType ft; - EditableDataSource::FeaturesLoaderGuard loader(m_dataSource, featureId.m_mwmId); + DataSource::FeaturesLoaderGuard loader(m_dataSource, featureId.m_mwmId, + EditableFeatureSourceFactory()); if (!loader.GetFeatureByIndex(featureId.m_index, ft)) { LOG(LERROR, ("Can't load types for feature", featureId)); diff --git a/routing/index_road_graph.hpp b/routing/index_road_graph.hpp index 43e8f6d881..12729592f0 100644 --- a/routing/index_road_graph.hpp +++ b/routing/index_road_graph.hpp @@ -19,7 +19,7 @@ class IndexRoadGraph : public RoadGraphBase public: IndexRoadGraph(std::shared_ptr numMwmIds, IndexGraphStarter & starter, std::vector const & segments, std::vector const & junctions, - DataSourceBase & dataSource); + DataSource & dataSource); // IRoadGraphBase overrides: virtual void GetOutgoingEdges(Junction const & junction, TEdgeVector & edges) const override; @@ -35,7 +35,7 @@ private: void GetEdges(Junction const & junction, bool isOutgoing, TEdgeVector & edges) const; std::vector const & GetSegments(Junction const & junction, bool isOutgoing) const; - DataSourceBase & m_dataSource; + DataSource & m_dataSource; std::shared_ptr m_numMwmIds; IndexGraphStarter & m_starter; std::vector m_segments; diff --git a/routing/index_router.cpp b/routing/index_router.cpp index 8c0a850542..31fcc152db 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -102,7 +102,8 @@ shared_ptr CreateVehicleModelFactory( } unique_ptr CreateDirectionsEngine(VehicleType vehicleType, - shared_ptr numMwmIds, DataSourceBase & dataSource) + shared_ptr numMwmIds, + DataSource & dataSource) { switch (vehicleType) { @@ -156,7 +157,7 @@ bool MwmHasRoutingData(version::MwmTraits const & traits) return traits.HasRoutingIndex() && traits.HasCrossMwmSection(); } -void GetOutdatedMwms(DataSourceBase & dataSource, vector & outdatedMwms) +void GetOutdatedMwms(DataSource & dataSource, vector & outdatedMwms) { outdatedMwms.clear(); vector> infos; @@ -276,7 +277,7 @@ IndexRouter::IndexRouter(VehicleType vehicleType, bool loadAltitudes, CountryParentNameGetterFn const & countryParentNameGetterFn, TCountryFileFn const & countryFileFn, CourntryRectFn const & countryRectFn, shared_ptr numMwmIds, unique_ptr> numMwmTree, - traffic::TrafficCache const & trafficCache, DataSourceBase & dataSource) + traffic::TrafficCache const & trafficCache, DataSource & dataSource) : m_vehicleType(vehicleType) , m_loadAltitudes(loadAltitudes) , m_name("astar-bidirectional-" + ToString(m_vehicleType)) diff --git a/routing/index_router.hpp b/routing/index_router.hpp index e7cd938d18..64af3ad631 100644 --- a/routing/index_router.hpp +++ b/routing/index_router.hpp @@ -28,7 +28,7 @@ #include #include -class DataSourceBase; +class DataSource; namespace routing { @@ -62,10 +62,11 @@ public: m2::PointD const m_direction; }; - IndexRouter(VehicleType vehicleType, bool loadAltitudes, CountryParentNameGetterFn const & countryParentNameGetterFn, + IndexRouter(VehicleType vehicleType, bool loadAltitudes, + CountryParentNameGetterFn const & countryParentNameGetterFn, TCountryFileFn const & countryFileFn, CourntryRectFn const & countryRectFn, shared_ptr numMwmIds, unique_ptr> numMwmTree, - traffic::TrafficCache const & trafficCache, DataSourceBase & dataSource); + traffic::TrafficCache const & trafficCache, DataSource & dataSource); std::unique_ptr MakeSingleMwmWorldGraph(); bool FindBestSegment(m2::PointD const & point, m2::PointD const & direction, @@ -148,7 +149,7 @@ private: VehicleType m_vehicleType; bool m_loadAltitudes; std::string const m_name; - DataSourceBase & m_dataSource; + DataSource & m_dataSource; std::shared_ptr m_vehicleModelFactory; TCountryFileFn const m_countryFileFn; diff --git a/routing/loaded_path_segment.hpp b/routing/loaded_path_segment.hpp index 4bc06557cb..544c2fe4ef 100644 --- a/routing/loaded_path_segment.hpp +++ b/routing/loaded_path_segment.hpp @@ -14,7 +14,7 @@ #include "std/vector.hpp" -class DataSourceBase; +class DataSource; namespace routing { diff --git a/routing/routing_benchmarks/helpers.cpp b/routing/routing_benchmarks/helpers.cpp index abddbcd2b3..170909ac9c 100644 --- a/routing/routing_benchmarks/helpers.cpp +++ b/routing/routing_benchmarks/helpers.cpp @@ -63,7 +63,10 @@ m2::PointD GetPointOnEdge(routing::Edge const & e, double posAlong) } // namespace RoutingTest::RoutingTest(routing::IRoadGraph::Mode mode, set const & neededMaps) - : m_mode(mode), m_neededMaps(neededMaps), m_numMwmIds(my::make_unique()) + : m_mode(mode) + , m_dataSource(make_unique()) + , m_neededMaps(neededMaps) + , m_numMwmIds(my::make_unique()) { classificator::Load(); diff --git a/routing/routing_integration_tests/get_altitude_test.cpp b/routing/routing_integration_tests/get_altitude_test.cpp index bb561eea76..b316de8eb1 100644 --- a/routing/routing_integration_tests/get_altitude_test.cpp +++ b/routing/routing_integration_tests/get_altitude_test.cpp @@ -43,7 +43,7 @@ LocalCountryFile GetLocalCountryFileByCountryId(CountryFile const & country) void TestAltitudeOfAllMwmFeatures(string const & countryId, TAltitude const altitudeLowerBoundMeters, TAltitude const altitudeUpperBoundMeters) { - DataSource dataSource; + DataSource dataSource(make_unique()); LocalCountryFile const country = GetLocalCountryFileByCountryId(CountryFile(countryId)); TEST_NOT_EQUAL(country, LocalCountryFile(), ()); diff --git a/routing/routing_integration_tests/road_graph_tests.cpp b/routing/routing_integration_tests/road_graph_tests.cpp index ebac0badeb..5d45015e88 100644 --- a/routing/routing_integration_tests/road_graph_tests.cpp +++ b/routing/routing_integration_tests/road_graph_tests.cpp @@ -31,7 +31,7 @@ UNIT_TEST(FakeEdgesCombinatorialExplosion) GetAllLocalFiles(localFiles); TEST(!localFiles.empty(), ()); - DataSource dataSource; + DataSource dataSource(make_unique()); for (auto const & file : localFiles) { auto const result = dataSource.Register(file); diff --git a/routing/routing_integration_tests/routing_test_tools.cpp b/routing/routing_integration_tests/routing_test_tools.cpp index 8a4275689c..688115296a 100644 --- a/routing/routing_integration_tests/routing_test_tools.cpp +++ b/routing/routing_integration_tests/routing_test_tools.cpp @@ -41,7 +41,7 @@ using namespace routing; using namespace routing_test; using TRouterFactory = - function(DataSourceBase & dataSource, TCountryFileFn const & countryFileFn, + function(DataSource & dataSource, TCountryFileFn const & countryFileFn, shared_ptr numMwmIds)>; namespace @@ -85,7 +85,7 @@ namespace integration return storage::CountryInfoReader::CreateCountryInfoReader(platform); } - unique_ptr CreateVehicleRouter(DataSourceBase & dataSource, + unique_ptr CreateVehicleRouter(DataSource & dataSource, storage::CountryInfoGetter const & infoGetter, traffic::TrafficCache const & trafficCache, vector const & localFiles, @@ -120,7 +120,7 @@ namespace integration return indexRouter; } - unique_ptr CreateAStarRouter(DataSourceBase & dataSource, + unique_ptr CreateAStarRouter(DataSource & dataSource, storage::CountryInfoGetter const & infoGetter, vector const & localFiles, TRouterFactory const & routerFactory) diff --git a/routing/routing_integration_tests/routing_test_tools.hpp b/routing/routing_integration_tests/routing_test_tools.hpp index 88da715494..2b284bc71c 100644 --- a/routing/routing_integration_tests/routing_test_tools.hpp +++ b/routing/routing_integration_tests/routing_test_tools.hpp @@ -51,7 +51,7 @@ shared_ptr CreateFeaturesFetcher(vector CreateCountryInfoGetter(); -unique_ptr CreateVehicleRouter(DataSourceBase & dataSource, +unique_ptr CreateVehicleRouter(DataSource & dataSource, storage::CountryInfoGetter const & infoGetter, traffic::TrafficCache const & trafficCache, vector const & localFiles, diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index 860519645c..281ae32610 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -285,7 +285,7 @@ void RoutingSession::ResetImpl() } RoutingSession::State RoutingSession::OnLocationPositionChanged(GpsInfo const & info, - DataSourceBase const & dataSource) + DataSource const & dataSource) { threads::MutexGuard guard(m_routingSessionMutex); ASSERT(m_state != RoutingNotActive, ()); @@ -663,7 +663,8 @@ string RoutingSession::GetTurnNotificationsLocale() const return m_turnNotificationsMgr.GetLocale(); } -double RoutingSession::GetDistanceToCurrentCamM(SpeedCameraRestriction & camera, DataSourceBase const & dataSource) +double RoutingSession::GetDistanceToCurrentCamM(SpeedCameraRestriction & camera, + DataSource const & dataSource) { ASSERT(m_route, ()); diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index 505576166e..1434f50740 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -25,7 +25,7 @@ #include "std/shared_ptr.hpp" #include "std/unique_ptr.hpp" -class DataSourceBase; +class DataSource; namespace location { @@ -120,7 +120,7 @@ public: bool GetRouteAltitudesAndDistancesM(vector & routeSegDistanceM, feature::TAltitudes & routeAltitudesM) const; - State OnLocationPositionChanged(location::GpsInfo const & info, DataSourceBase const & dataSource); + State OnLocationPositionChanged(location::GpsInfo const & info, DataSource const & dataSource); void GetRouteFollowingInfo(location::FollowingInfo & info) const; void MatchLocationToRoute(location::GpsInfo & location, @@ -191,7 +191,7 @@ private: /// Returns a nearest speed camera record on your way and distance to it. /// Returns kInvalidSpeedCameraDistance if there is no cameras on your way. // Should be called with locked m_routingSessionMutex. - double GetDistanceToCurrentCamM(SpeedCameraRestriction & camera, DataSourceBase const & dataSource); + double GetDistanceToCurrentCamM(SpeedCameraRestriction & camera, DataSource const & dataSource); /// RemoveRoute removes m_route and resets route attributes (m_state, m_lastDistance, m_moveAwayCounter). void RemoveRoute(); diff --git a/routing/routing_tests/routing_session_test.cpp b/routing/routing_tests/routing_session_test.cpp index bdd5761b91..279f920d06 100644 --- a/routing/routing_tests/routing_session_test.cpp +++ b/routing/routing_tests/routing_session_test.cpp @@ -114,7 +114,7 @@ UNIT_TEST(TestRouteBuilding) UNIT_TEST(TestRouteRebuilding) { - DataSource dataSource; + DataSource dataSource(make_unique()); RoutingSession session; session.Init(nullptr, nullptr); vector routePoints = kTestRoute; @@ -172,7 +172,7 @@ UNIT_TEST(TestRouteRebuilding) UNIT_TEST(TestFollowRouteFlagPersistence) { - DataSource dataSource; + DataSource dataSource(make_unique()); RoutingSession session; session.Init(nullptr, nullptr); vector routePoints = kTestRoute; @@ -248,7 +248,7 @@ UNIT_TEST(TestFollowRouteFlagPersistence) UNIT_TEST(TestFollowRoutePercentTest) { - DataSource dataSource; + DataSource dataSource(make_unique()); RoutingSession session; session.Init(nullptr, nullptr); vector routePoints = kTestRoute; diff --git a/routing/speed_camera.cpp b/routing/speed_camera.cpp index 2dcf4ac42f..f83c12b9e3 100644 --- a/routing/speed_camera.cpp +++ b/routing/speed_camera.cpp @@ -37,7 +37,7 @@ uint8_t ReadCameraRestriction(FeatureType & ft) return 0; } -uint8_t CheckCameraInPoint(m2::PointD const & point, DataSourceBase const & dataSource) +uint8_t CheckCameraInPoint(m2::PointD const & point, DataSource const & dataSource) { uint32_t speedLimit = kNoSpeedCamera; diff --git a/routing/speed_camera.hpp b/routing/speed_camera.hpp index 175f84eefb..e84a3bf398 100644 --- a/routing/speed_camera.hpp +++ b/routing/speed_camera.hpp @@ -4,11 +4,11 @@ #include "std/cstdint.hpp" -class DataSourceBase; +class DataSource; namespace routing { extern uint8_t const kNoSpeedCamera; -uint8_t CheckCameraInPoint(m2::PointD const & point, DataSourceBase const & dataSource); +uint8_t CheckCameraInPoint(m2::PointD const & point, DataSource const & dataSource); } // namespace routing diff --git a/routing/transit_graph_loader.cpp b/routing/transit_graph_loader.cpp index c55820f019..de226dc944 100644 --- a/routing/transit_graph_loader.cpp +++ b/routing/transit_graph_loader.cpp @@ -27,7 +27,7 @@ namespace routing class TransitGraphLoaderImpl : public TransitGraphLoader { public: - TransitGraphLoaderImpl(DataSourceBase & dataSource, shared_ptr numMwmIds, + TransitGraphLoaderImpl(DataSource & dataSource, shared_ptr numMwmIds, shared_ptr estimator); // TransitGraphLoader overrides. @@ -39,13 +39,14 @@ public: private: unique_ptr CreateTransitGraph(NumMwmId mwmId, IndexGraph & indexGraph) const; - DataSourceBase & m_dataSource; + DataSource & m_dataSource; shared_ptr m_numMwmIds; shared_ptr m_estimator; unordered_map> m_graphs; }; -TransitGraphLoaderImpl::TransitGraphLoaderImpl(DataSourceBase & dataSource, shared_ptr numMwmIds, +TransitGraphLoaderImpl::TransitGraphLoaderImpl(DataSource & dataSource, + shared_ptr numMwmIds, shared_ptr estimator) : m_dataSource(dataSource), m_numMwmIds(numMwmIds), m_estimator(estimator) { @@ -101,7 +102,7 @@ unique_ptr TransitGraphLoaderImpl::CreateTransitGraph(NumMwmId num } // static -unique_ptr TransitGraphLoader::Create(DataSourceBase & dataSource, +unique_ptr TransitGraphLoader::Create(DataSource & dataSource, shared_ptr numMwmIds, shared_ptr estimator) { diff --git a/routing/transit_graph_loader.hpp b/routing/transit_graph_loader.hpp index a4fdbcdfb6..bd37eb9a14 100644 --- a/routing/transit_graph_loader.hpp +++ b/routing/transit_graph_loader.hpp @@ -8,7 +8,7 @@ #include -class DataSourceBase; +class DataSource; namespace routing { @@ -20,7 +20,7 @@ public: virtual TransitGraph & GetTransitGraph(NumMwmId mwmId, IndexGraph & indexGraph) = 0; virtual void Clear() = 0; - static std::unique_ptr Create(DataSourceBase & dataSource, + static std::unique_ptr Create(DataSource & dataSource, std::shared_ptr numMwmIds, std::shared_ptr estimator); }; diff --git a/routing/turns_generator.hpp b/routing/turns_generator.hpp index b8c26a09a4..0e59dfed84 100644 --- a/routing/turns_generator.hpp +++ b/routing/turns_generator.hpp @@ -20,7 +20,7 @@ #include struct PathData; -class DataSourceBase; +class DataSource; namespace ftypes { diff --git a/search/cities_boundaries_table.hpp b/search/cities_boundaries_table.hpp index 7c1634ebe7..e9ac3841fa 100644 --- a/search/cities_boundaries_table.hpp +++ b/search/cities_boundaries_table.hpp @@ -12,7 +12,7 @@ #include #include -class DataSourceBase; +class DataSource; namespace feature { @@ -58,7 +58,7 @@ public: double m_eps = 0.0; }; - explicit CitiesBoundariesTable(DataSourceBase const & dataSource) : m_dataSource(dataSource) {} + explicit CitiesBoundariesTable(DataSource const & dataSource) : m_dataSource(dataSource) {} bool Load(); @@ -69,7 +69,7 @@ public: bool Get(uint32_t fid, Boundaries & bs) const; private: - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; MwmSet::MwmId m_mwmId; std::unordered_map> m_table; double m_eps = 0.0; diff --git a/search/city_finder.cpp b/search/city_finder.cpp index be34025cbc..2cfd0a2587 100644 --- a/search/city_finder.cpp +++ b/search/city_finder.cpp @@ -6,10 +6,10 @@ using namespace std; namespace search { -CityFinder::CityFinder(DataSourceBase const & dataSource) - : m_unusedBoundaries(dataSource) - , m_unusedCache(m_cancellable) - , m_finder(dataSource, m_unusedBoundaries, m_unusedCache) +CityFinder::CityFinder(DataSource const & dataSource) + : m_unusedBoundaries(dataSource) + , m_unusedCache(m_cancellable) + , m_finder(dataSource, m_unusedBoundaries, m_unusedCache) { } diff --git a/search/city_finder.hpp b/search/city_finder.hpp index f7b38f3e52..bca365bb34 100644 --- a/search/city_finder.hpp +++ b/search/city_finder.hpp @@ -10,7 +10,7 @@ #include #include -class DataSourceBase; +class DataSource; struct FeatureID; namespace search @@ -21,7 +21,7 @@ public: // TODO (@milchakov): consider to reuse locality finder from search // engine. Otherwise, CityFinder won't benefit from approximated // cities boundaries. - explicit CityFinder(DataSourceBase const & dataSource); + explicit CityFinder(DataSource const & dataSource); std::string GetCityName(m2::PointD const & p, int8_t lang); FeatureID GetCityFeatureID(m2::PointD const & p); diff --git a/search/downloader_search_callback.cpp b/search/downloader_search_callback.cpp index a965aaf065..6ad12a7f75 100644 --- a/search/downloader_search_callback.cpp +++ b/search/downloader_search_callback.cpp @@ -2,7 +2,9 @@ #include "search/result.hpp" -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" + +#include "indexer/data_source.hpp" #include "storage/country_info_getter.hpp" #include "storage/storage.hpp" @@ -35,7 +37,8 @@ bool GetGroupCountryIdFromFeature(storage::Storage const & storage, FeatureType namespace search { -DownloaderSearchCallback::DownloaderSearchCallback(Delegate & delegate, DataSourceBase const & dataSource, +DownloaderSearchCallback::DownloaderSearchCallback(Delegate & delegate, + DataSource const & dataSource, storage::CountryInfoGetter const & infoGetter, storage::Storage const & storage, storage::DownloaderSearchParams params) @@ -60,7 +63,8 @@ void DownloaderSearchCallback::operator()(search::Results const & results) if (result.GetResultType() != search::Result::Type::LatLon) { FeatureID const & fid = result.GetFeatureID(); - EditableDataSource::FeaturesLoaderGuard loader(m_dataSource, fid.m_mwmId); + DataSource::FeaturesLoaderGuard loader(m_dataSource, fid.m_mwmId, + EditableFeatureSourceFactory()); FeatureType ft; if (!loader.GetFeatureByIndex(fid.m_index, ft)) { diff --git a/search/downloader_search_callback.hpp b/search/downloader_search_callback.hpp index 555b67fd58..066957849b 100644 --- a/search/downloader_search_callback.hpp +++ b/search/downloader_search_callback.hpp @@ -4,7 +4,7 @@ #include -class DataSourceBase; +class DataSource; namespace storage { @@ -30,7 +30,7 @@ public: virtual void RunUITask(std::function fn) = 0; }; - DownloaderSearchCallback(Delegate & delegate, DataSourceBase const & dataSource, + DownloaderSearchCallback(Delegate & delegate, DataSource const & dataSource, storage::CountryInfoGetter const & infoGetter, storage::Storage const & storage, storage::DownloaderSearchParams params); @@ -39,7 +39,7 @@ public: private: Delegate & m_delegate; - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; storage::CountryInfoGetter const & m_infoGetter; storage::Storage const & m_storage; storage::DownloaderSearchParams m_params; diff --git a/search/editor_delegate.cpp b/search/editor_delegate.cpp index 7faf4c3463..8b70837dbe 100644 --- a/search/editor_delegate.cpp +++ b/search/editor_delegate.cpp @@ -2,14 +2,15 @@ #include "search/reverse_geocoder.hpp" -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" +#include "indexer/data_source.hpp" #include "indexer/data_source_helpers.hpp" #include "indexer/feature_decl.hpp" namespace search { -EditorDelegate::EditorDelegate(DataSourceBase const & dataSource) : m_dataSource(dataSource) {} +EditorDelegate::EditorDelegate(DataSource const & dataSource) : m_dataSource(dataSource) {} MwmSet::MwmId EditorDelegate::GetMwmIdByMapName(string const & name) const { @@ -18,7 +19,7 @@ MwmSet::MwmId EditorDelegate::GetMwmIdByMapName(string const & name) const unique_ptr EditorDelegate::GetOriginalFeature(FeatureID const & fid) const { - EditableDataSource::FeaturesLoaderGuard guard(m_dataSource, fid.m_mwmId); + DataSource::FeaturesLoaderGuard guard(m_dataSource, fid.m_mwmId, EditableFeatureSourceFactory()); auto feature = guard.GetOriginalFeatureByIndex(fid.m_index); if (feature) feature->ParseEverything(); diff --git a/search/editor_delegate.hpp b/search/editor_delegate.hpp index 333e500012..76ba3562b5 100644 --- a/search/editor_delegate.hpp +++ b/search/editor_delegate.hpp @@ -2,14 +2,14 @@ #include "editor/osm_editor.hpp" -class DataSourceBase; +class DataSource; namespace search { class EditorDelegate : public osm::Editor::Delegate { public: - EditorDelegate(DataSourceBase const & dataSource); + EditorDelegate(DataSource const & dataSource); // osm::Editor::Delegate overrides: MwmSet::MwmId GetMwmIdByMapName(string const & name) const override; @@ -19,6 +19,6 @@ public: m2::PointD const & point) const override; private: - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; }; } // namespace search diff --git a/search/engine.cpp b/search/engine.cpp index f3a559cc2c..7fac0f5da5 100644 --- a/search/engine.cpp +++ b/search/engine.cpp @@ -92,7 +92,7 @@ Engine::Params::Params(string const & locale, size_t numThreads) } // Engine ------------------------------------------------------------------------------------------ -Engine::Engine(DataSourceBase & dataSource, CategoriesHolder const & categories, +Engine::Engine(DataSource & dataSource, CategoriesHolder const & categories, storage::CountryInfoGetter const & infoGetter, Params const & params) : m_shutdown(false) { diff --git a/search/engine.hpp b/search/engine.hpp index ec5beb030c..813b918591 100644 --- a/search/engine.hpp +++ b/search/engine.hpp @@ -23,7 +23,7 @@ #include #include -class DataSourceBase; +class DataSource; namespace storage { @@ -90,7 +90,7 @@ public: }; // Doesn't take ownership of dataSource and categories. - Engine(DataSourceBase & dataSource, CategoriesHolder const & categories, + Engine(DataSource & dataSource, CategoriesHolder const & categories, storage::CountryInfoGetter const & infoGetter, Params const & params); ~Engine(); diff --git a/search/feature_loader.cpp b/search/feature_loader.cpp index 9841aa4b26..902c118625 100644 --- a/search/feature_loader.cpp +++ b/search/feature_loader.cpp @@ -1,12 +1,14 @@ #include "search/feature_loader.hpp" +#include "editor/editable_feature_source.hpp" + #include "indexer/feature_decl.hpp" #include "base/stl_add.hpp" namespace search { -FeatureLoader::FeatureLoader(DataSourceBase const & dataSource) : m_dataSource(dataSource) {} +FeatureLoader::FeatureLoader(DataSource const & dataSource) : m_dataSource(dataSource) {} bool FeatureLoader::Load(FeatureID const & id, FeatureType & ft) { @@ -14,7 +16,8 @@ bool FeatureLoader::Load(FeatureID const & id, FeatureType & ft) auto const & mwmId = id.m_mwmId; if (!m_guard || m_guard->GetId() != mwmId) - m_guard = my::make_unique(m_dataSource, mwmId); + m_guard = my::make_unique(m_dataSource, mwmId, + EditableFeatureSourceFactory()); return m_guard->GetFeatureByIndex(id.m_index, ft); } diff --git a/search/feature_loader.hpp b/search/feature_loader.hpp index 5d79a326e0..e908c1bc90 100644 --- a/search/feature_loader.hpp +++ b/search/feature_loader.hpp @@ -1,7 +1,6 @@ #pragma once -#include "editor/editable_data_source.hpp" - +#include "indexer/data_source.hpp" #include "indexer/scales.hpp" #include "base/assert.hpp" @@ -19,7 +18,7 @@ namespace search class FeatureLoader { public: - explicit FeatureLoader(DataSourceBase const & dataSource); + explicit FeatureLoader(DataSource const & dataSource); WARN_UNUSED_RESULT bool Load(FeatureID const & id, FeatureType & ft); @@ -32,8 +31,8 @@ public: } private: - DataSourceBase const & m_dataSource; - std::unique_ptr m_guard; + DataSource const & m_dataSource; + std::unique_ptr m_guard; ThreadChecker m_checker; }; diff --git a/search/features_layer_matcher.cpp b/search/features_layer_matcher.cpp index b7974aaa00..c2e6c0e9ad 100644 --- a/search/features_layer_matcher.cpp +++ b/search/features_layer_matcher.cpp @@ -13,7 +13,7 @@ namespace search /// even if there is no exact street written for this house. int constexpr kMaxApproxStreetDistanceM = 100; -FeaturesLayerMatcher::FeaturesLayerMatcher(DataSourceBase const & dataSource, +FeaturesLayerMatcher::FeaturesLayerMatcher(DataSource const & dataSource, ::base::Cancellable const & cancellable) : m_context(nullptr) , m_postcodes(nullptr) diff --git a/search/features_layer_matcher.hpp b/search/features_layer_matcher.hpp index 835984ea7c..fd587fdac1 100644 --- a/search/features_layer_matcher.hpp +++ b/search/features_layer_matcher.hpp @@ -35,7 +35,7 @@ #include "std/utility.hpp" #include "std/vector.hpp" -class DataSourceBase; +class DataSource; namespace search { @@ -61,7 +61,7 @@ public: static int constexpr kBuildingRadiusMeters = 50; static int constexpr kStreetRadiusMeters = 100; - FeaturesLayerMatcher(DataSourceBase const & dataSource, ::base::Cancellable const & cancellable); + FeaturesLayerMatcher(DataSource const & dataSource, ::base::Cancellable const & cancellable); void SetContext(MwmContext * context); void SetPostcodes(CBV const * postcodes); diff --git a/search/geocoder.cpp b/search/geocoder.cpp index a7270d7608..69b98d5050 100644 --- a/search/geocoder.cpp +++ b/search/geocoder.cpp @@ -336,7 +336,7 @@ size_t OrderCountries(m2::RectD const & pivot, vector> & inf } // namespace // Geocoder::Geocoder ------------------------------------------------------------------------------ -Geocoder::Geocoder(DataSourceBase const & dataSource, storage::CountryInfoGetter const & infoGetter, +Geocoder::Geocoder(DataSource const & dataSource, storage::CountryInfoGetter const & infoGetter, CategoriesHolder const & categories, PreRanker & preRanker, VillagesCache & villagesCache, ::base::Cancellable const & cancellable) : m_dataSource(dataSource) diff --git a/search/geocoder.hpp b/search/geocoder.hpp index 0d280c9e3f..749e04197e 100644 --- a/search/geocoder.hpp +++ b/search/geocoder.hpp @@ -43,7 +43,7 @@ #include "std/vector.hpp" class CategoriesHolder; -class DataSourceBase; +class DataSource; class MwmValue; namespace storage @@ -87,7 +87,7 @@ public: shared_ptr m_tracer; }; - Geocoder(DataSourceBase const & dataSource, storage::CountryInfoGetter const & infoGetter, + Geocoder(DataSource const & dataSource, storage::CountryInfoGetter const & infoGetter, CategoriesHolder const & categories, PreRanker & preRanker, VillagesCache & villagesCache, ::base::Cancellable const & cancellable); ~Geocoder(); @@ -239,7 +239,7 @@ private: WARN_UNUSED_RESULT bool GetTypeInGeocoding(BaseContext const & ctx, uint32_t featureId, Model::Type & type); - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; storage::CountryInfoGetter const & m_infoGetter; CategoriesHolder const & m_categories; diff --git a/search/house_detector.cpp b/search/house_detector.cpp index 8e6c6049f6..c2a2df5988 100644 --- a/search/house_detector.cpp +++ b/search/house_detector.cpp @@ -751,7 +751,7 @@ void Street::Reverse() void Street::SortHousesProjection() { sort(m_houses.begin(), m_houses.end(), &LessStreetDistance); } -HouseDetector::HouseDetector(DataSourceBase const & dataSource) +HouseDetector::HouseDetector(DataSource const & dataSource) : m_loader(dataSource), m_streetNum(0) { // default value for conversions diff --git a/search/house_detector.hpp b/search/house_detector.hpp index c1d71a270c..f82583109f 100644 --- a/search/house_detector.hpp +++ b/search/house_detector.hpp @@ -16,7 +16,7 @@ #include #include -class DataSourceBase; +class DataSource; namespace search { @@ -212,7 +212,7 @@ public: static int const DEFAULT_OFFSET_M = 200; - HouseDetector(DataSourceBase const & dataSource); + HouseDetector(DataSource const & dataSource); ~HouseDetector(); int LoadStreets(std::vector const & ids); diff --git a/search/locality_finder.cpp b/search/locality_finder.cpp index 1d01c12605..52e9b2f977 100644 --- a/search/locality_finder.cpp +++ b/search/locality_finder.cpp @@ -206,7 +206,8 @@ void LocalityFinder::Holder::Clear() } // LocalityFinder ---------------------------------------------------------------------------------- -LocalityFinder::LocalityFinder(DataSourceBase const & dataSource, CitiesBoundariesTable const & boundariesTable, +LocalityFinder::LocalityFinder(DataSource const & dataSource, + CitiesBoundariesTable const & boundariesTable, VillagesCache & villagesCache) : m_dataSource(dataSource) , m_boundariesTable(boundariesTable) diff --git a/search/locality_finder.hpp b/search/locality_finder.hpp index 371e69f66a..890558912f 100644 --- a/search/locality_finder.hpp +++ b/search/locality_finder.hpp @@ -20,7 +20,7 @@ #include #include -class DataSourceBase; +class DataSource; namespace search { @@ -100,7 +100,7 @@ public: DISALLOW_COPY_AND_MOVE(Holder); }; - LocalityFinder(DataSourceBase const & dataSource, CitiesBoundariesTable const & boundaries, + LocalityFinder(DataSource const & dataSource, CitiesBoundariesTable const & boundaries, VillagesCache & villagesCache); template @@ -125,7 +125,7 @@ private: void LoadVicinity(m2::PointD const & p, bool loadCities, bool loadVillages); void UpdateMaps(); - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; CitiesBoundariesTable const & m_boundariesTable; VillagesCache & m_villagesCache; diff --git a/search/mwm_context.hpp b/search/mwm_context.hpp index 7f54edee59..9f42e50f7c 100644 --- a/search/mwm_context.hpp +++ b/search/mwm_context.hpp @@ -25,7 +25,7 @@ namespace search void CoverRect(m2::RectD const & rect, int scale, covering::Intervals & result); /// @todo Move this class into "index" library and make it more generic. -/// Now it duplicates "DataSourceBase" functionality. +/// Now it duplicates "DataSource" functionality. class MwmContext { public: diff --git a/search/nested_rects_cache.cpp b/search/nested_rects_cache.cpp index b0c4e054cf..5ac54d9a21 100644 --- a/search/nested_rects_cache.cpp +++ b/search/nested_rects_cache.cpp @@ -19,7 +19,7 @@ namespace double const kPositionToleranceMeters = 15.0; } // namespace -NestedRectsCache::NestedRectsCache(DataSourceBase const & dataSource) +NestedRectsCache::NestedRectsCache(DataSource const & dataSource) : m_dataSource(dataSource), m_scale(0), m_position(0, 0), m_valid(false) { } diff --git a/search/nested_rects_cache.hpp b/search/nested_rects_cache.hpp index 10944797b2..829132b730 100644 --- a/search/nested_rects_cache.hpp +++ b/search/nested_rects_cache.hpp @@ -7,14 +7,14 @@ #include "std/map.hpp" #include "std/vector.hpp" -class DataSourceBase; +class DataSource; namespace search { class NestedRectsCache { public: - explicit NestedRectsCache(DataSourceBase const & dataSource); + explicit NestedRectsCache(DataSource const & dataSource); void SetPosition(m2::PointD const & position, int scale); @@ -37,7 +37,7 @@ private: void Update(); - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; int m_scale; m2::PointD m_position; bool m_valid; diff --git a/search/pre_ranker.cpp b/search/pre_ranker.cpp index 5d7a7ccd33..d1a9cdf107 100644 --- a/search/pre_ranker.cpp +++ b/search/pre_ranker.cpp @@ -45,7 +45,7 @@ void SweepNearbyResults(double eps, set const & prevEmit, vector m_results; Params m_params; diff --git a/search/processor.cpp b/search/processor.cpp index fd8052784a..7f730e4514 100644 --- a/search/processor.cpp +++ b/search/processor.cpp @@ -141,7 +141,7 @@ size_t const Processor::kPreResultsCount = 200; double const Processor::kMinViewportRadiusM = 5.0 * 1000; double const Processor::kMaxViewportRadiusM = 50.0 * 1000; -Processor::Processor(DataSourceBase const & dataSource, CategoriesHolder const & categories, +Processor::Processor(DataSource const & dataSource, CategoriesHolder const & categories, vector const & suggests, storage::CountryInfoGetter const & infoGetter) : m_categories(categories) diff --git a/search/processor.hpp b/search/processor.hpp index 588058efa1..238cf789b0 100644 --- a/search/processor.hpp +++ b/search/processor.hpp @@ -35,7 +35,7 @@ class FeatureType; class CategoriesHolder; -class DataSourceBase; +class DataSource; namespace coding { @@ -63,7 +63,7 @@ public: static double const kMinViewportRadiusM; static double const kMaxViewportRadiusM; - Processor(DataSourceBase const & dataSource, CategoriesHolder const & categories, + Processor(DataSource const & dataSource, CategoriesHolder const & categories, std::vector const & suggests, storage::CountryInfoGetter const & infoGetter); void SetViewport(m2::RectD const & viewport); diff --git a/search/rank_table_cache.cpp b/search/rank_table_cache.cpp index 9af61e7aa9..b91087b7de 100644 --- a/search/rank_table_cache.cpp +++ b/search/rank_table_cache.cpp @@ -7,7 +7,7 @@ namespace search { -RankTable const & RankTableCache::Get(DataSourceBase & dataSource, TId const & mwmId) +RankTable const & RankTableCache::Get(DataSource & dataSource, TId const & mwmId) { auto const it = m_ranks.find(TKey(mwmId)); if (it != m_ranks.end()) diff --git a/search/rank_table_cache.hpp b/search/rank_table_cache.hpp index c7b8d691ee..20b14ae99b 100644 --- a/search/rank_table_cache.hpp +++ b/search/rank_table_cache.hpp @@ -7,7 +7,7 @@ #include "std/map.hpp" #include "std/unique_ptr.hpp" -class DataSourceBase; +class DataSource; namespace search { @@ -29,7 +29,7 @@ class RankTableCache public: RankTableCache() = default; - RankTable const & Get(DataSourceBase & dataSource, TId const & mwmId); + RankTable const & Get(DataSource & dataSource, TId const & mwmId); void Remove(TId const & id); void Clear(); diff --git a/search/ranker.cpp b/search/ranker.cpp index 4239d4f95d..4ccc990df3 100644 --- a/search/ranker.cpp +++ b/search/ranker.cpp @@ -9,8 +9,9 @@ #include "search/token_slice.hpp" #include "search/utils.hpp" -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" +#include "indexer/data_source.hpp" #include "indexer/feature_algo.hpp" #include "indexer/search_string_utils.hpp" @@ -210,18 +211,18 @@ private: class RankerResultMaker { - using LoaderGuard = EditableDataSource::FeaturesLoaderGuard; Ranker & m_ranker; - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; Geocoder::Params const & m_params; storage::CountryInfoGetter const & m_infoGetter; - unique_ptr m_loader; + unique_ptr m_loader; bool LoadFeature(FeatureID const & id, FeatureType & ft) { if (!m_loader || m_loader->GetId() != id.m_mwmId) - m_loader = make_unique(m_dataSource, id.m_mwmId); + m_loader = make_unique(m_dataSource, id.m_mwmId, + EditableFeatureSourceFactory()); if (!m_loader->GetFeatureByIndex(id.m_index, ft)) return false; @@ -332,7 +333,7 @@ class RankerResultMaker } public: - RankerResultMaker(Ranker & ranker, DataSourceBase const & dataSource, + RankerResultMaker(Ranker & ranker, DataSource const & dataSource, storage::CountryInfoGetter const & infoGetter, Geocoder::Params const & params) : m_ranker(ranker), m_dataSource(dataSource), m_params(params), m_infoGetter(infoGetter) { @@ -359,7 +360,7 @@ public: } }; -Ranker::Ranker(DataSourceBase const & dataSource, CitiesBoundariesTable const & boundariesTable, +Ranker::Ranker(DataSource const & dataSource, CitiesBoundariesTable const & boundariesTable, storage::CountryInfoGetter const & infoGetter, KeywordLangMatcher & keywordsScorer, Emitter & emitter, CategoriesHolder const & categories, vector const & suggests, VillagesCache & villagesCache, diff --git a/search/ranker.hpp b/search/ranker.hpp index 9cf11f09fd..1b702e1d35 100644 --- a/search/ranker.hpp +++ b/search/ranker.hpp @@ -29,7 +29,7 @@ #include class CategoriesHolder; -class DataSourceBase; +class DataSource; namespace storage { @@ -79,7 +79,7 @@ public: size_t m_limit = 0; }; - Ranker(DataSourceBase const & dataSource, CitiesBoundariesTable const & boundariesTable, + Ranker(DataSource const & dataSource, CitiesBoundariesTable const & boundariesTable, storage::CountryInfoGetter const & infoGetter, KeywordLangMatcher & keywordsScorer, Emitter & emitter, CategoriesHolder const & categories, std::vector const & suggests, VillagesCache & villagesCache, @@ -134,7 +134,7 @@ private: int8_t m_localeCode; RegionInfoGetter m_regionInfoGetter; - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; storage::CountryInfoGetter const & m_infoGetter; Emitter & m_emitter; CategoriesHolder const & m_categories; diff --git a/search/retrieval.cpp b/search/retrieval.cpp index 8206b35c44..370c82211c 100644 --- a/search/retrieval.cpp +++ b/search/retrieval.cpp @@ -8,8 +8,6 @@ #include "search/search_trie.hpp" #include "search/token_slice.hpp" -#include "editor/editable_data_source.hpp" - #include "indexer/classificator.hpp" #include "indexer/feature.hpp" #include "indexer/feature_algo.hpp" diff --git a/search/reverse_geocoder.cpp b/search/reverse_geocoder.cpp index 33412e094c..6b521ebe9f 100644 --- a/search/reverse_geocoder.cpp +++ b/search/reverse_geocoder.cpp @@ -24,7 +24,7 @@ int constexpr kQueryScale = scales::GetUpperScale(); size_t constexpr kMaxNumTriesToApproxAddress = 10; } // namespace -ReverseGeocoder::ReverseGeocoder(DataSourceBase const & dataSource) : m_dataSource(dataSource) {} +ReverseGeocoder::ReverseGeocoder(DataSource const & dataSource) : m_dataSource(dataSource) {} void ReverseGeocoder::GetNearbyStreets(MwmSet::MwmId const & id, m2::PointD const & center, vector & streets) const diff --git a/search/reverse_geocoder.hpp b/search/reverse_geocoder.hpp index fe71871946..6b2fd65ac9 100644 --- a/search/reverse_geocoder.hpp +++ b/search/reverse_geocoder.hpp @@ -12,14 +12,14 @@ class FeatureType; -class DataSourceBase; +class DataSource; namespace search { class ReverseGeocoder { - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; struct Object { @@ -42,7 +42,7 @@ public: /// All "Nearby" functions work in this lookup radius. static int constexpr kLookupRadiusM = 500; - explicit ReverseGeocoder(DataSourceBase const & dataSource); + explicit ReverseGeocoder(DataSource const & dataSource); using Street = Object; @@ -98,11 +98,11 @@ private: /// Helper class to incapsulate house 2 street table reloading. class HouseTable { - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; unique_ptr m_table; MwmSet::MwmHandle m_handle; public: - explicit HouseTable(DataSourceBase const & dataSource) : m_dataSource(dataSource) {} + explicit HouseTable(DataSource const & dataSource) : m_dataSource(dataSource) {} bool Get(FeatureID const & fid, uint32_t & streetIndex); }; diff --git a/search/search_integration_tests/downloader_search_test.cpp b/search/search_integration_tests/downloader_search_test.cpp index 7462a7ef39..b75e0f589e 100644 --- a/search/search_integration_tests/downloader_search_test.cpp +++ b/search/search_integration_tests/downloader_search_test.cpp @@ -26,7 +26,7 @@ using namespace generator::tests_support; using namespace search::tests_support; using namespace std; -class DataSourceBase; +class DataSource; namespace search { @@ -106,7 +106,7 @@ public: class DownloaderSearchRequest : public TestSearchRequest, public TestDelegate { public: - DownloaderSearchRequest(DataSourceBase & dataSource, TestSearchEngine & engine, string const & query) + DownloaderSearchRequest(DataSource & dataSource, TestSearchEngine & engine, string const & query) : TestSearchRequest(engine, MakeSearchParams(query)) , m_storage(kCountriesTxt, make_unique()) , m_downloaderCallback(static_cast(*this), dataSource, diff --git a/search/search_integration_tests/generate_tests.cpp b/search/search_integration_tests/generate_tests.cpp index c645521a8a..bca5af9298 100644 --- a/search/search_integration_tests/generate_tests.cpp +++ b/search/search_integration_tests/generate_tests.cpp @@ -63,7 +63,7 @@ UNIT_CLASS_TEST(GenerateTest, GenerateDeprecatedTypes) MakeFeature(builder, {"shop", "estate_agent"}, {2, 2}); } - DataSource dataSource; + DataSource dataSource(make_unique()); TEST_EQUAL(dataSource.Register(file).second, MwmSet::RegResult::Success, ()); // New types. diff --git a/search/search_integration_tests/pre_ranker_test.cpp b/search/search_integration_tests/pre_ranker_test.cpp index 637e778590..8a17f866ee 100644 --- a/search/search_integration_tests/pre_ranker_test.cpp +++ b/search/search_integration_tests/pre_ranker_test.cpp @@ -38,7 +38,7 @@ using namespace generator::tests_support; using namespace search::tests_support; -class DataSourceBase; +class DataSource; namespace storage { @@ -52,12 +52,12 @@ namespace class TestRanker : public Ranker { public: - TestRanker(DataSourceBase & dataSource, storage::CountryInfoGetter & infoGetter, + TestRanker(DataSource & dataSource, storage::CountryInfoGetter & infoGetter, CitiesBoundariesTable const & boundariesTable, KeywordLangMatcher & keywordsScorer, Emitter & emitter, vector const & suggests, VillagesCache & villagesCache, ::base::Cancellable const & cancellable, vector & results) - : Ranker(dataSource, boundariesTable, infoGetter, keywordsScorer, emitter, GetDefaultCategories(), - suggests, villagesCache, cancellable) + : Ranker(dataSource, boundariesTable, infoGetter, keywordsScorer, emitter, + GetDefaultCategories(), suggests, villagesCache, cancellable) , m_results(results) { } diff --git a/search/search_integration_tests/processor_test.cpp b/search/search_integration_tests/processor_test.cpp index bf250247d2..9230565c94 100644 --- a/search/search_integration_tests/processor_test.cpp +++ b/search/search_integration_tests/processor_test.cpp @@ -13,8 +13,9 @@ #include "generator/generator_tests_support/test_feature.hpp" #include "generator/generator_tests_support/test_mwm_builder.hpp" -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" +#include "indexer/data_source.hpp" #include "indexer/feature.hpp" #include "indexer/ftypes_matcher.hpp" @@ -605,7 +606,7 @@ UNIT_CLASS_TEST(ProcessorTest, TestPostcodes) while (!features->GetBit(index)) ++index; - EditableDataSource::FeaturesLoaderGuard loader(m_dataSource, countryId); + DataSource::FeaturesLoaderGuard loader(m_dataSource, countryId, EditableFeatureSourceFactory()); FeatureType ft; TEST(loader.GetFeatureByIndex(::base::checked_cast(index), ft), ()); @@ -702,7 +703,8 @@ UNIT_CLASS_TEST(ProcessorTest, TestCategories) TEST(ResultsMatch(request->Results(), rules), ()); for (auto const & result : request->Results()) { - EditableDataSource::FeaturesLoaderGuard loader(m_dataSource, wonderlandId); + DataSource::FeaturesLoaderGuard loader(m_dataSource, wonderlandId, + EditableFeatureSourceFactory()); FeatureType ft; TEST(loader.GetFeatureByIndex(result.GetFeatureID().m_index, ft), ()); diff --git a/search/search_quality/assessment_tool/main_model.hpp b/search/search_quality/assessment_tool/main_model.hpp index 00d3160590..31a39aac15 100644 --- a/search/search_quality/assessment_tool/main_model.hpp +++ b/search/search_quality/assessment_tool/main_model.hpp @@ -17,7 +17,7 @@ #include class Framework; -class DataSourceBase; +class DataSource; namespace search { @@ -64,7 +64,7 @@ private: void ForAnyMatchingEntry(Context & context, FeatureID const & id, Fn && fn); Framework & m_framework; - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; search::FeatureLoader m_loader; ContextList m_contexts; diff --git a/search/search_quality/features_collector_tool/features_collector_tool.cpp b/search/search_quality/features_collector_tool/features_collector_tool.cpp index 6b188678e9..474a0e74b7 100644 --- a/search/search_quality/features_collector_tool/features_collector_tool.cpp +++ b/search/search_quality/features_collector_tool/features_collector_tool.cpp @@ -152,7 +152,7 @@ int main(int argc, char * argv[]) } classificator::Load(); - DataSource dataSource; + DataSource dataSource(make_unique()); vector mwms; platform::FindAllLocalMapsAndCleanup(numeric_limits::max() /* the latest version */, diff --git a/search/search_quality/search_quality_tool/search_quality_tool.cpp b/search/search_quality/search_quality_tool/search_quality_tool.cpp index 2a93578cd1..2e934bb165 100644 --- a/search/search_quality/search_quality_tool/search_quality_tool.cpp +++ b/search/search_quality/search_quality_tool/search_quality_tool.cpp @@ -197,8 +197,8 @@ void Split(string const & s, char delim, vector & parts) // Returns the position of the result that is expected to be found by geocoder completeness // tests in the |result| vector or -1 if it does not occur there. -int FindResult(DataSourceBase & dataSource, string const & mwmName, uint32_t const featureId, double const lat, - double const lon, vector const & results) +int FindResult(DataSource & dataSource, string const & mwmName, uint32_t const featureId, + double const lat, double const lon, vector const & results) { CHECK_LESS_OR_EQUAL(results.size(), numeric_limits::max(), ()); auto const mwmId = dataSource.GetMwmIdByCountryFile(platform::CountryFile(mwmName)); @@ -279,7 +279,7 @@ void ParseCompletenessQuery(string & s, CompletenessQuery & q) // from |path|, executes them against the |engine| with viewport set to |viewport| // and reports the number of queries whose expected result is among the returned results. // Exact feature id is expected, but a close enough (lat, lon) is good too. -void CheckCompleteness(string const & path, m2::RectD const & viewport, DataSourceBase & dataSource, +void CheckCompleteness(string const & path, m2::RectD const & viewport, DataSource & dataSource, TestSearchEngine & engine) { my::ScopedLogAbortLevelChanger const logAbortLevel(LCRITICAL); @@ -379,7 +379,7 @@ int main(int argc, char * argv[]) params.m_locale = FLAGS_locale; params.m_numThreads = FLAGS_num_threads; - DataSource dataSource; + DataSource dataSource(make_unique()); vector mwms; if (!FLAGS_mwm_list_path.empty()) diff --git a/search/search_tests/house_detector_tests.cpp b/search/search_tests/house_detector_tests.cpp index 3775ebab9d..155faed8a3 100644 --- a/search/search_tests/house_detector_tests.cpp +++ b/search/search_tests/house_detector_tests.cpp @@ -187,7 +187,7 @@ UNIT_TEST(HS_StreetsMerge) { classificator::Load(); - DataSource dataSource; + DataSource dataSource(make_unique()); LocalCountryFile localFile(LocalCountryFile::MakeForTesting("minsk-pass")); // Clean indexes to avoid jenkins errors. platform::CountryIndexes::DeleteFromDisk(localFile); @@ -256,8 +256,7 @@ UNIT_TEST(HS_StreetsMerge) namespace { - -m2::PointD FindHouse(DataSourceBase & dataSource, vector const & streets, +m2::PointD FindHouse(DataSource & dataSource, vector const & streets, string const & houseName, double offset) { search::HouseDetector houser(dataSource); @@ -284,7 +283,7 @@ UNIT_TEST(HS_FindHouseSmoke) { classificator::Load(); - DataSource dataSource; + DataSource dataSource(make_unique()); auto const p = dataSource.Register(LocalCountryFile::MakeForTesting("minsk-pass")); TEST(p.first.IsAlive(), ()); TEST_EQUAL(MwmSet::RegResult::Success, p.second, ()); @@ -385,7 +384,7 @@ UNIT_TEST(HS_MWMSearch) return; } - DataSource dataSource; + DataSource dataSource(make_unique()); auto p = dataSource.Register(LocalCountryFile::MakeForTesting(country)); if (p.second != MwmSet::RegResult::Success) { diff --git a/search/search_tests/locality_finder_test.cpp b/search/search_tests/locality_finder_test.cpp index c187f87cd4..3182055e18 100644 --- a/search/search_tests/locality_finder_test.cpp +++ b/search/search_tests/locality_finder_test.cpp @@ -16,6 +16,10 @@ #include "base/cancellable.hpp" +#include + +using namespace std; + namespace { class LocalityFinderTest : public generator::tests_support::TestWithClassificator @@ -33,7 +37,8 @@ class LocalityFinderTest : public generator::tests_support::TestWithClassificato public: LocalityFinderTest() - : m_villagesCache(m_cancellable) + : m_dataSource(make_unique()) + , m_villagesCache(m_cancellable) , m_boundariesTable(m_dataSource) , m_finder(m_dataSource, m_boundariesTable, m_villagesCache) { diff --git a/search/search_tests_support/test_results_matching.cpp b/search/search_tests_support/test_results_matching.cpp index 381f18f876..c6b6f7416e 100644 --- a/search/search_tests_support/test_results_matching.cpp +++ b/search/search_tests_support/test_results_matching.cpp @@ -62,7 +62,7 @@ string AlternativesMatchingRule::ToString() const return os.str(); } -bool MatchResults(DataSourceBase const & dataSource, vector> rules, +bool MatchResults(DataSource const & dataSource, vector> rules, vector const & actual) { vector resultIds; @@ -100,14 +100,14 @@ bool MatchResults(DataSourceBase const & dataSource, vector> rules, +bool MatchResults(DataSource const & dataSource, vector> rules, search::Results const & actual) { vector const results(actual.begin(), actual.end()); return MatchResults(dataSource, rules, results); } -bool ResultMatches(DataSourceBase const & dataSource, shared_ptr rule, +bool ResultMatches(DataSource const & dataSource, shared_ptr rule, search::Result const & result) { bool matches = false; diff --git a/search/search_tests_support/test_results_matching.hpp b/search/search_tests_support/test_results_matching.hpp index f6d6fd72d5..0e5c12d57d 100644 --- a/search/search_tests_support/test_results_matching.hpp +++ b/search/search_tests_support/test_results_matching.hpp @@ -11,7 +11,7 @@ #include class FeatureType; -class DataSourceBase; +class DataSource; namespace generator { @@ -74,11 +74,11 @@ std::shared_ptr AlternativesMatch(TArgs &&... args) return std::make_shared(std::forward(args)...); } -bool MatchResults(DataSourceBase const & dataSource, std::vector> rules, +bool MatchResults(DataSource const & dataSource, std::vector> rules, std::vector const & actual); -bool MatchResults(DataSourceBase const & dataSource, std::vector> rules, +bool MatchResults(DataSource const & dataSource, std::vector> rules, search::Results const & actual); -bool ResultMatches(DataSourceBase const & dataSource, std::shared_ptr rule, +bool ResultMatches(DataSource const & dataSource, std::shared_ptr rule, search::Result const & result); std::string DebugPrint(MatchingRule const & rule); diff --git a/search/search_tests_support/test_search_engine.cpp b/search/search_tests_support/test_search_engine.cpp index a9c8dffff2..54c539bf29 100644 --- a/search/search_tests_support/test_search_engine.cpp +++ b/search/search_tests_support/test_search_engine.cpp @@ -12,13 +12,15 @@ namespace search { namespace tests_support { -TestSearchEngine::TestSearchEngine(DataSourceBase & dataSource, unique_ptr infoGetter, +TestSearchEngine::TestSearchEngine(DataSource & dataSource, + unique_ptr infoGetter, Engine::Params const & params) - : m_infoGetter(move(infoGetter)), m_engine(dataSource, GetDefaultCategories(), *m_infoGetter, params) + : m_infoGetter(move(infoGetter)) + , m_engine(dataSource, GetDefaultCategories(), *m_infoGetter, params) { } -TestSearchEngine::TestSearchEngine(DataSourceBase & dataSource, Engine::Params const & params) +TestSearchEngine::TestSearchEngine(DataSource & dataSource, Engine::Params const & params) : m_infoGetter(storage::CountryInfoReader::CreateCountryInfoReader(GetPlatform())) , m_engine(dataSource, GetDefaultCategories(), *m_infoGetter, params) { diff --git a/search/search_tests_support/test_search_engine.hpp b/search/search_tests_support/test_search_engine.hpp index bc51c33bac..8fbfb3e05d 100644 --- a/search/search_tests_support/test_search_engine.hpp +++ b/search/search_tests_support/test_search_engine.hpp @@ -7,7 +7,7 @@ #include #include -class DataSourceBase; +class DataSource; namespace search { @@ -18,9 +18,9 @@ namespace tests_support class TestSearchEngine { public: - TestSearchEngine(DataSourceBase & dataSource, std::unique_ptr infoGetter, + TestSearchEngine(DataSource & dataSource, std::unique_ptr infoGetter, Engine::Params const & params); - TestSearchEngine(DataSourceBase & dataSource, Engine::Params const & params); + TestSearchEngine(DataSource & dataSource, Engine::Params const & params); void SetLocale(std::string const & locale) { m_engine.SetLocale(locale); } diff --git a/search/search_tests_support/test_with_custom_mwms.hpp b/search/search_tests_support/test_with_custom_mwms.hpp index 606ea08b2e..baed6cab9d 100644 --- a/search/search_tests_support/test_with_custom_mwms.hpp +++ b/search/search_tests_support/test_with_custom_mwms.hpp @@ -1,6 +1,6 @@ #pragma once -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" #include "editor/editor_tests_support/helpers.hpp" #include "generator/generator_tests_support/test_with_custom_mwms.hpp" @@ -31,7 +31,8 @@ public: template void EditFeature(FeatureID const & id, EditorFn && fn) { - EditableDataSource::FeaturesLoaderGuard loader(m_dataSource, id.m_mwmId); + DataSource::FeaturesLoaderGuard loader(m_dataSource, id.m_mwmId, + EditableFeatureSourceFactory()); FeatureType ft; CHECK(loader.GetFeatureByIndex(id.m_index, ft), ()); editor::tests_support::EditFeature(ft, std::forward(fn)); diff --git a/search/utils.cpp b/search/utils.cpp index 9dca350b72..c316995269 100644 --- a/search/utils.cpp +++ b/search/utils.cpp @@ -42,7 +42,8 @@ strings::LevenshteinDFA BuildLevenshteinDFA(strings::UniString const & s) return strings::LevenshteinDFA(s, 1 /* prefixSize */, kAllowedMisprints, GetMaxErrorsForToken(s)); } -MwmSet::MwmHandle FindWorld(DataSourceBase const & dataSource, vector> const & infos) +MwmSet::MwmHandle FindWorld(DataSource const & dataSource, + vector> const & infos) { MwmSet::MwmHandle handle; for (auto const & info : infos) @@ -56,7 +57,7 @@ MwmSet::MwmHandle FindWorld(DataSourceBase const & dataSource, vector> infos; dataSource.GetMwmsInfo(infos); diff --git a/search/utils.hpp b/search/utils.hpp index c36ef22f8d..11d5cd97dd 100644 --- a/search/utils.hpp +++ b/search/utils.hpp @@ -20,7 +20,7 @@ #include #include -class DataSourceBase; +class DataSource; class MwmInfo; namespace search @@ -114,7 +114,7 @@ bool FillCategories(QuerySliceOnRawStrings const & slice, Locales const & loc return !types.empty(); } -MwmSet::MwmHandle FindWorld(DataSourceBase const & dataSource, - std::vector> const &infos); -MwmSet::MwmHandle FindWorld(DataSourceBase const & dataSource); +MwmSet::MwmHandle FindWorld(DataSource const & dataSource, + std::vector> const & infos); +MwmSet::MwmHandle FindWorld(DataSource const & dataSource); } // namespace search diff --git a/track_analyzing/track_matcher.cpp b/track_analyzing/track_matcher.cpp index dffa3c2fcb..310e9b1ccb 100644 --- a/track_analyzing/track_matcher.cpp +++ b/track_analyzing/track_matcher.cpp @@ -54,7 +54,8 @@ namespace track_analyzing // TrackMatcher ------------------------------------------------------------------------------------ TrackMatcher::TrackMatcher(storage::Storage const & storage, NumMwmId mwmId, platform::CountryFile const & countryFile) - : m_mwmId(mwmId) + : m_dataSource(make_unique()) + , m_mwmId(mwmId) , m_vehicleModel(CarModelFactory({}).GetVehicleModelForCountry(countryFile.GetName())) { auto localCountryFile = storage.GetLatestLocalFile(countryFile); @@ -132,8 +133,8 @@ TrackMatcher::Step::Step(DataPoint const & dataPoint) } void TrackMatcher::Step::FillCandidatesWithNearbySegments( - DataSourceBase const & dataSource, IndexGraph const & graph, VehicleModelInterface const & vehicleModel, - NumMwmId mwmId) + DataSource const & dataSource, IndexGraph const & graph, + VehicleModelInterface const & vehicleModel, NumMwmId mwmId) { dataSource.ForEachInRect( [&](FeatureType const & ft) { diff --git a/track_analyzing/track_matcher.hpp b/track_analyzing/track_matcher.hpp index de386bb765..7563321537 100644 --- a/track_analyzing/track_matcher.hpp +++ b/track_analyzing/track_matcher.hpp @@ -57,7 +57,8 @@ private: DataPoint const & GetDataPoint() const { return m_dataPoint; } routing::Segment const & GetSegment() const { return m_segment; } bool HasCandidates() const { return !m_candidates.empty(); } - void FillCandidatesWithNearbySegments(DataSourceBase const & dataSource, routing::IndexGraph const & graph, + void FillCandidatesWithNearbySegments(DataSource const & dataSource, + routing::IndexGraph const & graph, routing::VehicleModelInterface const & vehicleModel, routing::NumMwmId mwmId); void FillCandidates(Step const & previousStep, routing::IndexGraph & graph); diff --git a/ugc/api.cpp b/ugc/api.cpp index 0ee32a2881..af4bb051e6 100644 --- a/ugc/api.cpp +++ b/ugc/api.cpp @@ -9,7 +9,7 @@ using namespace ugc; namespace ugc { -Api::Api(DataSourceBase const & dataSource, NumberOfUnsynchronizedCallback const & callback) +Api::Api(DataSource const & dataSource, NumberOfUnsynchronizedCallback const & callback) : m_storage(dataSource), m_loader(dataSource) { m_thread.Push([this, callback] { diff --git a/ugc/api.hpp b/ugc/api.hpp index 40198c076c..b531be5943 100644 --- a/ugc/api.hpp +++ b/ugc/api.hpp @@ -10,7 +10,7 @@ #include -class DataSourceBase; +class DataSource; struct FeatureID; namespace ugc @@ -24,7 +24,7 @@ public: using OnResultCallback = platform::SafeCallback; using NumberOfUnsynchronizedCallback = std::function; - Api(DataSourceBase const & dataSource, NumberOfUnsynchronizedCallback const & callback); + Api(DataSource const & dataSource, NumberOfUnsynchronizedCallback const & callback); void GetUGC(FeatureID const & id, UGCCallbackUnsafe const & callback); void SetUGCUpdate(FeatureID const & id, UGCUpdate const & ugc, diff --git a/ugc/loader.cpp b/ugc/loader.cpp index 3c2ad20085..51501c86f8 100644 --- a/ugc/loader.cpp +++ b/ugc/loader.cpp @@ -7,7 +7,7 @@ namespace ugc { -Loader::Loader(DataSourceBase const & dataSource) : m_dataSource(dataSource) {} +Loader::Loader(DataSource const & dataSource) : m_dataSource(dataSource) {} UGC Loader::GetUGC(FeatureID const & featureId) { diff --git a/ugc/loader.hpp b/ugc/loader.hpp index 8a5fa3b65b..afcfc7e848 100644 --- a/ugc/loader.hpp +++ b/ugc/loader.hpp @@ -9,7 +9,7 @@ #include #include -class DataSourceBase; +class DataSource; struct FeatureID; namespace ugc @@ -18,7 +18,7 @@ namespace ugc class Loader { public: - Loader(DataSourceBase const & dataSource); + Loader(DataSource const & dataSource); UGC GetUGC(FeatureID const & featureId); private: @@ -30,7 +30,7 @@ private: using EntryPtr = std::shared_ptr; - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; std::map m_deserializers; std::mutex m_mutex; }; diff --git a/ugc/storage.cpp b/ugc/storage.cpp index 9909b145c5..bccafde31f 100644 --- a/ugc/storage.cpp +++ b/ugc/storage.cpp @@ -3,9 +3,10 @@ #include "ugc/serdes.hpp" #include "ugc/serdes_json.hpp" -#include "editor/editable_data_source.hpp" +#include "editor/editable_feature_source.hpp" #include "indexer/classificator.hpp" +#include "indexer/data_source.hpp" #include "indexer/feature_algo.hpp" #include "indexer/feature_decl.hpp" #include "indexer/ftraits.hpp" @@ -443,7 +444,7 @@ uint64_t Storage::UGCSizeAtIndex(size_t const indexPosition) const unique_ptr Storage::GetFeature(FeatureID const & id) const { CHECK(id.IsValid(), ()); - EditableDataSource::FeaturesLoaderGuard guard(m_dataSource, id.m_mwmId); + DataSource::FeaturesLoaderGuard guard(m_dataSource, id.m_mwmId, EditableFeatureSourceFactory()); auto feature = guard.GetOriginalOrEditedFeatureByIndex(id.m_index); feature->ParseGeometry(FeatureType::BEST_GEOMETRY); if (feature->GetFeatureType() == feature::EGeomType::GEOM_AREA) diff --git a/ugc/storage.hpp b/ugc/storage.hpp index e3d5c21f45..30ce16f8a4 100644 --- a/ugc/storage.hpp +++ b/ugc/storage.hpp @@ -7,7 +7,7 @@ #include #include -class DataSourceBase; +class DataSource; class FeatureType; struct FeatureID; @@ -16,7 +16,7 @@ namespace ugc class Storage { public: - explicit Storage(DataSourceBase const & dataSource) : m_dataSource(dataSource) {} + explicit Storage(DataSource const & dataSource) : m_dataSource(dataSource) {} UGCUpdate GetUGCUpdate(FeatureID const & id) const; @@ -46,7 +46,7 @@ private: std::unique_ptr GetFeature(FeatureID const & id) const; void Migrate(std::string const & indexFilePath); - DataSourceBase const & m_dataSource; + DataSource const & m_dataSource; UpdateIndexes m_indexes; size_t m_numberOfDeleted = 0; }; diff --git a/ugc/ugc_tests/storage_tests.cpp b/ugc/ugc_tests/storage_tests.cpp index da2815e5ae..0302fc9cce 100644 --- a/ugc/ugc_tests/storage_tests.cpp +++ b/ugc/ugc_tests/storage_tests.cpp @@ -102,7 +102,7 @@ public: return FeatureIdForPoint(mercator, ftypes::IsRailwayStationChecker::Instance()); } - DataSourceBase & GetDataSource() { return m_dataSource; } + DataSource & GetDataSource() { return m_dataSource; } ~MwmBuilder() { @@ -111,10 +111,7 @@ public: } private: - MwmBuilder() - { - classificator::Load(); - } + MwmBuilder() : m_dataSource(make_unique()) { classificator::Load(); } MwmSet::MwmId BuildMwm(BuilderFn const & fn) { diff --git a/xcode/editor/editor.xcodeproj/project.pbxproj b/xcode/editor/editor.xcodeproj/project.pbxproj index 46f64c2060..9a8e39123a 100644 --- a/xcode/editor/editor.xcodeproj/project.pbxproj +++ b/xcode/editor/editor.xcodeproj/project.pbxproj @@ -154,7 +154,6 @@ 6715564120BF0267002BA3B4 /* libeditor_tests_support.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libeditor_tests_support.a; sourceTree = BUILT_PRODUCTS_DIR; }; 6715565220BF0F86002BA3B4 /* new_feature_categories.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = new_feature_categories.cpp; sourceTree = ""; }; 6715565320BF0F87002BA3B4 /* new_feature_categories.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = new_feature_categories.hpp; sourceTree = ""; }; - 671ED37220D3B65100D4317E /* editable_data_source.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = editable_data_source.hpp; sourceTree = ""; }; 675B562520D2706000A521D2 /* editable_feature_source.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = editable_feature_source.cpp; sourceTree = ""; }; 675B562620D2706000A521D2 /* editable_feature_source.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = editable_feature_source.hpp; sourceTree = ""; }; 67A7F0D520DBF00400937412 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; @@ -242,7 +241,6 @@ 340DC8281C4E71E500EAA2CC /* changeset_wrapper.hpp */, 3D3058721D707DBE004AC712 /* config_loader.cpp */, 3D3058731D707DBE004AC712 /* config_loader.hpp */, - 671ED37220D3B65100D4317E /* editable_data_source.hpp */, 675B562520D2706000A521D2 /* editable_feature_source.cpp */, 675B562620D2706000A521D2 /* editable_feature_source.hpp */, 34527C4F1C89B1770015050E /* editor_config.cpp */, -- cgit v1.2.3