From c11ae2537fd33e4a1706bd7c9d31b3b8f076515d Mon Sep 17 00:00:00 2001 From: Maksim Andrianov Date: Mon, 15 Apr 2019 15:30:15 +0300 Subject: [PATCH] Review fixes --- generator/CMakeLists.txt | 4 +- ...ode_processor.cpp => collector_camera.cpp} | 52 ++-- ...ode_processor.hpp => collector_camera.hpp} | 30 ++- generator/feature_maker.cpp | 8 +- generator/feature_maker.hpp | 10 +- generator/feature_maker_base.cpp | 14 +- generator/feature_maker_base.hpp | 14 +- generator/generator_tests/CMakeLists.txt | 1 + .../camera_collector_tests.cpp | 251 ++++++++++++++++++ .../intermediate_data_test.cpp | 230 +--------------- generator/holes.cpp | 14 +- generator/holes.hpp | 6 +- generator/osm_source.cpp | 21 +- generator/routing_helpers.hpp | 7 - generator/translator.cpp | 10 +- generator/translator.hpp | 6 +- generator/translator_coastline.cpp | 4 +- generator/translator_coastline.hpp | 2 +- generator/translator_country.cpp | 12 +- generator/translator_country.hpp | 2 +- generator/translator_geo_objects.cpp | 4 +- generator/translator_geo_objects.hpp | 2 +- generator/translator_interface.hpp | 2 +- generator/translator_region.cpp | 4 +- generator/translator_region.hpp | 2 +- generator/translator_world.cpp | 4 +- generator/translator_world.hpp | 2 +- generator/ways_merger.cpp | 6 +- generator/ways_merger.hpp | 6 +- 29 files changed, 378 insertions(+), 352 deletions(-) rename generator/{camera_node_processor.cpp => collector_camera.cpp} (79%) rename generator/{camera_node_processor.hpp => collector_camera.hpp} (61%) create mode 100644 generator/generator_tests/camera_collector_tests.cpp diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index 00ff760778..1592d7589b 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -20,8 +20,6 @@ set(SRC brands_loader.hpp camera_info_collector.cpp camera_info_collector.hpp - camera_node_processor.cpp - camera_node_processor.hpp centers_table_builder.cpp centers_table_builder.hpp check_model.cpp @@ -39,6 +37,8 @@ set(SRC collection_base.hpp collector_addresses.cpp collector_addresses.hpp + collector_camera.cpp + collector_camera.hpp collector_collection.cpp collector_collection.hpp collector_interface.hpp diff --git a/generator/camera_node_processor.cpp b/generator/collector_camera.cpp similarity index 79% rename from generator/camera_node_processor.cpp rename to generator/collector_camera.cpp index 671a6afc40..a0f9527080 100644 --- a/generator/camera_node_processor.cpp +++ b/generator/collector_camera.cpp @@ -1,4 +1,4 @@ -#include "generator/camera_node_processor.hpp" +#include "generator/collector_camera.hpp" #include "generator/feature_builder.hpp" #include "generator/osm_element.hpp" @@ -25,6 +25,25 @@ namespace routing { size_t const CameraProcessor::kMaxSpeedSpeedStringLength = 32; +std::string ValidateMaxSpeedString(std::string const & maxSpeedString) +{ + routing::SpeedInUnits speed; + if (!generator::ParseMaxspeedTag(maxSpeedString, speed) || !speed.IsNumeric()) + return std::string(); + + return strings::to_string(measurement_utils::ToSpeedKmPH(speed.GetSpeed(), speed.GetUnits())); +} + +CameraProcessor::CameraInfo::CameraInfo(OsmElement const & element) + : m_id(element.id) + , m_lon(element.lon) + , m_lat(element.lat) +{ + auto const maxspeed = element.GetTag("maxspeed"); + if (!maxspeed.empty()) + m_speed = ValidateMaxSpeedString(maxspeed); +} + void CameraProcessor::ForEachCamera(Fn && toDo) const { std::vector empty; @@ -47,34 +66,17 @@ void CameraProcessor::ProcessWay(OsmElement const & element) } } -// static -std::string CameraProcessor::ValidateMaxSpeedString(std::string const & maxSpeedString) -{ - routing::SpeedInUnits speed; - if (!generator::ParseMaxspeedTag(maxSpeedString, speed) || !speed.IsNumeric()) - return std::string(); - - return strings::to_string(measurement_utils::ToSpeedKmPH(speed.GetSpeed(), speed.GetUnits())); -} - void CameraProcessor::ProcessNode(OsmElement const & element) { - CameraInfo camera; - camera.m_id = element.id; - camera.m_lat = element.lat; - camera.m_lon = element.lon; - auto const maxspeed = element.GetTag("maxspeed"); - if (!maxspeed.empty()) - camera.m_speed = ValidateMaxSpeedString(maxspeed); - - CHECK_LESS(camera.m_speed.size(), kMaxSpeedSpeedStringLength, ("Too long string for speed")); + CameraInfo camera(element); + CHECK_LESS(camera.m_speed.size(), kMaxSpeedSpeedStringLength, ()); m_speedCameras.emplace(element.id, std::move(camera)); } -CameraNodeProcessor::CameraNodeProcessor(std::string const & writerFile) : +CameraCollector::CameraCollector(std::string const & writerFile) : m_fileWriter(writerFile) {} -void CameraNodeProcessor::CollectFeature(FeatureBuilder1 const & feature, OsmElement const & element) +void CameraCollector::CollectFeature(FeatureBuilder1 const & feature, OsmElement const & element) { switch (element.type) { @@ -95,7 +97,7 @@ void CameraNodeProcessor::CollectFeature(FeatureBuilder1 const & feature, OsmEle } } -void CameraNodeProcessor::Write(CameraProcessor::CameraInfo const & camera, std::vector const & ways) +void CameraCollector::Write(CameraProcessor::CameraInfo const & camera, std::vector const & ways) { std::string maxSpeedStringKmPH = camera.m_speed; int32_t maxSpeedKmPH = 0; @@ -120,9 +122,9 @@ void CameraNodeProcessor::Write(CameraProcessor::CameraInfo const & camera, std: WriteToSink(m_fileWriter, wayId); } -void CameraNodeProcessor::Save() +void CameraCollector::Save() { using namespace std::placeholders; - m_processor.ForEachCamera(std::bind(&CameraNodeProcessor::Write, this, _1, _2)); + m_processor.ForEachCamera(std::bind(&CameraCollector::Write, this, _1, _2)); } } // namespace routing diff --git a/generator/camera_node_processor.hpp b/generator/collector_camera.hpp similarity index 61% rename from generator/camera_node_processor.hpp rename to generator/collector_camera.hpp index 4242250f53..2fc5d783ae 100644 --- a/generator/camera_node_processor.hpp +++ b/generator/collector_camera.hpp @@ -13,7 +13,7 @@ namespace generator_tests { -class TestCameraNodeProcessor; +class TestCameraCollector; } // namespace generator_tests struct OsmElement; @@ -22,6 +22,15 @@ class FeatureBuilder1; // TODO (@gmoryes) move members of m_routingTagsProcessor to generator namespace routing { +/// \brief Gets text with speed, returns formatted speed string in km per hour. +/// \param maxSpeedString - text with speed. Possible format: +/// "130" - means 130 km per hour. +/// "130 mph" - means 130 miles per hour. +/// "130 kmh" - means 130 km per hour. +/// See https://wiki.openstreetmap.org/wiki/Key:maxspeed +/// for more details about input string. +std::string ValidateMaxSpeedString(std::string const & maxSpeedString); + class CameraProcessor { public: @@ -30,6 +39,8 @@ public: struct CameraInfo { + CameraInfo(const OsmElement & element); + uint64_t m_id = 0; double m_lon = 0.0; double m_lat = 0.0; @@ -44,27 +55,20 @@ public: void ProcessWay(OsmElement const & element); private: - /// \brief Gets text with speed, returns formatted speed string in km per hour. - /// \param maxSpeedString - text with speed. Possible format: - /// "130" - means 130 km per hour. - /// "130 mph" - means 130 miles per hour. - /// "130 kmh" - means 130 km per hour. - /// See https://wiki.openstreetmap.org/wiki/Key:maxspeed - /// for more details about input string. - static std::string ValidateMaxSpeedString(std::string const & maxSpeedString); - std::unordered_map m_speedCameras; std::unordered_map> m_cameraToWays; }; -class CameraNodeProcessor : public generator::CollectorInterface +class CameraCollector : public generator::CollectorInterface { public: - friend class generator_tests::TestCameraNodeProcessor; + friend class generator_tests::TestCameraCollector; - explicit CameraNodeProcessor(std::string const & writerFile); + explicit CameraCollector(std::string const & writerFile); // generator::CollectorInterface overrides: + // We will process all nodes before ways because of o5m format: + // all nodes are first, then all ways, then all relations. void CollectFeature(FeatureBuilder1 const & feature, OsmElement const & element) override; void Save() override; diff --git a/generator/feature_maker.cpp b/generator/feature_maker.cpp index ed280396a0..99d945cb19 100644 --- a/generator/feature_maker.cpp +++ b/generator/feature_maker.cpp @@ -40,7 +40,7 @@ bool FeatureMakerSimple::BuildFromWay(OsmElement & p, FeatureParams const & para m2::PointD pt; for (uint64_t ref : nodes) { - if (!m_holder.GetNode(ref, pt.y, pt.x)) + if (!m_cache.GetNode(ref, pt.y, pt.x)) return false; fb.AddPoint(pt); @@ -50,8 +50,8 @@ bool FeatureMakerSimple::BuildFromWay(OsmElement & p, FeatureParams const & para fb.SetParams(params); if (fb.IsGeometryClosed()) { - HolesProcessor processor(p.id, m_holder); - m_holder.ForEachRelationByWay(p.id, processor); + HolesProcessor processor(p.id, m_cache); + m_cache.ForEachRelationByWay(p.id, processor); fb.SetAreaAddHoles(processor.GetHoles()); } else @@ -65,7 +65,7 @@ bool FeatureMakerSimple::BuildFromWay(OsmElement & p, FeatureParams const & para bool FeatureMakerSimple::BuildFromRelation(OsmElement & p, FeatureParams const & params) { - HolesRelation helper(m_holder); + HolesRelation helper(m_cache); helper.Build(&p); auto const & holesGeometry = helper.GetHoles(); auto & outer = helper.GetOuter(); diff --git a/generator/feature_maker.hpp b/generator/feature_maker.hpp index 9568a3627a..d171e803bb 100644 --- a/generator/feature_maker.hpp +++ b/generator/feature_maker.hpp @@ -17,13 +17,13 @@ public: protected: // FeatureMaker overrides: - void ParseParams(FeatureParams & params, OsmElement & p) const override; + void ParseParams(FeatureParams & params, OsmElement & element) const override; private: // FeatureMaker overrides: - bool BuildFromNode(OsmElement & p, FeatureParams const & params) override; - bool BuildFromWay(OsmElement & p, FeatureParams const & params) override; - bool BuildFromRelation(OsmElement & p, FeatureParams const & params) override; + bool BuildFromNode(OsmElement & element, FeatureParams const & params) override; + bool BuildFromWay(OsmElement & element, FeatureParams const & params) override; + bool BuildFromRelation(OsmElement & element, FeatureParams const & params) override; }; // The difference between class FeatureMakerSimple and class FeatureMaker is that @@ -35,6 +35,6 @@ public: private: // FeatureMaker overrides: - void ParseParams(FeatureParams & params, OsmElement & p) const override; + void ParseParams(FeatureParams & params, OsmElement & element) const override; }; } // namespace generator diff --git a/generator/feature_maker_base.cpp b/generator/feature_maker_base.cpp index d8e15d1895..93a4c57cde 100644 --- a/generator/feature_maker_base.cpp +++ b/generator/feature_maker_base.cpp @@ -8,20 +8,20 @@ namespace generator { -FeatureMakerBase::FeatureMakerBase(cache::IntermediateDataReader & holder) : m_holder(holder) {} +FeatureMakerBase::FeatureMakerBase(cache::IntermediateDataReader & cache) : m_cache(cache) {} -bool FeatureMakerBase::Add(OsmElement & p) +bool FeatureMakerBase::Add(OsmElement & element) { FeatureParams params; - ParseParams(params, p); - switch (p.type) + ParseParams(params, element); + switch (element.type) { case OsmElement::EntityType::Node: - return BuildFromNode(p, params); + return BuildFromNode(element, params); case OsmElement::EntityType::Way: - return BuildFromWay(p, params); + return BuildFromWay(element, params); case OsmElement::EntityType::Relation: - return BuildFromRelation(p, params); + return BuildFromRelation(element, params); default: return false; } diff --git a/generator/feature_maker_base.hpp b/generator/feature_maker_base.hpp index d026baf6d0..8eff7ad891 100644 --- a/generator/feature_maker_base.hpp +++ b/generator/feature_maker_base.hpp @@ -19,23 +19,23 @@ class IntermediateDataReader; class FeatureMakerBase { public: - explicit FeatureMakerBase(cache::IntermediateDataReader & holder); + explicit FeatureMakerBase(cache::IntermediateDataReader & cache); virtual ~FeatureMakerBase() = default; - bool Add(OsmElement & p); + bool Add(OsmElement & element); // The function returns true when the receiving feature was successful and a false when not successful. bool GetNextFeature(FeatureBuilder1 & feature); size_t Size() const; bool Empty() const; protected: - virtual bool BuildFromNode(OsmElement & p, FeatureParams const & params) = 0; - virtual bool BuildFromWay(OsmElement & p, FeatureParams const & params) = 0; - virtual bool BuildFromRelation(OsmElement & p, FeatureParams const & params) = 0; + virtual bool BuildFromNode(OsmElement & element, FeatureParams const & params) = 0; + virtual bool BuildFromWay(OsmElement & element, FeatureParams const & params) = 0; + virtual bool BuildFromRelation(OsmElement & element, FeatureParams const & params) = 0; - virtual void ParseParams(FeatureParams & params, OsmElement & p) const = 0; + virtual void ParseParams(FeatureParams & params, OsmElement & element) const = 0; - cache::IntermediateDataReader & m_holder; + cache::IntermediateDataReader & m_cache; std::queue m_queue; }; diff --git a/generator/generator_tests/CMakeLists.txt b/generator/generator_tests/CMakeLists.txt index 59d39f4a3d..374773a549 100644 --- a/generator/generator_tests/CMakeLists.txt +++ b/generator/generator_tests/CMakeLists.txt @@ -4,6 +4,7 @@ set( SRC altitude_test.cpp brands_loader_test.cpp + camera_collector_tests.cpp check_mwms.cpp cities_boundaries_checker_tests.cpp city_roads_tests.cpp diff --git a/generator/generator_tests/camera_collector_tests.cpp b/generator/generator_tests/camera_collector_tests.cpp new file mode 100644 index 0000000000..cd531ee2c6 --- /dev/null +++ b/generator/generator_tests/camera_collector_tests.cpp @@ -0,0 +1,251 @@ +#include "testing/testing.hpp" + +#include "platform/platform.hpp" +#include "platform/platform_tests_support/scoped_dir.hpp" +#include "platform/platform_tests_support/scoped_file.hpp" +#include "platform/platform_tests_support/writable_dir_changer.hpp" + +#include "generator/collector_camera.hpp" +#include "generator/emitter_factory.hpp" +#include "generator/feature_maker.hpp" +#include "generator/generate_info.hpp" +#include "generator/intermediate_data.hpp" +#include "generator/intermediate_elements.hpp" +#include "generator/osm_source.hpp" +#include "generator/translator.hpp" + +#include "indexer/classificator_loader.hpp" +#include "indexer/map_style_reader.hpp" +#include "indexer/map_style.hpp" + +#include "base/macros.hpp" + +#include "defines.hpp" + +#include "std/string_view.hpp" + +#include +#include +#include +#include + +using namespace generator; +using namespace generator::cache; +using namespace feature; +using namespace platform::tests_support; +using namespace platform; +using namespace routing; +using namespace std; + +namespace +{ +string const kSpeedCameraTag = ""; + +class TranslatorForTest : public Translator +{ +public: + explicit TranslatorForTest(std::shared_ptr emitter, cache::IntermediateDataReader & cache, + feature::GenerateInfo const &) + : Translator(emitter, cache, std::make_shared(cache)) {} +}; +} // namespace + +namespace generator_tests +{ +class TestCameraCollector +{ +public: + // Directory name for creating test mwm and temprary files. + std::string static const kTestDir; + std::string static const kOsmFileName; + + TestCameraCollector() + { + GetStyleReader().SetCurrentStyle(MapStyleMerged); + classificator::Load(); + } + + bool Test(string const & osmSourceXML, set> & trueAnswers) + { + Platform & platform = GetPlatform(); + WritableDirChanger writableDirChanger(kTestDir); + auto const & writableDir = platform.WritableDir(); + ScopedDir const scopedDir(kTestDir); + auto const osmRelativePath = base::JoinPath(kTestDir, kOsmFileName); + ScopedFile const osmScopedFile(osmRelativePath, osmSourceXML); + + GenerateInfo genInfo; + // Generate intermediate data. + genInfo.m_intermediateDir = writableDir; + genInfo.m_nodeStorageType = feature::GenerateInfo::NodeStorageType::Index; + genInfo.m_osmFileName = base::JoinPath(writableDir, osmRelativePath); + genInfo.m_osmFileType = feature::GenerateInfo::OsmSourceType::XML; + + // Test save intermediate data is OK. + CHECK(GenerateIntermediateData(genInfo), ()); + + // Test load this data from cached file. + auto collector = std::make_shared(genInfo.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME)); + CacheLoader cacheLoader(genInfo); + auto emitter = CreateEmitter(EmitterType::Noop); + TranslatorForTest translator(emitter, cacheLoader.GetCache(), genInfo); + translator.AddCollector(collector); + CHECK(GenerateRaw(genInfo, translator), ()); + + set> answers; + collector->m_processor.ForEachCamera([&](auto const & camera, auto const & ways) { + for (auto const & w : ways) + answers.emplace(camera.m_id, w); + }); + + return answers == trueAnswers; + } +}; + +std::string const TestCameraCollector::kTestDir = "camera_test"; +std::string const TestCameraCollector::kOsmFileName = "planet" OSM_DATA_FILE_EXTENSION; +} // namespace generator_tests + +using namespace generator_tests; + +UNIT_CLASS_TEST(TestCameraCollector, test_1) +{ + string const osmSourceXML = R"( + + + )" + kSpeedCameraTag + R"( + )" + kSpeedCameraTag + R"( + )" + kSpeedCameraTag + R"( + + + + + + + + + + + + + + + +)"; + + set> trueAnswers = { + {1, 10}, {1, 20}, {2, 20}, {3, 20} + }; + + TEST(TestCameraCollector::Test(osmSourceXML, trueAnswers), ()); +} + +UNIT_CLASS_TEST(TestCameraCollector, test_2) +{ + string const osmSourceXML = R"( + + + )" + kSpeedCameraTag + R"( + )" + kSpeedCameraTag + R"( + )" + kSpeedCameraTag + R"( + )" + kSpeedCameraTag + R"( + )" + kSpeedCameraTag + R"( + + + + + + + + + + + + + + + + + + + + +)"; + + set> trueAnswers = { + {1, 10}, {2, 10}, {1, 20}, {3, 20}, {1, 30}, {3, 30}, {4, 30}, {5, 30} + }; + + TEST(TestCameraCollector::Test(osmSourceXML, trueAnswers), ()); +} + +UNIT_CLASS_TEST(TestCameraCollector, test_3) +{ + string const osmSourceXML = R"( + + + )" + kSpeedCameraTag + R"( + + + + + + + + + + + + + + +)"; + + set> trueAnswers = { + {1, 10}, {1, 20} + }; + + TEST(TestCameraCollector::Test(osmSourceXML, trueAnswers), ()); +} + +UNIT_CLASS_TEST(TestCameraCollector, test_4) +{ + string const osmSourceXML = R"( + + + )" + kSpeedCameraTag + R"( + + + + + + + + + +)"; + + set> trueAnswers = {}; + + TEST(TestCameraCollector::Test(osmSourceXML, trueAnswers), ()); +} + +UNIT_CLASS_TEST(TestCameraCollector, test_5) +{ + string const osmSourceXML = R"( + + + + + + + + + + +)"; + + set> trueAnswers = {}; + + TEST(TestCameraCollector::Test(osmSourceXML, trueAnswers), ()); +} diff --git a/generator/generator_tests/intermediate_data_test.cpp b/generator/generator_tests/intermediate_data_test.cpp index bf1ad0264a..c906b79b58 100644 --- a/generator/generator_tests/intermediate_data_test.cpp +++ b/generator/generator_tests/intermediate_data_test.cpp @@ -8,105 +8,23 @@ #include "testing/testing.hpp" -#include "platform/platform.hpp" -#include "platform/platform_tests_support/scoped_dir.hpp" -#include "platform/platform_tests_support/scoped_file.hpp" -#include "platform/platform_tests_support/writable_dir_changer.hpp" - -#include "generator/camera_node_processor.hpp" -#include "generator/emitter_factory.hpp" -#include "generator/feature_maker.hpp" #include "generator/generate_info.hpp" #include "generator/intermediate_data.hpp" #include "generator/intermediate_elements.hpp" -#include "generator/osm_source.hpp" -#include "generator/translator.hpp" -#include "base/control_flow.hpp" -#include "base/macros.hpp" +#include "coding/reader.hpp" +#include "coding/writer.hpp" #include "defines.hpp" #include -#include #include #include +#include using namespace generator; -using namespace cache; // after generator, because it is generator::cache -using namespace feature; -using namespace platform::tests_support; -using namespace platform; -using namespace routing; using namespace std; -namespace -{ -string const kSpeedCameraTag = ""; -string const kTestDir = "camera_generation_test"; - -class TranslatorForTest : public Translator -{ -public: - explicit TranslatorForTest(std::shared_ptr emitter, cache::IntermediateDataReader & holder, - feature::GenerateInfo const &) - : Translator(emitter, holder, std::make_shared(holder)) {} -}; -} // namespace - -namespace generator_tests -{ -class TestCameraNodeProcessor -{ -public: - bool Test(string const & osmSourceXML, set> & trueAnswers) - { - // Directory name for creating test mwm and temporary files. - static string const kTestDir = "camera_nodes_to_ways_test"; - static string const kOsmFileName = "town" OSM_DATA_FILE_EXTENSION; - - Platform & platform = GetPlatform(); - - WritableDirChanger writableDirChanger(kTestDir); - - string const & writableDir = platform.WritableDir(); - - ScopedDir const scopedDir(kTestDir); - - string const osmRelativePath = base::JoinPath(kTestDir, kOsmFileName); - ScopedFile const osmScopedFile(osmRelativePath, osmSourceXML); - - // Generate intermediate data. - GenerateInfo genInfo; - genInfo.m_intermediateDir = writableDir; - genInfo.m_nodeStorageType = feature::GenerateInfo::NodeStorageType::Index; - genInfo.m_osmFileName = base::JoinPath(writableDir, osmRelativePath); - genInfo.m_osmFileType = feature::GenerateInfo::OsmSourceType::XML; - - // Test save intermediate data is OK. - CHECK(GenerateIntermediateData(genInfo), ()); - - // Test load this data from cached file. - auto collector = std::make_shared(genInfo.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME)); - CacheLoader cacheLoader(genInfo); - auto emitter = CreateEmitter(EmitterType::Noop); - TranslatorForTest translator(emitter, cacheLoader.GetCache(), genInfo); - translator.AddCollector(collector); - CHECK(GenerateRaw(genInfo, translator), ()); - - set> answers; - collector->m_processor.ForEachCamera([&] (auto const & camera, auto const & ways) { - for (auto const & w : ways) - answers.emplace(camera.m_id, w); - }); - - return answers == trueAnswers; - } -}; -} // namespace generator_tests - -using namespace generator_tests; - UNIT_TEST(Intermediate_Data_empty_way_element_save_load_test) { WayElement e1(1 /* fake osm id */); @@ -197,145 +115,3 @@ UNIT_TEST(Intermediate_Data_relation_element_save_load_test) TEST_NOT_EQUAL(e2.tags["key1old"], "value1old", ()); TEST_NOT_EQUAL(e2.tags["key2old"], "value2old", ()); } - -UNIT_CLASS_TEST(TestCameraNodeProcessor, CameraNodesToWays_test_1) -{ - string const osmSourceXML = R"( - - - )" + kSpeedCameraTag + R"( - )" + kSpeedCameraTag + R"( - )" + kSpeedCameraTag + R"( - - - - - - - - - - - - - - - -)"; - - set> trueAnswers = { - {1, 10}, {1, 20}, {2, 20}, {3, 20} - }; - - TEST(TestCameraNodeProcessor::Test(osmSourceXML, trueAnswers), ()); -} - -UNIT_CLASS_TEST(TestCameraNodeProcessor, CameraNodesToWays_test_2) -{ - string const osmSourceXML = R"( - - - )" + kSpeedCameraTag + R"( - )" + kSpeedCameraTag + R"( - )" + kSpeedCameraTag + R"( - )" + kSpeedCameraTag + R"( - )" + kSpeedCameraTag + R"( - - - - - - - - - - - - - - - - - - - - -)"; - - set> trueAnswers = { - {1, 10}, {2, 10}, {1, 20}, {3, 20}, {1, 30}, {3, 30}, {4, 30}, {5, 30} - }; - - TEST(TestCameraNodeProcessor::Test(osmSourceXML, trueAnswers), ()); -} - -UNIT_CLASS_TEST(TestCameraNodeProcessor, CameraNodesToWays_test_3) -{ - string const osmSourceXML = R"( - - - )" + kSpeedCameraTag + R"( - - - - - - - - - - - - - - -)"; - - set> trueAnswers = { - {1, 10}, {1, 20} - }; - - TEST(TestCameraNodeProcessor::Test(osmSourceXML, trueAnswers), ()); -} - -UNIT_CLASS_TEST(TestCameraNodeProcessor, CameraNodesToWays_test_4) -{ - string const osmSourceXML = R"( - - - )" + kSpeedCameraTag + R"( - - - - - - - - - -)"; - - set> trueAnswers = {}; - - TEST(TestCameraNodeProcessor::Test(osmSourceXML, trueAnswers), ()); -} - -UNIT_CLASS_TEST(TestCameraNodeProcessor, CameraNodesToWays_test_5) -{ - string const osmSourceXML = R"( - - - - - - - - - - -)"; - - set> trueAnswers = {}; - - TEST(TestCameraNodeProcessor::Test(osmSourceXML, trueAnswers), ()); -} diff --git a/generator/holes.cpp b/generator/holes.cpp index 4240221036..9f4abdbd74 100644 --- a/generator/holes.cpp +++ b/generator/holes.cpp @@ -7,8 +7,8 @@ namespace generator { -HolesAccumulator::HolesAccumulator(cache::IntermediateDataReader & holder) : - m_merger(holder) +HolesAccumulator::HolesAccumulator(cache::IntermediateDataReader & cache) : + m_merger(cache) { } @@ -23,9 +23,9 @@ FeatureBuilder1::Geometry & HolesAccumulator::GetHoles() return m_holes; } -HolesProcessor::HolesProcessor(uint64_t id, cache::IntermediateDataReader & holder) : +HolesProcessor::HolesProcessor(uint64_t id, cache::IntermediateDataReader & cache) : m_id(id), - m_holes(holder) + m_holes(cache) { } @@ -51,9 +51,9 @@ void HolesProcessor::operator() (uint64_t id, std::string const & role) m_holes(id); } -HolesRelation::HolesRelation(cache::IntermediateDataReader & holder) : - m_holes(holder), - m_outer(holder) +HolesRelation::HolesRelation(cache::IntermediateDataReader & cache) : + m_holes(cache), + m_outer(cache) { } diff --git a/generator/holes.hpp b/generator/holes.hpp index 8a3dff6932..e8a4cb997c 100644 --- a/generator/holes.hpp +++ b/generator/holes.hpp @@ -19,7 +19,7 @@ class IntermediateDataReader; class HolesAccumulator { public: - explicit HolesAccumulator(cache::IntermediateDataReader & holder); + explicit HolesAccumulator(cache::IntermediateDataReader & cache); void operator() (uint64_t id) { m_merger.AddWay(id); } FeatureBuilder1::Geometry & GetHoles(); @@ -33,7 +33,7 @@ private: class HolesProcessor { public: - explicit HolesProcessor(uint64_t id, cache::IntermediateDataReader & holder); + explicit HolesProcessor(uint64_t id, cache::IntermediateDataReader & cache); /// 1. relations process function base::ControlFlow operator() (uint64_t /* id */, RelationElement const & e); @@ -49,7 +49,7 @@ private: class HolesRelation { public: - explicit HolesRelation(cache::IntermediateDataReader & holder); + explicit HolesRelation(cache::IntermediateDataReader & cache); void Build(OsmElement const * p); FeatureBuilder1::Geometry & GetHoles() { return m_holes.GetHoles(); } diff --git a/generator/osm_source.cpp b/generator/osm_source.cpp index 8edba3caba..4d4d0d8fc2 100644 --- a/generator/osm_source.cpp +++ b/generator/osm_source.cpp @@ -111,26 +111,26 @@ void AddElementToCache(cache::IntermediateDataWriter & cache, OsmElement & em) void BuildIntermediateDataFromXML(SourceReader & stream, cache::IntermediateDataWriter & cache, TownsDumper & towns) { - XMLSource parser([&](OsmElement * e) + XMLSource parser([&](OsmElement * element) { - towns.CheckElement(*e); - AddElementToCache(cache, *e); + towns.CheckElement(*element); + AddElementToCache(cache, *element); }); ParseXMLSequence(stream, parser); } void ProcessOsmElementsFromXML(SourceReader & stream, function processor) { - XMLSource parser([&](OsmElement * e) { processor(e); }); + XMLSource parser([&](OsmElement * element) { processor(element); }); ParseXMLSequence(stream, parser); } void BuildIntermediateDataFromO5M(SourceReader & stream, cache::IntermediateDataWriter & cache, TownsDumper & towns) { - auto processor = [&](OsmElement * e) { - towns.CheckElement(*e); - AddElementToCache(cache, *e); + auto processor = [&](OsmElement * element) { + towns.CheckElement(*element); + AddElementToCache(cache, *element); }; // Use only this function here, look into ProcessOsmElementsFromO5M @@ -207,10 +207,9 @@ void ProcessOsmElementsFromO5M(SourceReader & stream, function diff --git a/generator/translator.cpp b/generator/translator.cpp index 69f1c8b1a5..1d52c48446 100644 --- a/generator/translator.cpp +++ b/generator/translator.cpp @@ -9,22 +9,22 @@ namespace generator { -Translator::Translator(std::shared_ptr emitter, cache::IntermediateDataReader & holder, +Translator::Translator(std::shared_ptr emitter, cache::IntermediateDataReader & cache, std::shared_ptr maker, FilterCollection const & filters, CollectorCollection const & collectors) : m_filters(filters) , m_collectors(collectors) - , m_tagsEnricher(holder) + , m_tagsEnricher(cache) , m_featureMaker(maker) , m_emitter(emitter) - , m_holder(holder) + , m_cache(cache) { CHECK(m_emitter, ()); } -Translator::Translator(std::shared_ptr emitter, cache::IntermediateDataReader & holder, +Translator::Translator(std::shared_ptr emitter, cache::IntermediateDataReader & cache, std::shared_ptr maker) - : Translator(emitter, holder, maker, {} /* filters */, {} /* collectors */) {} + : Translator(emitter, cache, maker, {} /* filters */, {} /* collectors */) {} void Translator::Emit(OsmElement & element) { diff --git a/generator/translator.hpp b/generator/translator.hpp index 0f1c8c4424..9cfbfe1fa5 100644 --- a/generator/translator.hpp +++ b/generator/translator.hpp @@ -28,10 +28,10 @@ class IntermediateDataReader; class Translator : public TranslatorInterface { public: - explicit Translator(std::shared_ptr emitter, cache::IntermediateDataReader & holder, + explicit Translator(std::shared_ptr emitter, cache::IntermediateDataReader & cache, std::shared_ptr maker, FilterCollection const & filters, CollectorCollection const & collectors); - explicit Translator(std::shared_ptr emitter, cache::IntermediateDataReader & holder, + explicit Translator(std::shared_ptr emitter, cache::IntermediateDataReader & cache, std::shared_ptr maker); // TranslatorInterface overrides: @@ -51,6 +51,6 @@ protected: RelationTagsEnricher m_tagsEnricher; std::shared_ptr m_featureMaker; std::shared_ptr m_emitter; - cache::IntermediateDataReader & m_holder; + cache::IntermediateDataReader & m_cache; }; } // namespace generator diff --git a/generator/translator_coastline.cpp b/generator/translator_coastline.cpp index 75dfe6454b..8ac96e2fa6 100644 --- a/generator/translator_coastline.cpp +++ b/generator/translator_coastline.cpp @@ -30,8 +30,8 @@ public: } // namespace TranslatorCoastline::TranslatorCoastline(std::shared_ptr emitter, - cache::IntermediateDataReader & holder) - : Translator(emitter, holder, std::make_shared(holder)) + cache::IntermediateDataReader & cache) + : Translator(emitter, cache, std::make_shared(cache)) { AddFilter(std::make_shared()); AddFilter(std::make_shared()); diff --git a/generator/translator_coastline.hpp b/generator/translator_coastline.hpp index 7b920ed13f..d4467320e9 100644 --- a/generator/translator_coastline.hpp +++ b/generator/translator_coastline.hpp @@ -22,6 +22,6 @@ class TranslatorCoastline : public Translator { public: explicit TranslatorCoastline(std::shared_ptr emitter, - cache::IntermediateDataReader & holder); + cache::IntermediateDataReader & cache); }; } // namespace generator diff --git a/generator/translator_country.cpp b/generator/translator_country.cpp index 69ae5bfdee..a4d95eaaba 100644 --- a/generator/translator_country.cpp +++ b/generator/translator_country.cpp @@ -1,7 +1,7 @@ #include "generator/translator_country.hpp" -#include "generator/camera_node_processor.hpp" #include "generator/collector_addresses.hpp" +#include "generator/collector_camera.hpp" #include "generator/collector_interface.hpp" #include "generator/collector_tag.hpp" #include "generator/feature_maker.hpp" @@ -69,9 +69,9 @@ bool WikiDataValidator(std::string const & tagValue) } } // namespace -TranslatorCountry::TranslatorCountry(std::shared_ptr emitter, cache::IntermediateDataReader & holder, +TranslatorCountry::TranslatorCountry(std::shared_ptr emitter, cache::IntermediateDataReader & cache, feature::GenerateInfo const & info) - : Translator(emitter, holder, std::make_shared(holder)) + : Translator(emitter, cache, std::make_shared(cache)) , m_tagAdmixer(info.GetIntermediateFileName("ways", ".csv"), info.GetIntermediateFileName("towns", ".csv")) , m_tagReplacer(base::JoinPath(GetPlatform().ResourcesDir(), REPLACED_TAGS_FILE)) , m_osmTagMixer(base::JoinPath(GetPlatform().ResourcesDir(), MIXED_TAGS_FILE)) @@ -87,7 +87,7 @@ TranslatorCountry::TranslatorCountry(std::shared_ptr emitter, AddCollector(std::make_shared(info.GetIntermediateFileName(MAXSPEEDS_FILENAME))); AddCollector(std::make_shared(info.GetIntermediateFileName(RESTRICTIONS_FILENAME))); AddCollector(std::make_shared(info.GetIntermediateFileName(ROAD_ACCESS_FILENAME))); - AddCollector(std::make_shared(info.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME))); + AddCollector(std::make_shared(info.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME))); if (info.m_genAddresses) AddCollector(std::make_shared(info.GetAddressesFileName())); @@ -106,8 +106,8 @@ void TranslatorCountry::CollectFromRelations(OsmElement const & element) { RelationCollector collector(m_collectors); if (element.IsNode()) - m_holder.ForEachRelationByNodeCached(element.id, collector); + m_cache.ForEachRelationByNodeCached(element.id, collector); else if (element.IsWay()) - m_holder.ForEachRelationByWayCached(element.id, collector); + m_cache.ForEachRelationByWayCached(element.id, collector); } } // namespace generator diff --git a/generator/translator_country.hpp b/generator/translator_country.hpp index 1ad9bd4c08..712f958be1 100644 --- a/generator/translator_country.hpp +++ b/generator/translator_country.hpp @@ -22,7 +22,7 @@ namespace generator class TranslatorCountry : public Translator { public: - explicit TranslatorCountry(std::shared_ptr emitter, cache::IntermediateDataReader & holder, + explicit TranslatorCountry(std::shared_ptr emitter, cache::IntermediateDataReader & cache, feature::GenerateInfo const & info); // TranslatorInterface overrides: diff --git a/generator/translator_geo_objects.cpp b/generator/translator_geo_objects.cpp index 92c253deeb..b7325c32a4 100644 --- a/generator/translator_geo_objects.cpp +++ b/generator/translator_geo_objects.cpp @@ -27,8 +27,8 @@ public: } // namespace TranslatorGeoObjects::TranslatorGeoObjects(std::shared_ptr emitter, - cache::IntermediateDataReader & holder) - : Translator(emitter, holder, std::make_shared(holder)) + cache::IntermediateDataReader & cache) + : Translator(emitter, cache, std::make_shared(cache)) { AddFilter(std::make_shared()); diff --git a/generator/translator_geo_objects.hpp b/generator/translator_geo_objects.hpp index 31a2d89b21..fb40cbad9e 100644 --- a/generator/translator_geo_objects.hpp +++ b/generator/translator_geo_objects.hpp @@ -18,6 +18,6 @@ class TranslatorGeoObjects : public Translator { public: explicit TranslatorGeoObjects(std::shared_ptr emitter, - cache::IntermediateDataReader & holder); + cache::IntermediateDataReader & cache); }; } // namespace generator diff --git a/generator/translator_interface.hpp b/generator/translator_interface.hpp index 52e057a8c4..8a62906b15 100644 --- a/generator/translator_interface.hpp +++ b/generator/translator_interface.hpp @@ -13,7 +13,7 @@ class TranslatorInterface public: virtual ~TranslatorInterface() = default; - virtual void Preprocess(OsmElement & element) {} + virtual void Preprocess(OsmElement &) {} virtual void Emit(OsmElement & element) = 0; virtual bool Finish() = 0; virtual void GetNames(std::vector & names) const = 0; diff --git a/generator/translator_region.cpp b/generator/translator_region.cpp index aabe07205c..8a0222146d 100644 --- a/generator/translator_region.cpp +++ b/generator/translator_region.cpp @@ -41,9 +41,9 @@ public: }; } // namespace -TranslatorRegion::TranslatorRegion(std::shared_ptr emitter, cache::IntermediateDataReader & holder, +TranslatorRegion::TranslatorRegion(std::shared_ptr emitter, cache::IntermediateDataReader & cache, feature::GenerateInfo const & info) - : Translator(emitter, holder, std::make_shared(holder)) + : Translator(emitter, cache, std::make_shared(cache)) { AddFilter(std::make_shared()); diff --git a/generator/translator_region.hpp b/generator/translator_region.hpp index 18f2f61c0f..bb6b502482 100644 --- a/generator/translator_region.hpp +++ b/generator/translator_region.hpp @@ -21,7 +21,7 @@ namespace generator class TranslatorRegion : public Translator { public: - explicit TranslatorRegion(std::shared_ptr emitter, cache::IntermediateDataReader & holder, + explicit TranslatorRegion(std::shared_ptr emitter, cache::IntermediateDataReader & cache, feature::GenerateInfo const & info); }; } // namespace generator diff --git a/generator/translator_world.cpp b/generator/translator_world.cpp index 1dcde63119..a737db9d9a 100644 --- a/generator/translator_world.cpp +++ b/generator/translator_world.cpp @@ -14,9 +14,9 @@ namespace generator { -TranslatorWorld::TranslatorWorld(std::shared_ptr emitter, cache::IntermediateDataReader & holder, +TranslatorWorld::TranslatorWorld(std::shared_ptr emitter, cache::IntermediateDataReader & cache, feature::GenerateInfo const & info) - : Translator(emitter, holder, std::make_shared(holder)) + : Translator(emitter, cache, std::make_shared(cache)) , m_tagAdmixer(info.GetIntermediateFileName("ways", ".csv"), info.GetIntermediateFileName("towns", ".csv")) , m_tagReplacer(GetPlatform().ResourcesDir() + REPLACED_TAGS_FILE) , m_osmTagMixer(GetPlatform().ResourcesDir() + MIXED_TAGS_FILE) diff --git a/generator/translator_world.hpp b/generator/translator_world.hpp index ba0f6fdc60..d0d0512df1 100644 --- a/generator/translator_world.hpp +++ b/generator/translator_world.hpp @@ -22,7 +22,7 @@ namespace generator class TranslatorWorld : public Translator { public: - explicit TranslatorWorld(std::shared_ptr emitter, cache::IntermediateDataReader & holder, + explicit TranslatorWorld(std::shared_ptr emitter, cache::IntermediateDataReader & cache, feature::GenerateInfo const & info); // TranslatorInterface overrides: diff --git a/generator/ways_merger.cpp b/generator/ways_merger.cpp index e00e09f628..d19f67ebf4 100644 --- a/generator/ways_merger.cpp +++ b/generator/ways_merger.cpp @@ -2,15 +2,15 @@ namespace generator { -AreaWayMerger::AreaWayMerger(cache::IntermediateDataReader & holder) : - m_holder(holder) +AreaWayMerger::AreaWayMerger(cache::IntermediateDataReader & cache) : + m_cache(cache) { } void AreaWayMerger::AddWay(uint64_t id) { auto e = std::make_shared(id); - if (m_holder.GetWay(id, *e) && e->IsValid()) + if (m_cache.GetWay(id, *e) && e->IsValid()) { m_map.emplace(e->nodes.front(), e); m_map.emplace(e->nodes.back(), e); diff --git a/generator/ways_merger.hpp b/generator/ways_merger.hpp index 629c3c5154..49ee3d834e 100644 --- a/generator/ways_merger.hpp +++ b/generator/ways_merger.hpp @@ -20,7 +20,7 @@ class AreaWayMerger using WayMapIterator = WayMap::iterator; public: - explicit AreaWayMerger(cache::IntermediateDataReader & holder); + explicit AreaWayMerger(cache::IntermediateDataReader & cache); void AddWay(uint64_t id); @@ -46,7 +46,7 @@ public: e->ForEachPointOrdered(id, [this, &points](uint64_t id) { m2::PointD pt; - if (m_holder.GetNode(id, pt.y, pt.x)) + if (m_cache.GetNode(id, pt.y, pt.x)) points.push_back(pt); }); @@ -76,7 +76,7 @@ public: } private: - cache::IntermediateDataReader & m_holder; + cache::IntermediateDataReader & m_cache; WayMap m_map; }; } // namespace generator