From bf4661a690ca489ccb0c811dd0e426ea1f41a44b Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Fri, 14 Sep 2018 16:16:34 +0300 Subject: [PATCH] Renaming CityRoadsLoader to CityRoads and changing the code according to it. --- .../generator_tests/city_roads_tests.cpp | 18 ++++--- routing/CMakeLists.txt | 4 +- .../{city_roads_loader.cpp => city_roads.cpp} | 52 ++++++++++--------- .../{city_roads_loader.hpp => city_roads.hpp} | 11 ++-- routing/city_roads_serialization.hpp | 2 +- routing_common/vehicle_model.cpp | 2 + 6 files changed, 50 insertions(+), 39 deletions(-) rename routing/{city_roads_loader.cpp => city_roads.cpp} (68%) rename routing/{city_roads_loader.hpp => city_roads.hpp} (50%) diff --git a/generator/generator_tests/city_roads_tests.cpp b/generator/generator_tests/city_roads_tests.cpp index 1c5914bc96..64972a62fd 100644 --- a/generator/generator_tests/city_roads_tests.cpp +++ b/generator/generator_tests/city_roads_tests.cpp @@ -4,7 +4,7 @@ #include "generator/city_roads_generator.hpp" -#include "routing/city_roads_loader.hpp" +#include "routing/city_roads.hpp" #include "indexer/data_source.hpp" @@ -49,14 +49,14 @@ void BuildEmptyMwm(LocalCountryFile & country) generator::tests_support::TestMwmBuilder builder(country, feature::DataHeader::country); } -unique_ptr LoadCityRoads(LocalCountryFile const & country) +bool LoadCityRoads(LocalCountryFile const & country, CityRoads & cityRoads) { FrozenDataSource dataSource; auto const regResult = dataSource.RegisterMap(country); TEST_EQUAL(regResult.second, MwmSet::RegResult::Success, ()); auto const & mwmId = regResult.first; - return make_unique(dataSource, mwmId); + return LoadCityRoads(dataSource, mwmId, cityRoads); } /// \brief Builds mwm with city_roads section, read the section and compare original feature ids @@ -81,25 +81,27 @@ void TestCityRoadsBuilding(vector && cityRoadFeatureIds) vector originalCityRoadFeatureIds = cityRoadFeatureIds; SerializeCityRoads(mwmFullPath, move(cityRoadFeatureIds)); - auto const loader = LoadCityRoads(country); - TEST(loader, ()); + CityRoads cityRoads; + bool const loadCityRoadsResult = LoadCityRoads(country, cityRoads); // Comparing loading form mwm and expected feature ids. if (originalCityRoadFeatureIds.empty()) { - TEST(!loader->HasCityRoads(), ()); + TEST(!cityRoads.HasCityRoads(), ()); return; } + TEST(loadCityRoadsResult, ()); + sort(originalCityRoadFeatureIds.begin(), originalCityRoadFeatureIds.end()); size_t const kMaxRoadFeatureId = originalCityRoadFeatureIds.back(); CHECK_LESS(kMaxRoadFeatureId, numeric_limits::max(), ()); - // Note. 2 is added below to test all the if-branches of CityRoadsLoader::IsCityRoad() method. + // Note. 2 is added below to test all the if-branches of CityRoads::IsCityRoad() method. for (uint32_t fid = 0; fid < kMaxRoadFeatureId + 2; ++fid) { bool const isCityRoad = binary_search(originalCityRoadFeatureIds.cbegin(), originalCityRoadFeatureIds.cend(), fid); - TEST_EQUAL(loader->IsCityRoad(fid), isCityRoad, (fid)); + TEST_EQUAL(cityRoads.IsCityRoad(fid), isCityRoad, (fid)); } } diff --git a/routing/CMakeLists.txt b/routing/CMakeLists.txt index 453615ff39..3c346e1197 100644 --- a/routing/CMakeLists.txt +++ b/routing/CMakeLists.txt @@ -20,8 +20,8 @@ set( checkpoint_predictor.hpp checkpoints.cpp checkpoints.hpp - city_roads_loader.cpp - city_roads_loader.hpp + city_roads.cpp + city_roads.hpp city_roads_serialization.hpp coding.hpp cross_mwm_connector.cpp diff --git a/routing/city_roads_loader.cpp b/routing/city_roads.cpp similarity index 68% rename from routing/city_roads_loader.cpp rename to routing/city_roads.cpp index f4a3435ab5..fbce413a40 100644 --- a/routing/city_roads_loader.cpp +++ b/routing/city_roads.cpp @@ -1,4 +1,4 @@ -#include "routing/city_roads_loader.hpp" +#include "routing/city_roads.hpp" #include "routing/city_roads_serialization.hpp" @@ -14,34 +14,36 @@ namespace routing { -CityRoadsLoader::CityRoadsLoader(DataSource const & dataSource, MwmSet::MwmId const & mwmId) -{ - MwmSet::MwmHandle m_handle(dataSource.GetMwmHandleById(mwmId)); - if (!m_handle.IsAlive()) - return; - - auto const & mwmValue = *m_handle.GetValue(); - if (!mwmValue.m_cont.IsExist(CITY_ROADS_FILE_TAG)) - return; - - try - { - FilesContainerR::TReader reader(mwmValue.m_cont.GetReader(CITY_ROADS_FILE_TAG)); - ReaderSource src(reader); - CityRoadsSerializer::Deserialize(src, m_cityRoadsRegion, m_cityRoads); - } - catch (Reader::OpenException const & e) - { - LOG(LERROR, ("File", mwmValue.GetCountryFileName(), "Error while reading", CITY_ROADS_FILE_TAG, - "section.", e.Msg())); - } -} - -bool CityRoadsLoader::IsCityRoad(uint32_t fid) const +bool CityRoads::IsCityRoad(uint32_t fid) const { if (fid < m_cityRoads.size()) return m_cityRoads[fid]; return false; } + +bool LoadCityRoads(DataSource const & dataSource, MwmSet::MwmId const & mwmId, CityRoads & cityRoads) +{ + MwmSet::MwmHandle m_handle(dataSource.GetMwmHandleById(mwmId)); + if (!m_handle.IsAlive()) + return false; + + auto const & mwmValue = *m_handle.GetValue(); + if (!mwmValue.m_cont.IsExist(CITY_ROADS_FILE_TAG)) + return false; + + try + { + FilesContainerR::TReader reader(mwmValue.m_cont.GetReader(CITY_ROADS_FILE_TAG)); + ReaderSource src(reader); + CityRoadsSerializer::Deserialize(src, cityRoads.m_cityRoadsRegion, cityRoads.m_cityRoads); + return true; + } + catch (Reader::OpenException const & e) + { + LOG(LERROR, ("File", mwmValue.GetCountryFileName(), "Error while reading", CITY_ROADS_FILE_TAG, + "section.", e.Msg())); + return false; + } +} } // namespace routing diff --git a/routing/city_roads_loader.hpp b/routing/city_roads.hpp similarity index 50% rename from routing/city_roads_loader.hpp rename to routing/city_roads.hpp index 525857810f..9f3957785d 100644 --- a/routing/city_roads_loader.hpp +++ b/routing/city_roads.hpp @@ -13,16 +13,21 @@ class DataSource; namespace routing { -class CityRoadsLoader +class CityRoads { -public: - CityRoadsLoader(DataSource const & dataSource, MwmSet::MwmId const & mwmId); + friend bool LoadCityRoads(DataSource const & dataSource, MwmSet::MwmId const & mwmId, + CityRoads & cityRoads); +public: bool HasCityRoads() const { return m_cityRoads.size() > 0; } + // Returns true if |fid| is a feature id of a road (for cars, bicycles or pedestrians) in city. bool IsCityRoad(uint32_t fid) const; private: std::unique_ptr m_cityRoadsRegion; + // |m_cityRoads| contains true for feature ids which are roads in cities. succinct::elias_fano m_cityRoads; }; + +bool LoadCityRoads(DataSource const & dataSource, MwmSet::MwmId const & mwmId, CityRoads & cityRoads); } // namespace routing diff --git a/routing/city_roads_serialization.hpp b/routing/city_roads_serialization.hpp index 63ef257c94..6da83a15c3 100644 --- a/routing/city_roads_serialization.hpp +++ b/routing/city_roads_serialization.hpp @@ -1,6 +1,6 @@ #pragma once -#include "routing/city_roads_loader.hpp" +#include "routing/city_roads.hpp" #include "coding/succinct_mapper.hpp" #include "coding/writer.hpp" diff --git a/routing_common/vehicle_model.cpp b/routing_common/vehicle_model.cpp index af32d54c1a..940ef172b4 100644 --- a/routing_common/vehicle_model.cpp +++ b/routing_common/vehicle_model.cpp @@ -86,6 +86,8 @@ VehicleModel::SpeedKMpH VehicleModel::GetSpeed(FeatureType & f) const feature::TypesHolder const types(f); RoadAvailability const restriction = GetRoadAvailability(types); + // TODO(bykoianko) If a road is available, a speed according to city status (CityRoads) + // should be returned. if (restriction == RoadAvailability::Available) return GetMaxSpeed(); if (restriction != RoadAvailability::NotAvailable && HasRoadType(types))