From e91592ac74ca37e2a5c856016b7c74166fa3d987 Mon Sep 17 00:00:00 2001 From: Maksim Andrianov Date: Tue, 20 Aug 2019 13:32:18 +0300 Subject: [PATCH] Review fixes --- generator/CMakeLists.txt | 42 +++++----- .../booking_quality_check.cpp | 7 +- generator/coastlines_generator.cpp | 11 +-- generator/coastlines_generator.hpp | 5 +- generator/feature_maker_base.cpp | 3 + generator/feature_maker_base.hpp | 1 + generator/feature_merger.cpp | 22 ++--- generator/feature_merger.hpp | 14 ++-- generator/feature_processing_layers.cpp | 80 +++++-------------- generator/feature_processing_layers.hpp | 73 +++++------------ generator/features_processing_helpers.hpp | 2 +- .../features_tests.cpp | 33 ++++---- .../camera_collector_tests.cpp | 29 ++++--- .../collector_city_area_tests.cpp | 14 ++-- generator/generator_tests/common.cpp | 11 +-- .../generator_tests/feature_builder_test.cpp | 2 +- generator/generator_tests/maxspeeds_tests.cpp | 4 +- .../merge_collectors_tests.cpp | 4 +- generator/generator_tests/metalines_tests.cpp | 9 ++- .../region_info_collector_tests.cpp | 2 +- .../restriction_collector_test.cpp | 3 +- .../generator_tests/road_access_test.cpp | 2 +- .../generator_tests/speed_cameras_test.cpp | 4 +- generator/generator_tool/generator_tool.cpp | 39 +++++---- generator/metalines_builder.cpp | 13 ++- generator/processor_coastline.cpp | 11 ++- generator/processor_coastline.hpp | 2 +- generator/processor_country.cpp | 11 ++- generator/processor_country.hpp | 2 +- generator/processor_simple.cpp | 14 ++-- generator/processor_simple.hpp | 2 +- generator/processor_world.cpp | 11 ++- generator/processor_world.hpp | 2 +- generator/tag_admixer.hpp | 25 +++--- generator/translator.hpp | 6 ++ generator/translator_coastline.cpp | 5 +- generator/translator_coastline.hpp | 3 +- generator/translator_collection.cpp | 8 +- generator/translator_country.cpp | 3 +- generator/translator_geo_objects.cpp | 3 +- generator/translator_region.cpp | 3 +- generator/translator_streets.cpp | 3 +- generator/translator_world.cpp | 4 +- generator/ways_merger.cpp | 2 +- 44 files changed, 231 insertions(+), 318 deletions(-) diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index 3dba6cc291..1a48ee444c 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -38,10 +38,10 @@ set( collection_base.hpp collector_addresses.cpp collector_addresses.hpp - collector_city_area.cpp - collector_city_area.hpp collector_camera.cpp collector_camera.hpp + collector_city_area.cpp + collector_city_area.hpp collector_collection.cpp collector_collection.hpp collector_interface.hpp @@ -53,18 +53,6 @@ set( descriptions_section_builder.hpp dumper.cpp dumper.hpp - processor_booking.hpp - processor_coastline.cpp - processor_coastline.hpp - processor_country.cpp - processor_country.hpp - processor_factory.hpp - processor_interface.hpp - processor_noop.hpp - processor_simple.cpp - processor_simple.hpp - processor_world.cpp - processor_world.hpp factory_utils.hpp feature_builder.cpp feature_builder.hpp @@ -97,14 +85,14 @@ set( final_processor_intermediate_mwm.hpp gen_mwm_info.hpp generate_info.hpp - geo_objects/geo_objects_generator.cpp - geo_objects/geo_objects_generator.hpp - geo_objects/geo_objects_maintainer.cpp - geo_objects/geo_objects_maintainer.hpp geo_objects/geo_objects.cpp geo_objects/geo_objects.hpp geo_objects/geo_objects_filter.cpp geo_objects/geo_objects_filter.hpp + geo_objects/geo_objects_generator.cpp + geo_objects/geo_objects_generator.hpp + geo_objects/geo_objects_maintainer.cpp + geo_objects/geo_objects_maintainer.hpp geometry_holder.hpp holes.cpp holes.hpp @@ -141,15 +129,27 @@ set( osm_xml_source.hpp place.cpp place.hpp + place_node.hpp place_processor.cpp place_processor.hpp - place_node.hpp platform_helpers.cpp platform_helpers.hpp popular_places_section_builder.cpp popular_places_section_builder.hpp popularity.cpp popularity.hpp + processor_booking.hpp + processor_coastline.cpp + processor_coastline.hpp + processor_country.cpp + processor_country.hpp + processor_factory.hpp + processor_interface.hpp + processor_noop.hpp + processor_simple.cpp + processor_simple.hpp + processor_world.cpp + processor_world.hpp promo_catalog_cities.hpp ratings_section_builder.cpp ratings_section_builder.hpp @@ -230,12 +230,12 @@ set( tesselator.hpp towns_dumper.cpp towns_dumper.hpp - translation.hpp - translation.cpp traffic_generator.cpp traffic_generator.hpp transit_generator.cpp transit_generator.hpp + translation.cpp + translation.hpp translator.cpp translator.hpp translator_coastline.cpp diff --git a/generator/booking_quality_check/booking_quality_check.cpp b/generator/booking_quality_check/booking_quality_check.cpp index 9e7610443b..a2f440ad20 100644 --- a/generator/booking_quality_check/booking_quality_check.cpp +++ b/generator/booking_quality_check/booking_quality_check.cpp @@ -1,9 +1,10 @@ #include "generator/booking_dataset.hpp" -#include "generator/processor_booking.hpp" + #include "generator/feature_builder.hpp" -#include "generator/raw_generator.hpp" #include "generator/opentable_dataset.hpp" #include "generator/osm_source.hpp" +#include "generator/processor_booking.hpp" +#include "generator/raw_generator.hpp" #include "generator/sponsored_scoring.hpp" #include "generator/translator_collection.hpp" #include "generator/translator_factory.hpp" @@ -330,7 +331,7 @@ void RunImpl(GenerateInfo & info) LOG_SHORT(LINFO, ("OSM data:", FLAGS_osm)); generator::cache::IntermediateData cacheLoader(info); - auto translators = std::make_shared(); + auto translators = make_shared(); auto processor = make_shared>(dataset, features); translators->Append(CreateTranslator(TranslatorType::Country, processor, cacheLoader.GetCache(), info)); RawGenerator generator(info); diff --git a/generator/coastlines_generator.cpp b/generator/coastlines_generator.cpp index 3d7f16c28f..90d5f4a793 100644 --- a/generator/coastlines_generator.cpp +++ b/generator/coastlines_generator.cpp @@ -2,6 +2,8 @@ #include "generator/feature_builder.hpp" +#include "indexer/ftypes_matcher.hpp" + #include "coding/point_coding.hpp" #include "geometry/region2d/binary_operators.hpp" @@ -21,10 +23,8 @@ using RegionT = m2::RegionI; using PointT = m2::PointI; using RectT = m2::RectI; -CoastlineFeaturesGenerator::CoastlineFeaturesGenerator(uint32_t coastType) - : m_merger(kPointCoordBits), m_coastType(coastType) -{ -} +CoastlineFeaturesGenerator::CoastlineFeaturesGenerator() + : m_merger(kPointCoordBits) {} namespace { @@ -333,7 +333,8 @@ void CoastlineFeaturesGenerator::GetFeatures(vector & features) cellData.AssignGeometry(fb); fb.SetArea(); - fb.AddType(m_coastType); + static auto const kCoastType = ftypes::IsCoastlineChecker::Instance().GetCoastlineType(); + fb.AddType(kCoastType); // Should represent non-empty geometry CHECK_GREATER(fb.GetPolygonsCount(), 0, ()); diff --git a/generator/coastlines_generator.hpp b/generator/coastlines_generator.hpp index 249cf7622d..e7f633a0c6 100644 --- a/generator/coastlines_generator.hpp +++ b/generator/coastlines_generator.hpp @@ -3,7 +3,6 @@ #include "generator/feature_merger.hpp" #include "indexer/cell_id.hpp" -#include "indexer/ftypes_matcher.hpp" #include "geometry/tree4d.hpp" #include "geometry/region2d.hpp" @@ -22,10 +21,8 @@ class CoastlineFeaturesGenerator using TTree = m4::Tree; TTree m_tree; - uint32_t m_coastType; - public: - CoastlineFeaturesGenerator(uint32_t coastType = ftypes::IsCoastlineChecker::Instance().GetCoastlineType()); + CoastlineFeaturesGenerator(); void AddRegionToTree(feature::FeatureBuilder const & fb); diff --git a/generator/feature_maker_base.cpp b/generator/feature_maker_base.cpp index 16daa78bdc..a5a491b8c0 100644 --- a/generator/feature_maker_base.cpp +++ b/generator/feature_maker_base.cpp @@ -65,6 +65,9 @@ void TransformAreaToPoint(FeatureBuilder & feature) feature.ResetGeometry(); feature.SetOsmId(id); feature.SetCenter(center); + auto & params = feature.GetParams(); + if (!params.house.IsEmpty()) + params.SetGeomTypePointEx(); } void TransformAreaToLine(FeatureBuilder & feature) diff --git a/generator/feature_maker_base.hpp b/generator/feature_maker_base.hpp index 8027a68088..7b049e32ee 100644 --- a/generator/feature_maker_base.hpp +++ b/generator/feature_maker_base.hpp @@ -26,6 +26,7 @@ public: void SetCache(std::shared_ptr const & cache); + // Reference on element is non const because ftype::GetNameAndType will be call. virtual bool Add(OsmElement & element); // The function returns true when the receiving feature was successful and a false when not successful. bool GetNextFeature(feature::FeatureBuilder & feature); diff --git a/generator/feature_merger.cpp b/generator/feature_merger.cpp index 52ca3f40b1..000b94a261 100644 --- a/generator/feature_merger.cpp +++ b/generator/feature_merger.cpp @@ -122,7 +122,7 @@ double MergedFeatureBuilder::GetPriority() const } -FeatureMergeProcessor::key_t FeatureMergeProcessor::get_key(m2::PointD const & p) +FeatureMergeProcessor::Key FeatureMergeProcessor::GetKey(m2::PointD const & p) { return PointToInt64Obsolete(p, m_coordBits); } @@ -139,8 +139,8 @@ void FeatureMergeProcessor::operator() (FeatureBuilder const & fb) void FeatureMergeProcessor::operator() (MergedFeatureBuilder * p) { - key_t const k1 = get_key(p->FirstPoint()); - key_t const k2 = get_key(p->LastPoint()); + Key const k1 = GetKey(p->FirstPoint()); + Key const k2 = GetKey(p->LastPoint()); m_map[k1].push_back(p); if (k1 != k2) @@ -156,15 +156,15 @@ void FeatureMergeProcessor::operator() (MergedFeatureBuilder * p) void FeatureMergeProcessor::Insert(m2::PointD const & pt, MergedFeatureBuilder * p) { - m_map[get_key(pt)].push_back(p); + m_map[GetKey(pt)].push_back(p); } -void FeatureMergeProcessor::Remove(key_t key, MergedFeatureBuilder const * p) +void FeatureMergeProcessor::Remove(Key key, MergedFeatureBuilder const * p) { - map_t::iterator i = m_map.find(key); + auto i = m_map.find(key); if (i != m_map.end()) { - vector_t & v = i->second; + MergedFeatureBuilders & v = i->second; v.erase(remove(v.begin(), v.end(), p), v.end()); if (v.empty()) m_map.erase(i); } @@ -172,8 +172,8 @@ void FeatureMergeProcessor::Remove(key_t key, MergedFeatureBuilder const * p) void FeatureMergeProcessor::Remove(MergedFeatureBuilder const * p) { - key_t const k1 = get_key(p->FirstPoint()); - key_t const k2 = get_key(p->LastPoint()); + Key const k1 = GetKey(p->FirstPoint()); + Key const k2 = GetKey(p->LastPoint()); Remove(k1, p); if (k1 != k2) @@ -191,7 +191,7 @@ void FeatureMergeProcessor::DoMerge(FeatureEmitterIFace & emitter) while (!m_map.empty()) { // Get any starting feature. - vector_t & vS = m_map.begin()->second; + MergedFeatureBuilders & vS = m_map.begin()->second; CHECK(!vS.empty(), ()); MergedFeatureBuilder * p = vS.front(); // may be 'back' is better @@ -213,7 +213,7 @@ void FeatureMergeProcessor::DoMerge(FeatureEmitterIFace & emitter) while (ind < curr.GetKeyPointsCount()) // GetKeyPointsCount() can be different on each iteration { std::pair const pt = curr.GetKeyPoint(ind++); - map_t::const_iterator it = m_map.find(get_key(pt.first)); + auto it = m_map.find(GetKey(pt.first)); MergedFeatureBuilder * pp = 0; if (it != m_map.end()) diff --git a/generator/feature_merger.hpp b/generator/feature_merger.hpp index b29f98e5ff..a7d65f33f1 100644 --- a/generator/feature_merger.hpp +++ b/generator/feature_merger.hpp @@ -57,21 +57,21 @@ public: /// Feature merger. class FeatureMergeProcessor { - typedef int64_t key_t; - key_t get_key(m2::PointD const & p); + using Key = int64_t ; + Key GetKey(m2::PointD const & p); MergedFeatureBuilder m_last; - typedef std::vector vector_t; - typedef std::map map_t; - map_t m_map; + using MergedFeatureBuilders = std::vector; + using KeyToMergedFeatureBuilders = std::map; + KeyToMergedFeatureBuilders m_map; void Insert(m2::PointD const & pt, MergedFeatureBuilder * p); - void Remove(key_t key, MergedFeatureBuilder const * p); + void Remove(Key key, MergedFeatureBuilder const * p); inline void Remove1(m2::PointD const & pt, MergedFeatureBuilder const * p) { - Remove(get_key(pt), p); + Remove(GetKey(pt), p); } void Remove(MergedFeatureBuilder const * p); diff --git a/generator/feature_processing_layers.cpp b/generator/feature_processing_layers.cpp index 7df1e94415..e760e57774 100644 --- a/generator/feature_processing_layers.cpp +++ b/generator/feature_processing_layers.cpp @@ -42,23 +42,6 @@ std::string LogBuffer::GetAsString() const return m_buffer.str(); } -std::shared_ptr LayerBase::CloneRecursive() const -{ - auto temp = shared_from_this(); - std::shared_ptr clone; - if (temp) - { - clone = temp->Clone(); - temp = temp->m_next; - } - while (temp) - { - clone->Add(temp->Clone()); - temp = temp->m_next; - } - return clone; -} - void LayerBase::Handle(FeatureBuilder & fb) { if (m_next) @@ -72,8 +55,10 @@ void LayerBase::Merge(std::shared_ptr const & other) m_logBuffer.AppendLine(other->GetAsString()); } -void LayerBase::MergeRecursive(std::shared_ptr const & other) +void LayerBase::MergeChain(std::shared_ptr const & other) { + CHECK_EQUAL(GetChainSize(), other->GetChainSize(), ()); + auto left = shared_from_this(); auto right = other; while (left && right) @@ -84,6 +69,19 @@ void LayerBase::MergeRecursive(std::shared_ptr const & other) } } +size_t LayerBase::GetChainSize() const +{ + size_t size = 0; + auto current = shared_from_this(); + while (current) + { + ++size; + current = current->m_next; + } + + return size; +} + void LayerBase::SetNext(std::shared_ptr next) { m_next = next; @@ -106,21 +104,15 @@ std::string LayerBase::GetAsString() const std::string LayerBase::GetAsStringRecursive() const { - std::ostringstream m_buffer; + std::ostringstream buffer; auto temp = shared_from_this(); while (temp) { - m_buffer << temp->GetAsString(); + buffer << temp->GetAsString(); temp = temp->m_next; } - return m_buffer.str(); -} - -std::shared_ptr RepresentationLayer::Clone() const - -{ - return std::make_shared(); + return buffer.str(); } void RepresentationLayer::Handle(FeatureBuilder & fb) @@ -209,11 +201,6 @@ bool RepresentationLayer::CanBeLine(FeatureParams const & params) return feature::HasUsefulType(params.m_types, feature::GeomType::Line); } -std::shared_ptr PrepareFeatureLayer::Clone() const -{ - return std::make_shared(); -} - void PrepareFeatureLayer::Handle(FeatureBuilder & fb) { auto const type = fb.GetGeomType(); @@ -225,11 +212,6 @@ void PrepareFeatureLayer::Handle(FeatureBuilder & fb) LayerBase::Handle(fb); } -std::shared_ptr RepresentationCoastlineLayer::Clone() const -{ - return std::make_shared(); -} - void RepresentationCoastlineLayer::Handle(FeatureBuilder & fb) { auto const sourceType = fb.GetMostGenericOsmId().GetType(); @@ -243,8 +225,6 @@ void RepresentationCoastlineLayer::Handle(FeatureBuilder & fb) switch (geomType) { case feature::GeomType::Area: - LayerBase::Handle(fb); - break; case feature::GeomType::Line: LayerBase::Handle(fb); break; @@ -262,10 +242,6 @@ void RepresentationCoastlineLayer::Handle(FeatureBuilder & fb) } } -std::shared_ptr PrepareCoastlineFeatureLayer::Clone() const -{ - return std::make_shared(); -} void PrepareCoastlineFeatureLayer::Handle(FeatureBuilder & fb) { @@ -283,38 +259,22 @@ void PrepareCoastlineFeatureLayer::Handle(FeatureBuilder & fb) } WorldLayer::WorldLayer(std::string const & popularityFilename) - : m_popularityFilename(popularityFilename) - , m_filter(popularityFilename) + : m_filter(popularityFilename) { } -std::shared_ptr WorldLayer::Clone() const -{ - return std::make_shared(m_popularityFilename); -} - void WorldLayer::Handle(FeatureBuilder & fb) { if (fb.RemoveInvalidTypes() && m_filter.IsAccepted(fb)) LayerBase::Handle(fb); } -std::shared_ptr CountryLayer::Clone() const -{ - return std::make_shared(); -} - void CountryLayer::Handle(feature::FeatureBuilder & fb) { if (fb.RemoveInvalidTypes() && PreprocessForCountryMap(fb)) LayerBase::Handle(fb); } -std::shared_ptr PreserializeLayer::Clone() const -{ - return std::make_shared(); -} - void PreserializeLayer::Handle(FeatureBuilder & fb) { if (fb.PreSerialize()) diff --git a/generator/feature_processing_layers.hpp b/generator/feature_processing_layers.hpp index c0f8440c27..95e2431b6a 100644 --- a/generator/feature_processing_layers.hpp +++ b/generator/feature_processing_layers.hpp @@ -60,14 +60,13 @@ public: LayerBase() = default; virtual ~LayerBase() = default; - virtual std::shared_ptr Clone() const = 0; - std::shared_ptr CloneRecursive() const; - // The function works in linear time from the number of layers that exist after that. virtual void Handle(feature::FeatureBuilder & fb); void Merge(std::shared_ptr const & other); - void MergeRecursive(std::shared_ptr const & other); + void MergeChain(std::shared_ptr const & other); + + size_t GetChainSize() const; void SetNext(std::shared_ptr next); std::shared_ptr Add(std::shared_ptr next); @@ -82,8 +81,6 @@ public: std::string GetAsStringRecursive() const; private: - void FailIfMethodUnsuppirted() const { CHECK(false, ("This method is unsupported.")); } - LogBuffer m_logBuffer; std::shared_ptr m_next; }; @@ -97,8 +94,6 @@ private: class RepresentationLayer : public LayerBase { // LayerBase overrides: - std::shared_ptr Clone() const override; - void Handle(feature::FeatureBuilder & fb) override; private: @@ -107,7 +102,6 @@ private: static bool CanBeLine(FeatureParams const & params); void HandleArea(feature::FeatureBuilder & fb, FeatureParams const & params); - std::shared_ptr m_processor; }; // Responsibility of class PrepareFeatureLayer is the removal of unused types and names, @@ -116,8 +110,6 @@ class PrepareFeatureLayer : public LayerBase { public: // LayerBase overrides: - std::shared_ptr Clone() const override; - void Handle(feature::FeatureBuilder & fb) override; }; @@ -127,8 +119,6 @@ class RepresentationCoastlineLayer : public LayerBase { public: // LayerBase overrides: - std::shared_ptr Clone() const override; - void Handle(feature::FeatureBuilder & fb) override; }; @@ -138,8 +128,6 @@ class PrepareCoastlineFeatureLayer : public LayerBase { public: // LayerBase overrides: - std::shared_ptr Clone() const override; - void Handle(feature::FeatureBuilder & fb) override; }; @@ -149,12 +137,9 @@ public: explicit WorldLayer(std::string const & popularityFilename); // LayerBase overrides: - std::shared_ptr Clone() const override; - void Handle(feature::FeatureBuilder & fb) override; private: - std::string m_popularityFilename; FilterWorld m_filter; }; @@ -162,8 +147,6 @@ class CountryLayer : public LayerBase { public: // LayerBase overrides: - std::shared_ptr Clone() const override; - void Handle(feature::FeatureBuilder & fb) override; }; @@ -171,59 +154,47 @@ class PreserializeLayer : public LayerBase { public: // LayerBase overrides: - std::shared_ptr Clone() const override; - void Handle(feature::FeatureBuilder & fb) override; }; template -class AffilationsFeatureLayer : public LayerBase +class AffiliationsFeatureLayer : public LayerBase { public: - AffilationsFeatureLayer(size_t bufferSize, std::shared_ptr const & affilation) + AffiliationsFeatureLayer(size_t bufferSize, std::shared_ptr const & affiliation, + std::shared_ptr const & queue) : m_bufferSize(bufferSize) - , m_affilation(affilation) + , m_affiliation(affiliation) + , m_queue(queue) { m_buffer.reserve(m_bufferSize); } // LayerBase overrides: - std::shared_ptr Clone() const override - { - return std::make_shared>(m_bufferSize, m_affilation); - } - void Handle(feature::FeatureBuilder & fb) override { feature::FeatureBuilder::Buffer buffer; SerializePolicy::Serialize(fb, buffer); - m_buffer.emplace_back(std::move(buffer), m_affilation->GetAffiliations(fb)); - } - - bool AddBufferToQueue(std::shared_ptr const & queue) - { - if (!m_buffer.empty()) - { - queue->Push(std::move(m_buffer)); - m_buffer = {}; - m_buffer.reserve(m_bufferSize); - return true; - } - - return false; - } - - bool AddBufferToQueueIfFull(std::shared_ptr const & queue) - { + m_buffer.emplace_back(std::move(buffer), m_affiliation->GetAffiliations(fb)); if (m_buffer.size() >= m_bufferSize) - return AddBufferToQueue(queue); + AddBufferToQueue(); + } - return false; + bool AddBufferToQueue() + { + if (m_buffer.empty()) + return false; + + m_queue->Push(std::move(m_buffer)); + m_buffer.clear(); + m_buffer.reserve(m_bufferSize); + return true; } private: size_t const m_bufferSize; std::vector m_buffer; - std::shared_ptr m_affilation; + std::shared_ptr m_affiliation; + std::shared_ptr m_queue; }; } // namespace generator diff --git a/generator/features_processing_helpers.hpp b/generator/features_processing_helpers.hpp index 9fbe037e83..0d70b65c12 100644 --- a/generator/features_processing_helpers.hpp +++ b/generator/features_processing_helpers.hpp @@ -11,7 +11,7 @@ namespace generator { -size_t static const kAffilationsBufferSize = 512; +size_t static const kAffiliationsBufferSize = 512; struct ProcessedData { diff --git a/generator/generator_integration_tests/features_tests.cpp b/generator/generator_integration_tests/features_tests.cpp index f452822271..016d336cf4 100644 --- a/generator/generator_integration_tests/features_tests.cpp +++ b/generator/generator_integration_tests/features_tests.cpp @@ -29,7 +29,7 @@ public: { // You can get features-2019_07_17__13_39_20 by running: // rsync -v -p testdata.mapsme.cloud.devmail.ru::testdata/features-2019_07_17__13_39_20.zip . - Init("features-2019_07_17__13_39_20" /* arhiveName */); + Init("features-2019_07_17__13_39_20" /* archiveName */); } ~FeatureIntegrationTests() @@ -39,8 +39,8 @@ public: void BuildCoasts() { - auto const worldCoastsGeom = m_genInfo.GetIntermediateFileName(WORLD_COASTS_FILE_NAME".geom"); - auto const worldCoastsRawGeom = m_genInfo.GetIntermediateFileName(WORLD_COASTS_FILE_NAME".rawgeom"); + auto const worldCoastsGeom = m_genInfo.GetIntermediateFileName(WORLD_COASTS_FILE_NAME ".geom"); + auto const worldCoastsRawGeom = m_genInfo.GetIntermediateFileName(WORLD_COASTS_FILE_NAME ".rawgeom"); CHECK(!Platform::IsFileExistsByFullPath(worldCoastsGeom), ()); CHECK(!Platform::IsFileExistsByFullPath(worldCoastsRawGeom), ()); @@ -51,7 +51,7 @@ public: TEST(Platform::IsFileExistsByFullPath(worldCoastsGeom), ()); TEST(Platform::IsFileExistsByFullPath(worldCoastsRawGeom), ()); - size_t fileSize = 0; + uint64_t fileSize = 0; CHECK(Platform::GetFileSizeByFullPath(worldCoastsGeom, fileSize), ()); TEST_GREATER(fileSize, 0, ()); CHECK(Platform::GetFileSizeByFullPath(worldCoastsRawGeom, fileSize), ()); @@ -129,16 +129,16 @@ public: TestCountry(northAuckland, 1811971 /* fbsCnt */, 12195948 /* pointsCnt */, 1007372 /* pointCnt */, 205469 /* lineCnt */, 599130 /* areaCnt */, 212087 /* poiCnt */, - 521 /* cityTownOrVillageCnt */, 43 /* popularAttractionCnt */, 3557 /* bookingHotelsCnt */); + 521 /* cityTownOrVillageCnt */, 3557 /* bookingHotelsCnt */); TestCountry(northWellington, 797778 /* fbsCnt */, 7772270 /* pointsCnt */, 460446 /* pointCnt */, 87058 /* lineCnt */, 250274 /* areaCnt */, 95651 /* poiCnt */, - 297 /* cityTownOrVillageCnt */, 16 /* popularAttractionCnt */, 1062 /* bookingHotelsCnt */); + 297 /* cityTownOrVillageCnt */, 1062 /* bookingHotelsCnt */); TestCountry(southCanterbury, 636934 /* fbsCnt */, 6984360 /* pointsCnt */, 397634 /* pointCnt */, 81712 /* lineCnt */, 157588 /* areaCnt */, 89249 /* poiCnt */, - 331 /* cityTownOrVillageCnt */, 40 /* popularAttractionCnt */, 2085 /* bookingHotelsCnt */); + 331 /* cityTownOrVillageCnt */, 2085 /* bookingHotelsCnt */); TestCountry(southSouthland, 340491 /* fbsCnt */, 5342804 /* pointsCnt */, 185845 /* pointCnt */, 40124 /* lineCnt */, 114522 /* areaCnt */, 40497 /* poiCnt */, - 297 /* cityTownOrVillageCnt */, 37 /* popularAttractionCnt */, 1621 /* bookingHotelsCnt */); + 297 /* cityTownOrVillageCnt */, 1621 /* bookingHotelsCnt */); } void CheckGeneratedData() @@ -166,7 +166,7 @@ public: TestGeneratedFile(cameraToWays, 0 /* fileSize */); TestGeneratedFile(citiesAreas, 18601 /* fileSize */); TestGeneratedFile(maxSpeeds, 1301515 /* fileSize */); - TestGeneratedFile(metalines, 306228 /* fileSize */); + TestGeneratedFile(metalines, 288032 /* fileSize */); TestGeneratedFile(restrictions, 273283 /* fileSize */); TestGeneratedFile(roadAccess, 1918315 /* fileSize */); TestGeneratedFile(m_genInfo.m_citiesBoundariesFilename, 2435 /* fileSize */); @@ -193,7 +193,7 @@ public: private: void TestCountry(std::string const & path, size_t fbsCnt, size_t pointsCnt, size_t pointCnt, size_t lineCnt, size_t areaCnt, size_t poiCnt, size_t cityTownOrVillageCnt, - size_t popularAttractionCnt, size_t bookingHotelsCnt) + size_t bookingHotelsCnt) { CHECK(Platform::IsFileExistsByFullPath(path), ()); auto const fbs = feature::ReadAllDatRawFormat(path); @@ -203,7 +203,6 @@ private: size_t areaCntReal = 0; size_t poiCntReal = 0; size_t cityTownOrVillageCntReal = 0; - size_t popularAttractionCntReal = 0; size_t bookingHotelsCntReal = 0; for (auto const & fb : fbs) { @@ -219,9 +218,6 @@ private: if (poiChecker(fb.GetTypes())) ++poiCntReal; - if (generator::FilterWorld::IsPopularAttraction(fb, m_genInfo.m_popularPlacesFilename)) - ++popularAttractionCntReal; - if (ftypes::IsCityTownOrVillage(fb.GetTypes())) ++cityTownOrVillageCntReal; @@ -237,19 +233,18 @@ private: TEST_EQUAL(areaCntReal, areaCnt, ()); TEST_EQUAL(poiCntReal, poiCnt, ()); TEST_EQUAL(cityTownOrVillageCntReal, cityTownOrVillageCnt, ()); - TEST_EQUAL(popularAttractionCntReal, popularAttractionCnt, ()); TEST_EQUAL(bookingHotelsCntReal, bookingHotelsCnt, ()); } void TestGeneratedFile(std::string const & path, size_t fileSize) { TEST(Platform::IsFileExistsByFullPath(path), (path)); - size_t fileSizeReal = 0; + uint64_t fileSizeReal = 0; CHECK(Platform::GetFileSizeByFullPath(path, fileSizeReal), (path)); TEST_EQUAL(fileSizeReal, fileSize, (path)); } - void Init(std::string const & arhiveName) + void Init(std::string const & archiveName) { classificator::Load(); auto const & options = GetTestingOptions(); @@ -260,13 +255,13 @@ private: m_testPath = base::JoinPath(platform.WritableDir(), "gen-test"); m_genInfo.SetNodeStorageType("map"); m_genInfo.SetOsmFileType("o5m"); - m_genInfo.m_intermediateDir = base::JoinPath(m_testPath, arhiveName, "intermediate_data"); + m_genInfo.m_intermediateDir = base::JoinPath(m_testPath, archiveName, "intermediate_data"); m_genInfo.m_targetDir = m_genInfo.m_intermediateDir; m_genInfo.m_tmpDir = base::JoinPath(m_genInfo.m_intermediateDir, "tmp"); m_genInfo.m_osmFileName = base::JoinPath(m_testPath, "planet.o5m"); m_genInfo.m_popularPlacesFilename = m_genInfo.GetIntermediateFileName("popular_places.csv"); m_genInfo.m_idToWikidataFilename = m_genInfo.GetIntermediateFileName("wiki_urls.csv"); - DecompressZipArchive(base::JoinPath(options.m_dataPath, arhiveName + ".zip"), m_testPath); + DecompressZipArchive(base::JoinPath(options.m_dataPath, archiveName + ".zip"), m_testPath); } size_t m_threadCount; diff --git a/generator/generator_tests/camera_collector_tests.cpp b/generator/generator_tests/camera_collector_tests.cpp index e6d8c251b3..82d11dc6f6 100644 --- a/generator/generator_tests/camera_collector_tests.cpp +++ b/generator/generator_tests/camera_collector_tests.cpp @@ -27,6 +27,7 @@ #include "defines.hpp" #include +#include #include #include #include @@ -54,15 +55,15 @@ feature::FeatureBuilder MakeFeatureBuilderWithParams(OsmElement & element) class TranslatorForTest : public Translator { public: - explicit TranslatorForTest(std::shared_ptr const & processor, - std::shared_ptr const & cache) - : Translator(processor, cache, std::make_shared(cache)) + explicit TranslatorForTest(shared_ptr const & processor, + shared_ptr const & cache) + : Translator(processor, cache, make_shared(cache)) { SetFilter(make_shared()); } // TranslatorInterface overrides: - std::shared_ptr Clone() const override + shared_ptr Clone() const override { CHECK(false, ()); return {}; @@ -84,8 +85,8 @@ class TestCameraCollector { public: // Directory name for creating test mwm and temprary files. - std::string static const kTestDir; - std::string static const kOsmFileName; + string static const kTestDir; + string static const kOsmFileName; TestCameraCollector() { @@ -113,10 +114,10 @@ public: CHECK(GenerateIntermediateData(genInfo), ()); // Test load this data from cached file. - auto collector = std::make_shared(genInfo.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME)); - auto cache = std::make_shared(genInfo, true /* forceReload */); + auto collector = make_shared(genInfo.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME)); + auto cache = make_shared(genInfo, true /* forceReload */); auto processor = CreateProcessor(ProcessorType::Noop); - auto translator = std::make_shared(processor, cache); + auto translator = make_shared(processor, cache); translator->SetCollector(collector); RawGenerator rawGenerator(genInfo); rawGenerator.GenerateCustom(translator); @@ -127,9 +128,7 @@ public: answers.emplace(camera.m_id, w); }); - return answers == trueAnswers; - } void TestMergeCollectors() @@ -140,7 +139,7 @@ public: // Generate intermediate data. genInfo.m_intermediateDir = writableDir; auto const filename = genInfo.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME); - auto collector1 = std::make_shared(filename); + auto collector1 = make_shared(filename); auto collector2 = collector1->Clone(); { OsmElement el; @@ -202,12 +201,12 @@ public: answers.emplace(camera.m_id, w); }); - TEST(answers == trueAnswers, ()); + TEST_EQUAL(answers, trueAnswers, ()); } }; -std::string const TestCameraCollector::kTestDir = "camera_test"; -std::string const TestCameraCollector::kOsmFileName = "planet" OSM_DATA_FILE_EXTENSION; +string const TestCameraCollector::kTestDir = "camera_test"; +string const TestCameraCollector::kOsmFileName = "planet" OSM_DATA_FILE_EXTENSION; } // namespace generator_tests using namespace generator_tests; diff --git a/generator/generator_tests/collector_city_area_tests.cpp b/generator/generator_tests/collector_city_area_tests.cpp index d8341e3134..e8dd1904a1 100644 --- a/generator/generator_tests/collector_city_area_tests.cpp +++ b/generator/generator_tests/collector_city_area_tests.cpp @@ -1,8 +1,8 @@ #include "testing/testing.hpp" -#include "generator/generator_tests/common.hpp" #include "generator/collector_city_area.hpp" #include "generator/feature_builder.hpp" +#include "generator/generator_tests/common.hpp" #include "generator/osm2type.hpp" #include "generator/osm_element.hpp" @@ -12,8 +12,8 @@ #include "geometry/point2d.hpp" -#include "base/scope_guard.hpp" #include "base/geo_object_id.hpp" +#include "base/scope_guard.hpp" #include #include @@ -34,7 +34,7 @@ feature::FeatureBuilder MakeFbForTest(OsmElement element) return result; } -bool FindId(std::vector const & fbs, uint64_t id) { +bool HasRelationWithId(std::vector const & fbs, uint64_t id) { return std::find_if(std::begin(fbs), std::end(fbs), [&](auto const & fb) { return fb.GetMostGenericOsmId() == base::MakeOsmRelation(id); }) != std::end(fbs); @@ -46,7 +46,7 @@ auto const o3 = MakeOsmElement(3 /* id */, {{"place", "village"}} /* tags */, Os auto const o4 = MakeOsmElement(4 /* id */, {{"place", "country"}} /* tags */, OsmElement::EntityType::Relation); } // namespace -UNIT_TEST(CollectorCityArea_Case1) +UNIT_TEST(CollectorCityArea_Merge) { classificator::Load(); auto const filename = generator_tests::GetFileName(); @@ -65,7 +65,7 @@ UNIT_TEST(CollectorCityArea_Case1) auto const fbs = feature::ReadAllDatRawFormat(filename); TEST_EQUAL(fbs.size(), 3, ()); - TEST(FindId(fbs, 1 /* id */), ()); - TEST(FindId(fbs, 2 /* id */), ()); - TEST(FindId(fbs, 3 /* id */), ()); + TEST(HasRelationWithId(fbs, 1 /* id */), ()); + TEST(HasRelationWithId(fbs, 2 /* id */), ()); + TEST(HasRelationWithId(fbs, 3 /* id */), ()); } diff --git a/generator/generator_tests/common.cpp b/generator/generator_tests/common.cpp index 606b3d066e..13b2a465c4 100644 --- a/generator/generator_tests/common.cpp +++ b/generator/generator_tests/common.cpp @@ -30,8 +30,6 @@ OsmElement MakeOsmElement(uint64_t id, Tags const & tags, OsmElement::EntityType std::string GetFileName(std::string const & filename) { auto & platform = GetPlatform(); - auto const tmpDir = platform.TmpDir(); - platform.SetWritableDirForTests(tmpDir); return filename.empty() ? platform.TmpPathForFile() : platform.TmpPathForFile(filename); } @@ -43,10 +41,9 @@ bool MakeFakeBordersFile(std::string const & intemediatePath, std::string const if (code != Platform::EError::ERR_OK && code != Platform::EError::ERR_FILE_ALREADY_EXISTS) return false; - std::ofstream file; - file.exceptions(std::ios::failbit | std::ios::badbit); - file.open(base::JoinPath(borderPath, filename + ".poly")); - file << filename << "\n1\n\t-180.0 -90.0\n\t180.0 -90.0\n\t180.0 90.0\n\t-180.0 90.0\n\t-180.0 -90.0\nEND\nEND"; + std::vector points = {{-180.0, -90.0}, {180.0, -90.0}, {180.0, 90.0}, {-180.0, 90.0}, + {-180.0, -90.0}}; + borders::DumpBorderToPolyFile(borderPath, filename, {m2::RegionD{points}}); return true; } @@ -77,7 +74,7 @@ feature::FeatureBuilder FeatureBuilderFromOmsElementData(OsmElementData const & auto const & p1 = elementData.m_polygon[0]; auto const & p2 = elementData.m_polygon[1]; vector poly = { - {p1.x, p1.y}, {p1.x, p2.y}, {p2.x, p2.y}, {p2.x, p1.y}, {p1.x, p1.y}}; + {p1.x, p1.y}, {p1.x, p2.y}, {p2.x, p2.y}, {p2.x, p1.y}, {p1.x, p1.y}}; fb.AddPolygon(poly); fb.SetHoles({}); fb.SetArea(); diff --git a/generator/generator_tests/feature_builder_test.cpp b/generator/generator_tests/feature_builder_test.cpp index 2c868df0f0..4705ecfd14 100644 --- a/generator/generator_tests/feature_builder_test.cpp +++ b/generator/generator_tests/feature_builder_test.cpp @@ -231,7 +231,7 @@ UNIT_CLASS_TEST(TestWithClassificator, FeatureParams_Parsing) } } -UNIT_CLASS_TEST(TestWithClassificator, FeatureBuilder2_SerializeLocalityObjectForBuildingPoint) +UNIT_CLASS_TEST(TestWithClassificator, FeatureBuilder_SerializeLocalityObjectForBuildingPoint) { FeatureBuilder fb; FeatureParams params; diff --git a/generator/generator_tests/maxspeeds_tests.cpp b/generator/generator_tests/maxspeeds_tests.cpp index f1af24a50b..2d665702c8 100644 --- a/generator/generator_tests/maxspeeds_tests.cpp +++ b/generator/generator_tests/maxspeeds_tests.cpp @@ -373,11 +373,11 @@ UNIT_TEST(MaxspeedSection_Big) TestMaxspeedsSection(roads, maxspeedsCsvContent, featureIdToOsmId); } -UNIT_TEST(MaxspeedCollector_Case1) +UNIT_TEST(MaxspeedCollector_Merge) { classificator::Load(); auto const filename = GetFileName(); - SCOPE_GUARD(_, bind(Platform::RemoveFileIfExists, cref(filename))); + SCOPE_GUARD(_, std::bind(Platform::RemoveFileIfExists, std::cref(filename))); auto c1 = std::make_shared(filename); auto c2 = c1->Clone(); diff --git a/generator/generator_tests/merge_collectors_tests.cpp b/generator/generator_tests/merge_collectors_tests.cpp index b7e4bcc199..2e486bea8a 100644 --- a/generator/generator_tests/merge_collectors_tests.cpp +++ b/generator/generator_tests/merge_collectors_tests.cpp @@ -24,7 +24,7 @@ namespace auto const kEmptyValidator = [](auto const &) { return true; }; } -UNIT_TEST(MergeCollector_Case1) +UNIT_TEST(MergeCollector_MergeCase1) { auto const filename = GetFileName(); std::string const tagKey = "admin_level"; @@ -59,7 +59,7 @@ UNIT_TEST(MergeCollector_Case1) TEST_EQUAL(line, answers[pos++], ()); } -UNIT_TEST(MergeCollector_Case2) +UNIT_TEST(MergeCollector_MergeCase2) { auto const filename = GetFileName(); std::string const tagKey = "admin_level"; diff --git a/generator/generator_tests/metalines_tests.cpp b/generator/generator_tests/metalines_tests.cpp index 3ee83bcafe..d44b0f5215 100644 --- a/generator/generator_tests/metalines_tests.cpp +++ b/generator/generator_tests/metalines_tests.cpp @@ -9,6 +9,8 @@ #include "platform/platform.hpp" +#include "coding/read_write_utils.hpp" + #include "base/scope_guard.hpp" #include @@ -164,7 +166,7 @@ UNIT_TEST(MetalinesTest_Case6) TEST_EQUAL(outputData.at(keyB).size(), 1 /* ways count */, ()); } -UNIT_TEST(MetalinesTest_MetalinesBuilder) +UNIT_TEST(MetalinesTest_MetalinesBuilderMarge) { classificator::Load(); auto const filename = generator_tests::GetFileName(); @@ -186,9 +188,8 @@ UNIT_TEST(MetalinesTest_MetalinesBuilder) std::set> s; while (src.Size() > 0) { - uint16_t size = ReadPrimitiveFromSource(src); - std::vector ways(size); - src.Read(ways.data(), size * sizeof(int32_t)); + std::vector ways; + rw::ReadVectorOfPOD(src, ways); s.emplace(std::move(ways)); } diff --git a/generator/generator_tests/region_info_collector_tests.cpp b/generator/generator_tests/region_info_collector_tests.cpp index ac5a1fa5a1..c0385cd216 100644 --- a/generator/generator_tests/region_info_collector_tests.cpp +++ b/generator/generator_tests/region_info_collector_tests.cpp @@ -138,7 +138,7 @@ UNIT_TEST(RegionInfoCollector_Exists) UNIT_TEST(RegionInfoCollector_MergeAndSave) { auto const filename = generator_tests::GetFileName(); - SCOPE_GUARD(_, bind(Platform::RemoveFileIfExists, cref(filename))); + SCOPE_GUARD(_, std::bind(Platform::RemoveFileIfExists, std::cref(filename))); auto c1 = std::make_shared(filename); auto c2 = c1->Clone(); diff --git a/generator/generator_tests/restriction_collector_test.cpp b/generator/generator_tests/restriction_collector_test.cpp index 86f7fe3619..55364c5f16 100644 --- a/generator/generator_tests/restriction_collector_test.cpp +++ b/generator/generator_tests/restriction_collector_test.cpp @@ -17,6 +17,7 @@ #include "base/scope_guard.hpp" #include "base/stl_helpers.hpp" +#include #include #include #include @@ -214,7 +215,7 @@ UNIT_CLASS_TEST(TestRestrictionCollector, InvalidCase_FeaturesNotIntersecting) TestRestrictionCollector::InvalidCase_FeaturesNotIntersecting(); } -UNIT_TEST(RestrictionWriter_Case1) +UNIT_TEST(RestrictionWriter_Merge) { classificator::Load(); auto const filename = generator_tests::GetFileName(); diff --git a/generator/generator_tests/road_access_test.cpp b/generator/generator_tests/road_access_test.cpp index 1bf52be5c9..7b496b6f2d 100644 --- a/generator/generator_tests/road_access_test.cpp +++ b/generator/generator_tests/road_access_test.cpp @@ -180,7 +180,7 @@ UNIT_TEST(RoadAccess_Access_Multiple_Vehicle_Types) TEST_EQUAL(bicycleRoadAccess.GetFeatureType(3 /* featureId */), RoadAccess::Type::No, ()); } -UNIT_TEST(RoadAccessWriter_Case1) +UNIT_TEST(RoadAccessWriter_Merge) { classificator::Load(); auto const filename = generator_tests::GetFileName(); diff --git a/generator/generator_tests/speed_cameras_test.cpp b/generator/generator_tests/speed_cameras_test.cpp index cac9629d7e..dceb1d833a 100644 --- a/generator/generator_tests/speed_cameras_test.cpp +++ b/generator/generator_tests/speed_cameras_test.cpp @@ -1,7 +1,6 @@ #include "testing/testing.hpp" #include "generator/camera_info_collector.hpp" -#include "generator/processor_factory.hpp" #include "generator/feature_sorter.hpp" #include "generator/generate_info.hpp" #include "generator/generator_tests/common.hpp" @@ -10,8 +9,9 @@ #include "generator/intermediate_data.hpp" #include "generator/maxspeeds_parser.hpp" #include "generator/metalines_builder.hpp" -#include "generator/raw_generator.hpp" #include "generator/osm_source.hpp" +#include "generator/processor_factory.hpp" +#include "generator/raw_generator.hpp" #include "generator/translator_collection.hpp" #include "generator/translator_factory.hpp" diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp index f820881a1c..80e2580119 100644 --- a/generator/generator_tool/generator_tool.cpp +++ b/generator/generator_tool/generator_tool.cpp @@ -6,11 +6,9 @@ #include "generator/cities_boundaries_builder.hpp" #include "generator/cities_ids_builder.hpp" #include "generator/city_roads_generator.hpp" -#include "generator/descriptions_section_builder.hpp" #include "generator/data_version.hpp" +#include "generator/descriptions_section_builder.hpp" #include "generator/dumper.hpp" -#include "generator/osm_source.hpp" -#include "generator/processor_factory.hpp" #include "generator/feature_generator.hpp" #include "generator/feature_sorter.hpp" #include "generator/generate_info.hpp" @@ -18,9 +16,11 @@ #include "generator/locality_sorter.hpp" #include "generator/maxspeeds_builder.hpp" #include "generator/metalines_builder.hpp" +#include "generator/osm_source.hpp" #include "generator/platform_helpers.hpp" #include "generator/popular_places_section_builder.hpp" #include "generator/popularity.hpp" +#include "generator/processor_factory.hpp" #include "generator/ratings_section_builder.hpp" #include "generator/raw_generator.hpp" #include "generator/regions/collector_region_info.hpp" @@ -117,12 +117,12 @@ DEFINE_uint64(planet_version, base::SecondsSinceEpoch(), DEFINE_bool(preprocess, false, "1st pass - create nodes/ways/relations data."); DEFINE_bool(generate_features, false, "2nd pass - generate intermediate features."); DEFINE_bool(no_ads, false, "generation without ads."); -DEFINE_string(generate_region_features, "", - "Generate intermediate features for regions to use in regions index and borders generation."); -DEFINE_string(generate_streets_features, "", - "Generate intermediate features for streets to use in server-side forward geocoder."); -DEFINE_string(generate_geo_objects_features, "", - "Generate intermediate features for geo objects to use in geo objects index."); +DEFINE_bool(generate_region_features, false, + "Generate intermediate features for regions to use in regions index and borders generation."); +DEFINE_bool(generate_streets_features, false, + "Generate intermediate features for streets to use in server-side forward geocoder."); +DEFINE_bool(generate_geo_objects_features, false, + "Generate intermediate features for geo objects to use in geo objects index."); DEFINE_bool(generate_geometry, false, "3rd pass - split and simplify geometry and triangles for features."); DEFINE_bool(generate_index, false, "4rd pass - generate index."); @@ -222,14 +222,13 @@ DEFINE_string(regions_features, "", "Input tmp.mwm file with regions."); DEFINE_string(popularity_csv, "", "Output csv for popularity."); -DEFINE_bool(dump_mwm_tmp, false, "Prints features builder objects from .mwm.tmp"); +DEFINE_bool(dump_mwm_tmp, false, "Prints feature builder objects from .mwm.tmp"); // Common. DEFINE_bool(verbose, false, "Provide more detailed output."); using namespace generator; - int GeneratorToolMain(int argc, char ** argv) { CHECK(IsLittleEndian(), ("Only little-endian architectures are supported.")); @@ -312,9 +311,9 @@ int GeneratorToolMain(int argc, char ** argv) if (FLAGS_generate_features || FLAGS_generate_world || FLAGS_make_coasts || - !FLAGS_generate_region_features.empty() || - !FLAGS_generate_streets_features.empty() || - !FLAGS_generate_geo_objects_features.empty()) + FLAGS_generate_region_features || + FLAGS_generate_streets_features || + FLAGS_generate_geo_objects_features) { RawGenerator rawGenerator(genInfo, threadsCount); if (FLAGS_generate_features) @@ -323,12 +322,12 @@ int GeneratorToolMain(int argc, char ** argv) rawGenerator.GenerateWorld(FLAGS_no_ads); if (FLAGS_make_coasts) rawGenerator.GenerateCoasts(); - if (!FLAGS_generate_region_features.empty()) - rawGenerator.GenerateRegionFeatures(FLAGS_generate_region_features); - if (!FLAGS_generate_streets_features.empty()) - rawGenerator.GenerateStreetsFeatures(FLAGS_generate_streets_features); - if (!FLAGS_generate_geo_objects_features.empty()) - rawGenerator.GenerateGeoObjectsFeatures(FLAGS_generate_geo_objects_features); + if (FLAGS_generate_region_features) + rawGenerator.GenerateRegionFeatures(FLAGS_output); + if (FLAGS_generate_streets_features) + rawGenerator.GenerateStreetsFeatures(FLAGS_output); + if (FLAGS_generate_geo_objects_features) + rawGenerator.GenerateGeoObjectsFeatures(FLAGS_output); if (!rawGenerator.Execute()) return EXIT_FAILURE; diff --git a/generator/metalines_builder.cpp b/generator/metalines_builder.cpp index f753abc7cc..d816b9fcbb 100644 --- a/generator/metalines_builder.cpp +++ b/generator/metalines_builder.cpp @@ -6,6 +6,7 @@ #include "indexer/classificator.hpp" #include "coding/file_container.hpp" +#include "coding/read_write_utils.hpp" #include "coding/varint.hpp" #include "coding/write_to_sink.hpp" @@ -104,7 +105,7 @@ LineStringMerger::OutputData LineStringMerger::Merge(InputData const & data) bool LineStringMerger::TryMerge(LinePtr const & lineString, Buffer & buffer) { bool merged = false; - while(TryMergeOne(lineString, buffer)) + while (TryMergeOne(lineString, buffer)) merged = true; buffer.emplace(lineString->GetStart(), lineString); @@ -200,11 +201,8 @@ void MetalinesBuilder::Save() for (auto const & lineString : p.second) { auto const & ways = lineString->GetWays(); - uint16_t size = base::checked_cast(ways.size()); - WriteToSink(writer, size); + rw::WriteVectorOfPOD(writer, ways); countWays += ways.size(); - for (int32_t const way : ways) - WriteToSink(writer, way); ++countLines; } } @@ -240,9 +238,8 @@ bool WriteMetalinesSection(std::string const & mwmPath, std::string const & meta while (src.Size() > 0) { std::vector featureIds; - uint16_t size = ReadPrimitiveFromSource(src); - std::vector ways(size); - src.Read(ways.data(), size * sizeof(int32_t)); + std::vector ways; + rw::ReadVectorOfPOD(src, ways); for (auto const wayId : ways) { // We get a negative wayId when a feature direction should be reversed. diff --git a/generator/processor_coastline.cpp b/generator/processor_coastline.cpp index bd014e9a4c..f411ddcdc8 100644 --- a/generator/processor_coastline.cpp +++ b/generator/processor_coastline.cpp @@ -19,9 +19,9 @@ ProcessorCoastline::ProcessorCoastline(std::shared_ptr co { m_processingChain = std::make_shared(); m_processingChain->Add(std::make_shared()); - auto affilation = std::make_shared(WORLD_COASTS_FILE_NAME); - m_affilationsLayer = std::make_shared>(kAffilationsBufferSize, affilation); - m_processingChain->Add(m_affilationsLayer); + auto affiliation = std::make_shared(WORLD_COASTS_FILE_NAME); + m_affiliationsLayer = std::make_shared>(kAffiliationsBufferSize, affiliation, m_queue); + m_processingChain->Add(m_affiliationsLayer); } std::shared_ptr ProcessorCoastline::Clone() const @@ -32,12 +32,11 @@ std::shared_ptr ProcessorCoastline::Clone() const void ProcessorCoastline::Process(feature::FeatureBuilder & feature) { m_processingChain->Handle(feature); - m_affilationsLayer->AddBufferToQueueIfFull(m_queue); } void ProcessorCoastline::Finish() { - m_affilationsLayer->AddBufferToQueue(m_queue); + m_affiliationsLayer->AddBufferToQueue(); } void ProcessorCoastline::Merge(FeatureProcessorInterface const & other) @@ -47,6 +46,6 @@ void ProcessorCoastline::Merge(FeatureProcessorInterface const & other) void ProcessorCoastline::MergeInto(ProcessorCoastline & other) const { - other.m_processingChain->Merge(m_processingChain); + other.m_processingChain->MergeChain(m_processingChain); } } // namespace generator diff --git a/generator/processor_coastline.hpp b/generator/processor_coastline.hpp index 56dfe52669..2de40b5ffb 100644 --- a/generator/processor_coastline.hpp +++ b/generator/processor_coastline.hpp @@ -24,7 +24,7 @@ public: void MergeInto(ProcessorCoastline & other) const override; private: - std::shared_ptr> m_affilationsLayer; + std::shared_ptr> m_affiliationsLayer; std::shared_ptr m_queue; std::shared_ptr m_processingChain; }; diff --git a/generator/processor_country.cpp b/generator/processor_country.cpp index 1cfed5a633..fcb48ce8f6 100644 --- a/generator/processor_country.cpp +++ b/generator/processor_country.cpp @@ -20,9 +20,9 @@ ProcessorCountry::ProcessorCountry(std::shared_ptr const m_processingChain = std::make_shared(); m_processingChain->Add(std::make_shared()); m_processingChain->Add(std::make_shared()); - auto affilation = std::make_shared(bordersPath, haveBordersForWholeWorld); - m_affilationsLayer = std::make_shared>(kAffilationsBufferSize, affilation); - m_processingChain->Add(m_affilationsLayer); + auto affiliation = std::make_shared(bordersPath, haveBordersForWholeWorld); + m_affiliationsLayer = std::make_shared>(kAffiliationsBufferSize, affiliation, m_queue); + m_processingChain->Add(m_affiliationsLayer); } @@ -34,12 +34,11 @@ std::shared_ptr ProcessorCountry::Clone() const void ProcessorCountry::Process(feature::FeatureBuilder & feature) { m_processingChain->Handle(feature); - m_affilationsLayer->AddBufferToQueueIfFull(m_queue); } void ProcessorCountry::Finish() { - m_affilationsLayer->AddBufferToQueue(m_queue); + m_affiliationsLayer->AddBufferToQueue(); } void ProcessorCountry::WriteDump() @@ -58,6 +57,6 @@ void ProcessorCountry::Merge(FeatureProcessorInterface const & other) void ProcessorCountry::MergeInto(ProcessorCountry & other) const { - other.m_processingChain->Merge(m_processingChain); + other.m_processingChain->MergeChain(m_processingChain); } } // namespace generator diff --git a/generator/processor_country.hpp b/generator/processor_country.hpp index 69a3bd95bd..a74af4b56a 100644 --- a/generator/processor_country.hpp +++ b/generator/processor_country.hpp @@ -37,7 +37,7 @@ private: std::string m_bordersPath; std::string m_layerLogFilename; - std::shared_ptr> m_affilationsLayer; + std::shared_ptr> m_affiliationsLayer; std::shared_ptr m_queue; std::shared_ptr m_processingChain; bool m_haveBordersForWholeWorld; diff --git a/generator/processor_simple.cpp b/generator/processor_simple.cpp index 5da4508eec..71f5a95208 100644 --- a/generator/processor_simple.cpp +++ b/generator/processor_simple.cpp @@ -12,10 +12,11 @@ ProcessorSimple::ProcessorSimple(std::shared_ptr const & : m_name(name) , m_queue(queue) { - m_processingChain->Add(std::make_shared()); - auto affilation = std::make_shared(name); - m_affilationsLayer = std::make_shared>(kAffilationsBufferSize, affilation); - m_processingChain->Add(m_affilationsLayer); + m_processingChain = std::make_shared(); + auto affiliation = std::make_shared(name); + m_affiliationsLayer = std::make_shared>(kAffiliationsBufferSize, affiliation, m_queue); + m_processingChain->Add(m_affiliationsLayer); } std::shared_ptrProcessorSimple::Clone() const @@ -26,12 +27,11 @@ std::shared_ptrProcessorSimple::Clone() const void ProcessorSimple::Process(feature::FeatureBuilder & fb) { m_processingChain->Handle(fb); - m_affilationsLayer->AddBufferToQueueIfFull(m_queue); } void ProcessorSimple::Finish() { - m_affilationsLayer->AddBufferToQueue(m_queue); + m_affiliationsLayer->AddBufferToQueue(); } void ProcessorSimple::Merge(FeatureProcessorInterface const & other) @@ -41,6 +41,6 @@ void ProcessorSimple::Merge(FeatureProcessorInterface const & other) void ProcessorSimple::MergeInto(ProcessorSimple & other) const { - other.m_processingChain->Merge(m_processingChain); + other.m_processingChain->MergeChain(m_processingChain); } } // namespace generator diff --git a/generator/processor_simple.hpp b/generator/processor_simple.hpp index 4b30063fec..c9c8594426 100644 --- a/generator/processor_simple.hpp +++ b/generator/processor_simple.hpp @@ -30,7 +30,7 @@ public: private: std::string m_name; - std::shared_ptr> m_affilationsLayer; + std::shared_ptr> m_affiliationsLayer; std::shared_ptr m_queue; std::shared_ptr m_processingChain; }; diff --git a/generator/processor_world.cpp b/generator/processor_world.cpp index 48a6f64c98..89c91b888d 100644 --- a/generator/processor_world.cpp +++ b/generator/processor_world.cpp @@ -16,9 +16,9 @@ ProcessorWorld::ProcessorWorld(std::shared_ptr const & qu m_processingChain = std::make_shared(); m_processingChain->Add(std::make_shared()); m_processingChain->Add(std::make_shared(popularityFilename)); - auto affilation = std::make_shared(WORLD_FILE_NAME); - m_affilationsLayer = std::make_shared>(kAffilationsBufferSize, affilation); - m_processingChain->Add(m_affilationsLayer); + auto affiliation = std::make_shared(WORLD_FILE_NAME); + m_affiliationsLayer = std::make_shared>(kAffiliationsBufferSize, affiliation, m_queue); + m_processingChain->Add(m_affiliationsLayer); } std::shared_ptr ProcessorWorld::Clone() const @@ -29,12 +29,11 @@ std::shared_ptr ProcessorWorld::Clone() const void ProcessorWorld::Process(feature::FeatureBuilder & feature) { m_processingChain->Handle(feature); - m_affilationsLayer->AddBufferToQueueIfFull(m_queue); } void ProcessorWorld::Finish() { - m_affilationsLayer->AddBufferToQueue(m_queue); + m_affiliationsLayer->AddBufferToQueue(); } void ProcessorWorld::Merge(FeatureProcessorInterface const & other) @@ -44,6 +43,6 @@ void ProcessorWorld::Merge(FeatureProcessorInterface const & other) void ProcessorWorld::MergeInto(ProcessorWorld & other) const { - other.m_processingChain->Merge(m_processingChain); + other.m_processingChain->MergeChain(m_processingChain); } } // namespace generator diff --git a/generator/processor_world.hpp b/generator/processor_world.hpp index 53e27e3e02..eba44c5eb8 100644 --- a/generator/processor_world.hpp +++ b/generator/processor_world.hpp @@ -33,7 +33,7 @@ public: private: std::string m_popularityFilename; - std::shared_ptr> m_affilationsLayer; + std::shared_ptr> m_affiliationsLayer; std::shared_ptr m_queue; std::shared_ptr m_processingChain; }; diff --git a/generator/tag_admixer.hpp b/generator/tag_admixer.hpp index d381ef4ba8..5b97c8744e 100644 --- a/generator/tag_admixer.hpp +++ b/generator/tag_admixer.hpp @@ -18,7 +18,7 @@ class WaysParserHelper { public: - WaysParserHelper(std::map & ways) : m_ways(ways) {} + explicit WaysParserHelper(std::map & ways) : m_ways(ways) {} void ParseStream(std::istream & input) { @@ -43,7 +43,7 @@ private: class CapitalsParserHelper { public: - CapitalsParserHelper(std::set & capitals) : m_capitals(capitals) {} + explicit CapitalsParserHelper(std::set & capitals) : m_capitals(capitals) {} void ParseStream(std::istream & input) { @@ -81,7 +81,7 @@ class TagAdmixer public: TagAdmixer() = default; - TagAdmixer(std::string const & waysFile, std::string const & capitalsFile) : m_ferryTag("route", "ferry") + explicit TagAdmixer(std::string const & waysFile, std::string const & capitalsFile) { { std::ifstream reader(waysFile); @@ -97,7 +97,7 @@ public: } TagAdmixer(TagAdmixer const & other) - : m_ways(other.m_ways), m_capitals(other.m_capitals), m_ferryTag(other.m_ferryTag) {} + : m_ways(other.m_ways), m_capitals(other.m_capitals) {} TagAdmixer & operator=(TagAdmixer const & other) { @@ -105,7 +105,6 @@ public: { m_ways = other.m_ways; m_capitals = other.m_capitals; - m_ferryTag = other.m_ferryTag; } return *this; @@ -116,7 +115,8 @@ public: if (element.m_type == OsmElement::EntityType::Way && m_ways.find(element.m_id) != m_ways.end()) { // Exclude ferry routes. - if (find(element.Tags().begin(), element.Tags().end(), m_ferryTag) == element.Tags().end()) + static OsmElement::Tag const kFerryTag = {"route", "ferry"}; + if (find(element.Tags().begin(), element.Tags().end(), kFerryTag) == element.Tags().end()) element.AddTag("highway", m_ways[element.m_id]); } else if (element.m_type == OsmElement::EntityType::Node && m_capitals.find(element.m_id) != m_capitals.end()) @@ -136,7 +136,6 @@ public: private: std::map m_ways; std::set m_capitals; - OsmElement::Tag m_ferryTag; }; class TagReplacer @@ -144,7 +143,7 @@ class TagReplacer public: TagReplacer() = default; - TagReplacer(std::string const & filePath) + explicit TagReplacer(std::string const & filePath) { std::ifstream stream(filePath); @@ -209,7 +208,7 @@ class OsmTagMixer public: OsmTagMixer() = default; - OsmTagMixer(std::string const & filePath) + explicit OsmTagMixer(std::string const & filePath) { std::ifstream stream(filePath); std::vector values; @@ -237,10 +236,7 @@ public: } if (!tags.empty()) - { - std::pair elementPair = {entityType, id}; - m_elements[elementPair].swap(tags); - } + m_elements[{entityType, id}].swap(tags); } } @@ -256,8 +252,7 @@ public: void operator()(OsmElement & element) { - std::pair elementId = {element.m_type, element.m_id}; - auto elements = m_elements.find(elementId); + auto elements = m_elements.find({element.m_type, element.m_id}); if (elements != m_elements.end()) { for (OsmElement::Tag tag : elements->second) diff --git a/generator/translator.hpp b/generator/translator.hpp index c4693cd206..1b050557dc 100644 --- a/generator/translator.hpp +++ b/generator/translator.hpp @@ -55,6 +55,12 @@ protected: return std::make_shared(processor, cache, featureMaker, filter, collector); } + void MergeIntoBase(Translator & other) const + { + other.m_collector->Merge(*m_collector); + other.m_processor->Merge(*m_processor); + } + std::shared_ptr m_filter; std::shared_ptr m_collector; RelationTagsEnricher m_tagsEnricher; diff --git a/generator/translator_coastline.cpp b/generator/translator_coastline.cpp index 7e3265a7fe..e3ec0ba3a7 100644 --- a/generator/translator_coastline.cpp +++ b/generator/translator_coastline.cpp @@ -14,8 +14,6 @@ #include "base/file_name_utils.hpp" -#include - #include "defines.hpp" using namespace feature; @@ -65,7 +63,6 @@ void TranslatorCoastline::Merge(TranslatorInterface const & other) void TranslatorCoastline::MergeInto(TranslatorCoastline & other) const { - other.m_collector->Merge(*m_collector); - other.m_processor->Merge(*m_processor); + MergeIntoBase(other); } } // namespace generator diff --git a/generator/translator_coastline.hpp b/generator/translator_coastline.hpp index eb15121944..b026d251b8 100644 --- a/generator/translator_coastline.hpp +++ b/generator/translator_coastline.hpp @@ -28,10 +28,9 @@ public: std::shared_ptr Clone() const override; void Merge(TranslatorInterface const & other) override; + void MergeInto(TranslatorCoastline & other) const override; protected: using Translator::Translator; - - void MergeInto(TranslatorCoastline & other) const override; }; } // namespace generator diff --git a/generator/translator_collection.cpp b/generator/translator_collection.cpp index 1fd3a17f79..aeb3ef9401 100644 --- a/generator/translator_collection.cpp +++ b/generator/translator_collection.cpp @@ -38,14 +38,14 @@ bool TranslatorCollection::Save() }); } -void TranslatorCollection::Merge(TranslatorInterface const & collector) +void TranslatorCollection::Merge(TranslatorInterface const & other) { - collector.MergeInto(*this); + other.MergeInto(*this); } -void TranslatorCollection::MergeInto(TranslatorCollection & collector) const +void TranslatorCollection::MergeInto(TranslatorCollection & other) const { - auto & otherCollection = collector.m_collection; + auto & otherCollection = other.m_collection; CHECK_EQUAL(m_collection.size(), otherCollection.size(), ()); for (size_t i = 0; i < m_collection.size(); ++i) otherCollection[i]->Merge(*m_collection[i]); diff --git a/generator/translator_country.cpp b/generator/translator_country.cpp index aae6c6d324..4e2113d450 100644 --- a/generator/translator_country.cpp +++ b/generator/translator_country.cpp @@ -124,8 +124,7 @@ void TranslatorCountry::Merge(TranslatorInterface const & other) void TranslatorCountry::MergeInto(TranslatorCountry & other) const { - other.m_collector->Merge(*m_collector); - other.m_processor->Merge(*m_processor); + MergeIntoBase(other); } void TranslatorCountry::CollectFromRelations(OsmElement const & element) diff --git a/generator/translator_geo_objects.cpp b/generator/translator_geo_objects.cpp index 0d06dd7805..dc54bea6b5 100644 --- a/generator/translator_geo_objects.cpp +++ b/generator/translator_geo_objects.cpp @@ -32,7 +32,6 @@ void TranslatorGeoObjects::Merge(TranslatorInterface const & other) void TranslatorGeoObjects::MergeInto(TranslatorGeoObjects & other) const { - other.m_collector->Merge(*m_collector); - other.m_processor->Merge(*m_processor); + MergeIntoBase(other); } } // namespace generator diff --git a/generator/translator_region.cpp b/generator/translator_region.cpp index c22de980b0..dafec39007 100644 --- a/generator/translator_region.cpp +++ b/generator/translator_region.cpp @@ -74,7 +74,6 @@ void TranslatorRegion::Merge(TranslatorInterface const & other) void TranslatorRegion::MergeInto(TranslatorRegion & other) const { - other.m_collector->Merge(*m_collector); - other.m_processor->Merge(*m_processor); + MergeIntoBase(other); } } // namespace generator diff --git a/generator/translator_streets.cpp b/generator/translator_streets.cpp index 6147079e7c..9aed1fd97b 100644 --- a/generator/translator_streets.cpp +++ b/generator/translator_streets.cpp @@ -28,7 +28,6 @@ void TranslatorStreets::Merge(TranslatorInterface const & other) void TranslatorStreets::MergeInto(TranslatorStreets & other) const { - other.m_collector->Merge(*m_collector); - other.m_processor->Merge(*m_processor); + MergeIntoBase(other); } } // namespace generator diff --git a/generator/translator_world.cpp b/generator/translator_world.cpp index 6a794463bb..caf1ad366e 100644 --- a/generator/translator_world.cpp +++ b/generator/translator_world.cpp @@ -5,6 +5,7 @@ #include "generator/filter_collection.hpp" #include "generator/filter_planet.hpp" #include "generator/filter_elements.hpp" +#include "generator/filter_world.hpp" #include "generator/generate_info.hpp" #include "generator/intermediate_data.hpp" #include "generator/node_mixer.hpp" @@ -56,8 +57,7 @@ void TranslatorWorld::Merge(TranslatorInterface const & other) void TranslatorWorld::MergeInto(TranslatorWorld & other) const { - other.m_collector->Merge(*m_collector); - other.m_processor->Merge(*m_processor); + MergeIntoBase(other); } TranslatorWorldWithAds::TranslatorWorldWithAds(std::shared_ptr const & processor, diff --git a/generator/ways_merger.cpp b/generator/ways_merger.cpp index 1552758ec1..3a4de9affe 100644 --- a/generator/ways_merger.cpp +++ b/generator/ways_merger.cpp @@ -2,7 +2,7 @@ namespace generator { -AreaWayMerger::AreaWayMerger( std::shared_ptr const & cache) : +AreaWayMerger::AreaWayMerger(std::shared_ptr const & cache) : m_cache(cache) { }