diff --git a/generator/gen_mwm_info.hpp b/generator/gen_mwm_info.hpp index d9f8ce99af..b1f875b0f9 100644 --- a/generator/gen_mwm_info.hpp +++ b/generator/gen_mwm_info.hpp @@ -5,10 +5,8 @@ #include "base/assert.hpp" #include "std/algorithm.hpp" -#include "std/fstream.hpp" -#include "std/iostream.hpp" -#include "std/string.hpp" #include "std/utility.hpp" +#include "std/vector.hpp" namespace gen { @@ -31,11 +29,11 @@ public: { rw::ReadVectorOfPOD(src, m_data); } - - vector const & GetData() const { return m_data; } }; -class OsmID2FeatureID : public Accumulator> +using OsmIdAndFeatureId = pair; + +class OsmID2FeatureID : public Accumulator { typedef Accumulator BaseT; @@ -65,5 +63,7 @@ public: else return 0; } + + vector const & GetData() const { return m_data; } }; } // namespace gen diff --git a/generator/generator_tests/restriction_collector_test.cpp b/generator/generator_tests/restriction_collector_test.cpp index 852f7193b6..94ea9c0ad9 100644 --- a/generator/generator_tests/restriction_collector_test.cpp +++ b/generator/generator_tests/restriction_collector_test.cpp @@ -1,6 +1,6 @@ #include "testing/testing.hpp" -#include "generator/generator_tests_support/restrcion_support.hpp" +#include "generator/generator_tests_support/restriction_helpers.hpp" #include "generator/osm_id.hpp" #include "generator/restriction_collector.hpp" @@ -90,11 +90,14 @@ UNIT_TEST(RestrictionTest_ParseRestrictions) UNIT_TEST(RestrictionTest_RestrictionCollectorWholeClassTest) { + ScopedDir scopedDir(kRestrictionTestDir); + string const kRestrictionName = "restrictions_in_osm_ids.csv"; string const kRestrictionPath = my::JoinFoldersToPath(kRestrictionTestDir, kRestrictionName); string const kRestrictionContent = R"(No, 10, 10, Only, 10, 20, Only, 30, 40,)"; + ScopedFile restrictionScopedFile(kRestrictionPath, kRestrictionContent); string const kOsmIdsToFeatureIdsName = "osm_ids_to_feature_ids" OSM2FEATURE_FILE_EXTENSION; string const osmIdsToFeatureIdsPath = @@ -106,10 +109,7 @@ UNIT_TEST(RestrictionTest_RestrictionCollectorWholeClassTest) Platform const & platform = Platform(); string const osmIdsToFeatureIdsFullPath = my::JoinFoldersToPath(platform.WritableDir(), osmIdsToFeatureIdsPath); - GenerateOsmIdsToFeatureIdsMapping(kOsmIdsToFeatureIdsContent, osmIdsToFeatureIdsFullPath); - - ScopedDir scopedDir(kRestrictionTestDir); - ScopedFile restrictionScopedFile(kRestrictionPath, kRestrictionContent); + ReEncodeOsmIdsToFeatureIdsMapping(kOsmIdsToFeatureIdsContent, osmIdsToFeatureIdsFullPath); ScopedFile mappingScopedFile(osmIdsToFeatureIdsPath); RestrictionCollector restrictionCollector( diff --git a/generator/generator_tests/restriction_test.cpp b/generator/generator_tests/restriction_test.cpp index efd6e5ff96..71b5aef962 100644 --- a/generator/generator_tests/restriction_test.cpp +++ b/generator/generator_tests/restriction_test.cpp @@ -1,6 +1,6 @@ #include "testing/testing.hpp" -#include "generator/generator_tests_support/restrcion_support.hpp" +#include "generator/generator_tests_support/restriction_helpers.hpp" #include "generator/generator_tests_support/test_feature.hpp" #include "generator/generator_tests_support/test_mwm_builder.hpp" @@ -69,7 +69,7 @@ void TestRestrictionBuilding(string const & restrictionContent, string const & m string const mappingRelativePath = my::JoinFoldersToPath(kTestDir, kOsmIdsToFeatureIdsName); ScopedFile const mappingScopedFile(mappingRelativePath); string const mappingFullPath = my::JoinFoldersToPath(writableDir, mappingRelativePath); - GenerateOsmIdsToFeatureIdsMapping(mappingContent, mappingFullPath); + ReEncodeOsmIdsToFeatureIdsMapping(mappingContent, mappingFullPath); // Adding restriction section to mwm. string const restrictionFullPath = my::JoinFoldersToPath(writableDir, restrictionRelativePath); diff --git a/generator/generator_tests_support/generator_tests_support.pro b/generator/generator_tests_support/generator_tests_support.pro index af3ff085e2..46b0560b79 100644 --- a/generator/generator_tests_support/generator_tests_support.pro +++ b/generator/generator_tests_support/generator_tests_support.pro @@ -7,11 +7,11 @@ ROOT_DIR = ../.. include($$ROOT_DIR/common.pri) SOURCES += \ - restrcion_support.cpp \ + restriction_helpers.cpp \ test_feature.cpp \ test_mwm_builder.cpp \ HEADERS += \ - restrcion_support.hpp \ + restriction_helpers.hpp \ test_feature.hpp \ test_mwm_builder.hpp \ diff --git a/generator/generator_tests_support/restrcion_support.cpp b/generator/generator_tests_support/restriction_helpers.cpp similarity index 76% rename from generator/generator_tests_support/restrcion_support.cpp rename to generator/generator_tests_support/restriction_helpers.cpp index 678cc37fd4..3ac0aacba3 100644 --- a/generator/generator_tests_support/restrcion_support.cpp +++ b/generator/generator_tests_support/restriction_helpers.cpp @@ -1,4 +1,4 @@ -#include "generator/generator_tests_support/restrcion_support.hpp" +#include "generator/generator_tests_support/restriction_helpers.hpp" #include "testing/testing.hpp" @@ -12,20 +12,22 @@ namespace generator { -void GenerateOsmIdsToFeatureIdsMapping(string const & mappingContent, string const & outputFilePath) +void ReEncodeOsmIdsToFeatureIdsMapping(string const & mappingContent, string const & outputFilePath) { - strings::SimpleTokenizer lineIter(mappingContent, "\n\r" /* string delimiter */); + strings::SimpleTokenizer lineIter(mappingContent, "\n\r" /* line delimiters */); gen::Accumulator> osmIdsToFeatureIds; for (; lineIter; ++lineIter) { - strings::SimpleTokenizer idIter(*lineIter, ", \t" /* id delimiter */); + strings::SimpleTokenizer idIter(*lineIter, ", \t" /* id delimiters */); uint64_t osmId = 0; + TEST(idIter, ()); TEST(strings::to_uint64(*idIter, osmId), ("Cannot covert to uint64_t:", *idIter)); TEST(idIter, ("Wrong feature ids to osm ids mapping.")); ++idIter; uint32_t featureId = 0; + TEST(idIter, ()); TEST(strings::to_uint(*idIter, featureId), ("Cannot covert to uint:", *idIter)); osmIdsToFeatureIds.Add(make_pair(osmId, featureId)); } diff --git a/generator/generator_tests_support/restrcion_support.hpp b/generator/generator_tests_support/restriction_helpers.hpp similarity index 69% rename from generator/generator_tests_support/restrcion_support.hpp rename to generator/generator_tests_support/restriction_helpers.hpp index 2268158c5a..46a85a1ebf 100644 --- a/generator/generator_tests_support/restrcion_support.hpp +++ b/generator/generator_tests_support/restriction_helpers.hpp @@ -4,7 +4,7 @@ namespace generator { -/// \brief Generates a binary file with by a string with mapping from osm ids to feature ids. +/// \brief Generates a binary file by |mappingContent| with mapping from osm ids to feature ids. /// \param mappingContent a string with lines with mapping from osm id to feature id (one to one). /// For example /// 10, 1, @@ -12,5 +12,5 @@ namespace generator /// 30, 3, /// 40, 4 /// \parma outputFilePath full path to an output file where the mapping is saved. -void GenerateOsmIdsToFeatureIdsMapping(string const & mappingContent, string const & outputFilePath); +void ReEncodeOsmIdsToFeatureIdsMapping(string const & mappingContent, string const & outputFilePath); } // namespace generator diff --git a/generator/restriction_collector.cpp b/generator/restriction_collector.cpp index 58c85e27a6..7e6ff19828 100644 --- a/generator/restriction_collector.cpp +++ b/generator/restriction_collector.cpp @@ -72,10 +72,7 @@ bool RestrictionCollector::IsValid() const bool RestrictionCollector::ParseOsmIdToFeatureIdMapping(string const & osmIdsToFeatureIdPath) { - LOG(LINFO, ("osmIdsToFeatureIdPath =", osmIdsToFeatureIdPath)); - - using OsmIdToFeatureId = pair; - gen::Accumulator osmIdsToFeatureIds; + gen::OsmID2FeatureID osmIdsToFeatureIds; try { FileReader reader(osmIdsToFeatureIdPath); @@ -88,7 +85,7 @@ bool RestrictionCollector::ParseOsmIdToFeatureIdMapping(string const & osmIdsToF return false; } - vector const & mapping = osmIdsToFeatureIds.GetData(); + vector const & mapping = osmIdsToFeatureIds.GetData(); if (mapping.empty()) { LOG(LINFO, ("No osm ids to feature ids mapping in file", osmIdsToFeatureIdPath));