diff --git a/generator/translator.cpp b/generator/translator.cpp index 776e13a82c..0b5403f3e3 100644 --- a/generator/translator.cpp +++ b/generator/translator.cpp @@ -1,8 +1,7 @@ #include "generator/translator.hpp" -#include "generator/collector_interface.hpp" -#include "generator/emitter_interface.hpp" -#include "generator/intermediate_data.hpp" +#include "generator/collector_collection.hpp" +#include "generator/filter_collection.hpp" #include "generator/osm_element.hpp" #include "base/assert.hpp" @@ -11,62 +10,67 @@ using namespace feature; namespace generator { -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(cache) +Translator::Translator(std::shared_ptr const & processor, + std::shared_ptr const & cache, + std::shared_ptr const & maker, + std::shared_ptr const & filter, + std::shared_ptr const & collector) + : m_filter(filter) + , m_collector(collector) + , m_tagsEnricher(cache->GetCache()) , m_featureMaker(maker) - , m_emitter(emitter) + , m_processor(processor) , m_cache(cache) { - CHECK(m_emitter, ()); + m_featureMaker->SetCache(cache); } -Translator::Translator(std::shared_ptr emitter, cache::IntermediateDataReader & cache, - std::shared_ptr maker) - : Translator(emitter, cache, maker, {} /* filters */, {} /* collectors */) {} +Translator::Translator(std::shared_ptr const & processor, + std::shared_ptr const & cache, + std::shared_ptr const & maker) + : Translator(processor, cache, maker, std::make_shared(), std::make_shared()) +{ +} + +void Translator::SetCollector(std::shared_ptr const & collector) +{ + m_collector = collector; +} + +void Translator::SetFilter(std::shared_ptr const & filter) +{ + m_filter = filter; +} void Translator::Emit(OsmElement & element) { - if (!m_filters.IsAccepted(element)) + if (!m_filter->IsAccepted(element)) return; Preprocess(element); m_tagsEnricher(element); - m_collectors.Collect(element); + m_collector->Collect(element); m_featureMaker->Add(element); FeatureBuilder feature; while (m_featureMaker->GetNextFeature(feature)) { - if (!m_filters.IsAccepted(feature)) + if (!m_filter->IsAccepted(feature)) continue; - m_collectors.CollectFeature(feature, element); - m_emitter->Process(feature); + m_collector->CollectFeature(feature, element); + m_processor->Process(feature); } } -bool Translator::Finish() +void Translator::Finish() { - m_collectors.Finish(); - m_collectors.Save(); - return m_emitter->Finish(); + m_collector->Finish(); + m_processor->Finish(); } -void Translator::GetNames(std::vector & names) const +bool Translator::Save() { - m_emitter->GetNames(names); -} - -void Translator::AddCollector(std::shared_ptr collector) -{ - m_collectors.Append(collector); -} - -void Translator::AddFilter(std::shared_ptr filter) -{ - m_filters.Append(filter); + m_collector->Save(); + return true; } } // namespace generator diff --git a/generator/translator.hpp b/generator/translator.hpp index f9fa82eb02..c4693cd206 100644 --- a/generator/translator.hpp +++ b/generator/translator.hpp @@ -1,9 +1,10 @@ #pragma once -#include "generator/collector_collection.hpp" +#include "generator/collector_interface.hpp" #include "generator/feature_maker_base.hpp" -#include "generator/filter_collection.hpp" #include "generator/filter_interface.hpp" +#include "generator/intermediate_data.hpp" +#include "generator/processor_interface.hpp" #include "generator/relation_tags_enricher.hpp" #include "generator/translator_interface.hpp" @@ -15,39 +16,50 @@ struct OsmElement; namespace generator { -class EmitterInterface; -class CollectorInterface; - namespace cache { -class IntermediateDataReader; +class IntermediateData; } // namespace cache -// Implementing this base class allows an object to create FeatureBuilder1 from OsmElement and then process it. +// Implementing this base class allows an object to create FeatureBuilder from OsmElement and then process it. // You can add any collectors and filters. class Translator : public TranslatorInterface { public: - 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 & cache, - std::shared_ptr maker); + explicit Translator(std::shared_ptr const & processor, + std::shared_ptr const & cache, + std::shared_ptr const & maker, + std::shared_ptr const & filter, + std::shared_ptr const & collector); + explicit Translator(std::shared_ptr const & processor, + std::shared_ptr const & cache, + std::shared_ptr const & maker); + + void SetCollector(std::shared_ptr const & collector); + void SetFilter(std::shared_ptr const & filter); // TranslatorInterface overrides: void Emit(OsmElement & element) override; - bool Finish() override; - void GetNames(std::vector & names) const override; - - void AddCollector(std::shared_ptr collector); - void AddFilter(std::shared_ptr filter); + void Finish() override; + bool Save() override; protected: - FilterCollection m_filters; - CollectorCollection m_collectors; + template + decltype(auto) CloneBase() const + { + auto cache = m_cache->Clone(); + auto processor = m_processor->Clone(); + auto featureMaker = m_featureMaker->Clone(); + auto filter = m_filter->Clone(); + auto collector = m_collector->Clone(cache->GetCache()); + return std::make_shared(processor, cache, featureMaker, filter, collector); + } + + std::shared_ptr m_filter; + std::shared_ptr m_collector; RelationTagsEnricher m_tagsEnricher; std::shared_ptr m_featureMaker; - std::shared_ptr m_emitter; - cache::IntermediateDataReader & m_cache; + std::shared_ptr m_processor; + std::shared_ptr m_cache; }; } // namespace generator diff --git a/generator/translator_coastline.cpp b/generator/translator_coastline.cpp index b70f41d14a..7e3265a7fe 100644 --- a/generator/translator_coastline.cpp +++ b/generator/translator_coastline.cpp @@ -1,6 +1,8 @@ #include "generator/translator_coastline.hpp" +#include "generator/collector_interface.hpp" #include "generator/feature_maker.hpp" +#include "generator/filter_collection.hpp" #include "generator/filter_elements.hpp" #include "generator/filter_planet.hpp" #include "generator/generate_info.hpp" @@ -12,6 +14,8 @@ #include "base/file_name_utils.hpp" +#include + #include "defines.hpp" using namespace feature; @@ -37,12 +41,31 @@ public: }; } // namespace -TranslatorCoastline::TranslatorCoastline(std::shared_ptr emitter, - cache::IntermediateDataReader & cache) - : Translator(emitter, cache, std::make_shared(cache)) +TranslatorCoastline::TranslatorCoastline(std::shared_ptr const & processor, + std::shared_ptr const & cache) + : Translator(processor, cache, std::make_shared(cache)) { - AddFilter(std::make_shared()); - AddFilter(std::make_shared()); - AddFilter(std::make_shared(base::JoinPath(GetPlatform().ResourcesDir(), SKIPPED_ELEMENTS_FILE))); + auto filters = std::make_shared(); + filters->Append(std::make_shared()); + filters->Append(std::make_shared()); + filters->Append(std::make_shared(base::JoinPath(GetPlatform().ResourcesDir(), SKIPPED_ELEMENTS_FILE))); + SetFilter(filters); +} + +std::shared_ptr +TranslatorCoastline::Clone() const +{ + return Translator::CloneBase(); +} + +void TranslatorCoastline::Merge(TranslatorInterface const & other) +{ + other.MergeInto(*this); +} + +void TranslatorCoastline::MergeInto(TranslatorCoastline & other) const +{ + other.m_collector->Merge(*m_collector); + other.m_processor->Merge(*m_processor); } } // namespace generator diff --git a/generator/translator_coastline.hpp b/generator/translator_coastline.hpp index d4467320e9..eb15121944 100644 --- a/generator/translator_coastline.hpp +++ b/generator/translator_coastline.hpp @@ -1,6 +1,6 @@ #pragma once -#include "generator/emitter_interface.hpp" +#include "generator/processor_interface.hpp" #include "generator/translator.hpp" #include @@ -12,7 +12,7 @@ struct GenerateInfo; namespace cache { -class IntermediateDataReader; +class IntermediateData; } // namespace cache namespace generator @@ -21,7 +21,17 @@ namespace generator class TranslatorCoastline : public Translator { public: - explicit TranslatorCoastline(std::shared_ptr emitter, - cache::IntermediateDataReader & cache); + explicit TranslatorCoastline(std::shared_ptr const & processor, + std::shared_ptr const & cache); + + // TranslatorInterface overrides: + std::shared_ptr Clone() const override; + + void Merge(TranslatorInterface const & other) 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 c63e847e88..1fd3a17f79 100644 --- a/generator/translator_collection.cpp +++ b/generator/translator_collection.cpp @@ -7,6 +7,15 @@ namespace generator { +std::shared_ptr +TranslatorCollection::Clone() const +{ + auto p = std::make_shared(); + for (auto const & c : m_collection) + p->Append(c->Clone()); + return p; +} + void TranslatorCollection::Emit(OsmElement /* const */ & element) { for (auto & t : m_collection) @@ -16,20 +25,29 @@ void TranslatorCollection::Emit(OsmElement /* const */ & element) } } -bool TranslatorCollection::Finish() +void TranslatorCollection::Finish() +{ + for (auto & t : m_collection) + t->Finish(); +} + +bool TranslatorCollection::Save() { return std::all_of(std::begin(m_collection), std::end(m_collection), [](auto & t) { - return t->Finish(); + return t->Save(); }); } -void TranslatorCollection::GetNames(std::vector & names) const +void TranslatorCollection::Merge(TranslatorInterface const & collector) { - for (auto & t : m_collection) - { - std::vector temp; - t->GetNames(temp); - std::move(std::begin(temp), std::end(temp), std::back_inserter(names)); - } + collector.MergeInto(*this); +} + +void TranslatorCollection::MergeInto(TranslatorCollection & collector) const +{ + auto & otherCollection = collector.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]); } } // namespace generator diff --git a/generator/translator_collection.hpp b/generator/translator_collection.hpp index 3bf45cbf2f..66a867d27d 100644 --- a/generator/translator_collection.hpp +++ b/generator/translator_collection.hpp @@ -12,8 +12,14 @@ class TranslatorCollection : public CollectionBase Clone() const override; + void Emit(OsmElement /* const */ & element) override; - bool Finish() override; - void GetNames(std::vector & names) const override; + + void Finish() override; + bool Save() override; + + void Merge(TranslatorInterface const & other) override; + void MergeInto(TranslatorCollection & other) const override; }; } // namespace generator diff --git a/generator/translator_country.cpp b/generator/translator_country.cpp index bbbc33a68f..aae6c6d324 100644 --- a/generator/translator_country.cpp +++ b/generator/translator_country.cpp @@ -2,9 +2,12 @@ #include "generator/collector_addresses.hpp" #include "generator/collector_camera.hpp" +#include "generator/collector_city_area.hpp" +#include "generator/collector_collection.hpp" #include "generator/collector_interface.hpp" #include "generator/collector_tag.hpp" #include "generator/feature_maker.hpp" +#include "generator/filter_collection.hpp" #include "generator/filter_elements.hpp" #include "generator/filter_planet.hpp" #include "generator/generate_info.hpp" @@ -22,6 +25,7 @@ #include #include +#include #include #include "defines.hpp" @@ -33,19 +37,20 @@ namespace class RelationCollector { public: - explicit RelationCollector(CollectorCollection & collectors) : m_collectors(collectors) {} + explicit RelationCollector(std::shared_ptr const & collectors) + : m_collectors(collectors) {} template base::ControlFlow operator()(uint64_t id, Reader & reader) { RelationElement element; CHECK(reader.Read(id, element), (id)); - m_collectors.CollectRelation(element); + m_collectors->CollectRelation(element); return base::ControlFlow::Continue; } private: - CollectorInterface & m_collectors; + std::shared_ptr m_collectors; }; // https://www.wikidata.org/wiki/Wikidata:Identifiers @@ -69,27 +74,40 @@ bool WikiDataValidator(std::string const & tagValue) } } // namespace -TranslatorCountry::TranslatorCountry(std::shared_ptr emitter, cache::IntermediateDataReader & cache, +TranslatorCountry::TranslatorCountry(std::shared_ptr const & processor, + std::shared_ptr const & cache, feature::GenerateInfo const & info) - : Translator(emitter, cache, std::make_shared(cache)) + : Translator(processor, cache, std::make_shared(cache)) , m_tagAdmixer(info.GetIntermediateFileName("ways", ".csv"), info.GetIntermediateFileName("towns", ".csv")) , m_tagReplacer(base::JoinPath(GetPlatform().ResourcesDir(), REPLACED_TAGS_FILE)) { - AddFilter(std::make_shared()); - AddFilter(std::make_shared(base::JoinPath(GetPlatform().ResourcesDir(), SKIPPED_ELEMENTS_FILE))); + auto filters = std::make_shared(); + filters->Append(std::make_shared()); + filters->Append(std::make_shared(base::JoinPath(GetPlatform().ResourcesDir(), SKIPPED_ELEMENTS_FILE))); + SetFilter(filters); - AddCollector(std::make_shared(info.GetIntermediateFileName(METALINES_FILENAME))); + auto collectors = std::make_shared(); + collectors->Append(std::make_shared(info.GetIntermediateFileName(METALINES_FILENAME))); + collectors->Append(std::make_shared(info.GetIntermediateFileName(CITIES_AREAS_TMP_FILENAME))); // These are the four collector that collect additional information for the future building of routing section. - AddCollector(std::make_shared(info.GetIntermediateFileName(MAXSPEEDS_FILENAME))); - AddCollector(std::make_shared(info.GetIntermediateFileName(RESTRICTIONS_FILENAME), - std::shared_ptr(&cache, [](cache::IntermediateDataReader *) {}))); - AddCollector(std::make_shared(info.GetIntermediateFileName(ROAD_ACCESS_FILENAME))); - AddCollector(std::make_shared(info.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME))); - + collectors->Append(std::make_shared(info.GetIntermediateFileName(MAXSPEEDS_FILENAME))); + collectors->Append(std::make_shared(info.GetIntermediateFileName(RESTRICTIONS_FILENAME), cache->GetCache())); + collectors->Append(std::make_shared(info.GetIntermediateFileName(ROAD_ACCESS_FILENAME))); + collectors->Append(std::make_shared(info.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME))); if (info.m_genAddresses) - AddCollector(std::make_shared(info.GetAddressesFileName())); + collectors->Append(std::make_shared(info.GetAddressesFileName())); if (!info.m_idToWikidataFilename.empty()) - AddCollector(std::make_shared(info.m_idToWikidataFilename, "wikidata" /* tagKey */, WikiDataValidator)); + collectors->Append(std::make_shared(info.m_idToWikidataFilename, "wikidata" /* tagKey */, WikiDataValidator)); + SetCollector(collectors); +} + +std::shared_ptr +TranslatorCountry::Clone() const +{ + auto copy = Translator::CloneBase(); + copy->m_tagAdmixer = m_tagAdmixer; + copy->m_tagReplacer = m_tagReplacer; + return copy; } void TranslatorCountry::Preprocess(OsmElement & element) @@ -99,20 +117,44 @@ void TranslatorCountry::Preprocess(OsmElement & element) CollectFromRelations(element); } -void TranslatorCountry::CollectFromRelations(OsmElement const & element) +void TranslatorCountry::Merge(TranslatorInterface const & other) { - RelationCollector collector(m_collectors); - if (element.IsNode()) - m_cache.ForEachRelationByNodeCached(element.m_id, collector); - else if (element.IsWay()) - m_cache.ForEachRelationByWayCached(element.m_id, collector); + other.MergeInto(*this); } -TranslatorCountryWithAds::TranslatorCountryWithAds(std::shared_ptr emitter, - cache::IntermediateDataReader & cache, +void TranslatorCountry::MergeInto(TranslatorCountry & other) const +{ + other.m_collector->Merge(*m_collector); + other.m_processor->Merge(*m_processor); +} + +void TranslatorCountry::CollectFromRelations(OsmElement const & element) +{ + auto const & cache = m_cache->GetCache(); + RelationCollector collector(m_collector); + if (element.IsNode()) + cache->ForEachRelationByNodeCached(element.m_id, collector); + else if (element.IsWay()) + cache->ForEachRelationByWayCached(element.m_id, collector); +} + +TranslatorCountryWithAds::TranslatorCountryWithAds(std::shared_ptr const & processor, + std::shared_ptr const & cache, feature::GenerateInfo const & info) - : TranslatorCountry(emitter, cache, info) - , m_osmTagMixer(base::JoinPath(GetPlatform().ResourcesDir(), MIXED_TAGS_FILE)) {} + : TranslatorCountry(processor, cache, info) + , m_osmTagMixer(base::JoinPath(GetPlatform().ResourcesDir(), MIXED_TAGS_FILE)) +{ +} + +std::shared_ptr +TranslatorCountryWithAds::Clone() const +{ + auto copy = Translator::CloneBase(); + copy->m_tagAdmixer = m_tagAdmixer; + copy->m_tagReplacer = m_tagReplacer; + copy->m_osmTagMixer = m_osmTagMixer; + return copy; +} void TranslatorCountryWithAds::Preprocess(OsmElement & element) { @@ -121,10 +163,20 @@ void TranslatorCountryWithAds::Preprocess(OsmElement & element) TranslatorCountry::Preprocess(element); } -bool TranslatorCountryWithAds::Finish() +bool TranslatorCountryWithAds::Save() { MixFakeNodes(GetPlatform().ResourcesDir() + MIXED_NODES_FILE, std::bind(&TranslatorCountryWithAds::Emit, this, std::placeholders::_1)); - return TranslatorCountry::Finish(); + return TranslatorCountry::Save(); +} + +void TranslatorCountryWithAds::Merge(TranslatorInterface const & other) +{ + TranslatorCountry::Merge(other); +} + +void TranslatorCountryWithAds::MergeInto(TranslatorCountryWithAds & other) const +{ + TranslatorCountry::MergeInto(other); } } // namespace generator diff --git a/generator/translator_country.hpp b/generator/translator_country.hpp index ab4d1d9112..f5e4e57227 100644 --- a/generator/translator_country.hpp +++ b/generator/translator_country.hpp @@ -1,6 +1,6 @@ #pragma once -#include "generator/emitter_interface.hpp" +#include "generator/processor_interface.hpp" #include "generator/tag_admixer.hpp" #include "generator/translator.hpp" @@ -13,7 +13,7 @@ struct GenerateInfo; namespace cache { -class IntermediateDataReader; +class IntermediateData; } // namespace cache namespace generator @@ -21,14 +21,22 @@ namespace generator // The TranslatorArea class implements translator for building countries. class TranslatorCountry : public Translator { -public: - explicit TranslatorCountry(std::shared_ptr emitter, cache::IntermediateDataReader & cache, +public: + explicit TranslatorCountry(std::shared_ptr const & processor, + std::shared_ptr const & cache, feature::GenerateInfo const & info); // TranslatorInterface overrides: void Preprocess(OsmElement & element) override; -private: + std::shared_ptr Clone() const override; + + void Merge(TranslatorInterface const & other) override; + void MergeInto(TranslatorCountry & other) const override; + +protected: + using Translator::Translator; + void CollectFromRelations(OsmElement const & element); TagAdmixer m_tagAdmixer; @@ -39,15 +47,22 @@ private: class TranslatorCountryWithAds : public TranslatorCountry { public: - explicit TranslatorCountryWithAds(std::shared_ptr emitter, - cache::IntermediateDataReader & cache, + explicit TranslatorCountryWithAds(std::shared_ptr const & processor, + std::shared_ptr const & cache, feature::GenerateInfo const & info); // TranslatorInterface overrides: void Preprocess(OsmElement & element) override; - bool Finish() override; + bool Save() override; + + std::shared_ptr Clone() const override; + + void Merge(TranslatorInterface const & other) override; + void MergeInto(TranslatorCountryWithAds & other) const override; + +protected: + using TranslatorCountry::TranslatorCountry; -private: OsmTagMixer m_osmTagMixer; }; } // namespace generator diff --git a/generator/translator_geo_objects.cpp b/generator/translator_geo_objects.cpp index 7b28e38724..0d06dd7805 100644 --- a/generator/translator_geo_objects.cpp +++ b/generator/translator_geo_objects.cpp @@ -1,6 +1,8 @@ #include "generator/translator_geo_objects.hpp" +#include "generator/collector_interface.hpp" #include "generator/feature_maker.hpp" +#include "generator/filter_collection.hpp" #include "generator/filter_interface.hpp" #include "generator/geo_objects/geo_objects_filter.hpp" #include "generator/intermediate_data.hpp" @@ -9,11 +11,28 @@ namespace generator { -TranslatorGeoObjects::TranslatorGeoObjects(std::shared_ptr emitter, - cache::IntermediateDataReader & cache) - : Translator(emitter, cache, std::make_shared(cache)) +TranslatorGeoObjects::TranslatorGeoObjects(std::shared_ptr const & processor, + std::shared_ptr const & cache) + : Translator(processor, cache, std::make_shared(cache)) { - AddFilter(std::make_shared()); + SetFilter(std::make_shared()); +} + +std::shared_ptr +TranslatorGeoObjects::Clone() const +{ + return Translator::CloneBase(); +} + +void TranslatorGeoObjects::Merge(TranslatorInterface const & other) +{ + other.MergeInto(*this); +} + +void TranslatorGeoObjects::MergeInto(TranslatorGeoObjects & other) const +{ + other.m_collector->Merge(*m_collector); + other.m_processor->Merge(*m_processor); } } // namespace generator diff --git a/generator/translator_geo_objects.hpp b/generator/translator_geo_objects.hpp index fb40cbad9e..3c0c9e83ff 100644 --- a/generator/translator_geo_objects.hpp +++ b/generator/translator_geo_objects.hpp @@ -1,13 +1,13 @@ #pragma once -#include "generator/emitter_interface.hpp" +#include "generator/processor_interface.hpp" #include "generator/translator.hpp" #include namespace cache { -class IntermediateDataReader; +class IntermediateData; } // namespace cache namespace generator @@ -17,7 +17,16 @@ namespace generator class TranslatorGeoObjects : public Translator { public: - explicit TranslatorGeoObjects(std::shared_ptr emitter, - cache::IntermediateDataReader & cache); + explicit TranslatorGeoObjects(std::shared_ptr const & processor, + std::shared_ptr const & cache); + + // TranslatorInterface overrides: + std::shared_ptr Clone() const override; + + void Merge(TranslatorInterface const & other) override; + void MergeInto(TranslatorGeoObjects & other) const override; + +protected: + using Translator::Translator; }; } // namespace generator diff --git a/generator/translator_interface.hpp b/generator/translator_interface.hpp index 8a62906b15..79c7391a9b 100644 --- a/generator/translator_interface.hpp +++ b/generator/translator_interface.hpp @@ -1,5 +1,8 @@ #pragma once +#include "base/assert.hpp" + +#include #include #include @@ -7,15 +10,47 @@ struct OsmElement; namespace generator { +namespace cache +{ +class IntermediateData; +} // namespace cache + +class TranslatorRegion; +class TranslatorGeoObjects; +class TranslatorCountry; +class TranslatorCountryWithAds; +class TranslatorCoastline; +class TranslatorWorld; +class TranslatorWorldWithAds; +class TranslatorStreets; +class TranslatorCollection; + // Implementing this interface allows an object to create intermediate data from OsmElement. class TranslatorInterface { public: virtual ~TranslatorInterface() = default; + virtual std::shared_ptr Clone() const = 0; + virtual void Preprocess(OsmElement &) {} virtual void Emit(OsmElement & element) = 0; - virtual bool Finish() = 0; - virtual void GetNames(std::vector & names) const = 0; + virtual void Finish() = 0; + virtual bool Save() = 0; + + virtual void Merge(TranslatorInterface const &) = 0; + + virtual void MergeInto(TranslatorRegion &) const { FailIfMethodUnsupported(); } + virtual void MergeInto(TranslatorGeoObjects &) const { FailIfMethodUnsupported(); } + virtual void MergeInto(TranslatorCountry &) const { FailIfMethodUnsupported(); } + virtual void MergeInto(TranslatorCountryWithAds &) const { FailIfMethodUnsupported(); } + virtual void MergeInto(TranslatorCoastline &) const { FailIfMethodUnsupported(); } + virtual void MergeInto(TranslatorWorld &) const { FailIfMethodUnsupported(); } + virtual void MergeInto(TranslatorWorldWithAds &) const { FailIfMethodUnsupported(); } + virtual void MergeInto(TranslatorStreets &) const { FailIfMethodUnsupported(); } + virtual void MergeInto(TranslatorCollection &) const { FailIfMethodUnsupported(); } + +private: + void FailIfMethodUnsupported() const { CHECK(false, ("This method is unsupported.")); } }; } // namespace generator diff --git a/generator/translator_region.cpp b/generator/translator_region.cpp index b0c33584a0..c22de980b0 100644 --- a/generator/translator_region.cpp +++ b/generator/translator_region.cpp @@ -9,6 +9,7 @@ #include "generator/regions/collector_region_info.hpp" #include +#include #include #include @@ -48,14 +49,32 @@ public: }; } // namespace -TranslatorRegion::TranslatorRegion(std::shared_ptr emitter, cache::IntermediateDataReader & cache, - GenerateInfo const & info) - : Translator(emitter, cache, std::make_shared(cache)) +TranslatorRegion::TranslatorRegion(std::shared_ptr const & processor, + std::shared_ptr const & cache, + feature::GenerateInfo const & info) + : Translator(processor, cache, std::make_shared(cache)) { - AddFilter(std::make_shared()); + SetFilter(std::make_shared()); auto filename = info.GetTmpFileName(info.m_fileName, regions::CollectorRegionInfo::kDefaultExt); - AddCollector(std::make_shared(filename)); + SetCollector(std::make_shared(filename)); +} + +std::shared_ptr +TranslatorRegion::Clone() const +{ + return Translator::CloneBase(); +} + +void TranslatorRegion::Merge(TranslatorInterface const & other) +{ + other.MergeInto(*this); +} + +void TranslatorRegion::MergeInto(TranslatorRegion & other) const +{ + other.m_collector->Merge(*m_collector); + other.m_processor->Merge(*m_processor); } } // namespace generator diff --git a/generator/translator_region.hpp b/generator/translator_region.hpp index bb6b502482..ce28d8c268 100644 --- a/generator/translator_region.hpp +++ b/generator/translator_region.hpp @@ -1,6 +1,6 @@ #pragma once -#include "generator/emitter_interface.hpp" +#include "generator/processor_interface.hpp" #include "generator/translator.hpp" #include @@ -12,7 +12,7 @@ struct GenerateInfo; namespace cache { -class IntermediateDataReader; +class IntermediateData; } // namespace cache namespace generator @@ -21,7 +21,17 @@ namespace generator class TranslatorRegion : public Translator { public: - explicit TranslatorRegion(std::shared_ptr emitter, cache::IntermediateDataReader & cache, + explicit TranslatorRegion(std::shared_ptr const & processor, + std::shared_ptr const & cache, feature::GenerateInfo const & info); + + // TranslatorInterface overrides: + std::shared_ptr Clone() const override; + + void Merge(TranslatorInterface const & other) override; + void MergeInto(TranslatorRegion & other) const override; + +protected: + using Translator::Translator; }; } // namespace generator diff --git a/generator/translator_streets.cpp b/generator/translator_streets.cpp index b5f43c18de..6147079e7c 100644 --- a/generator/translator_streets.cpp +++ b/generator/translator_streets.cpp @@ -1,16 +1,34 @@ #include "generator/translator_streets.hpp" +#include "generator/collector_interface.hpp" #include "generator/feature_maker.hpp" #include "generator/streets/streets_filter.hpp" #include "generator/intermediate_data.hpp" namespace generator { -TranslatorStreets::TranslatorStreets(std::shared_ptr emitter, - cache::IntermediateDataReader & cache) - : Translator(emitter, cache, std::make_shared(cache)) +TranslatorStreets::TranslatorStreets(std::shared_ptr const & processor, + std::shared_ptr const & cache) + : Translator(processor, cache, std::make_shared(cache)) { - AddFilter(std::make_shared()); + SetFilter(std::make_shared()); +} + +std::shared_ptr +TranslatorStreets::Clone() const +{ + return Translator::CloneBase(); +} + +void TranslatorStreets::Merge(TranslatorInterface const & other) +{ + other.MergeInto(*this); +} + +void TranslatorStreets::MergeInto(TranslatorStreets & other) const +{ + other.m_collector->Merge(*m_collector); + other.m_processor->Merge(*m_processor); } } // namespace generator diff --git a/generator/translator_streets.hpp b/generator/translator_streets.hpp index b34f38f9c4..9b5cf7a4a0 100644 --- a/generator/translator_streets.hpp +++ b/generator/translator_streets.hpp @@ -1,13 +1,13 @@ #pragma once -#include "generator/emitter_interface.hpp" +#include "generator/processor_interface.hpp" #include "generator/translator.hpp" #include namespace cache { -class IntermediateDataReader; +class IntermediateData; } // namespace cache namespace generator @@ -17,7 +17,16 @@ namespace generator class TranslatorStreets : public Translator { public: - explicit TranslatorStreets(std::shared_ptr emitter, - cache::IntermediateDataReader & cache); + explicit TranslatorStreets(std::shared_ptr const & processor, + std::shared_ptr const & cache); + + // TranslatorInterface overrides: + std::shared_ptr Clone() const override; + + void Merge(TranslatorInterface const & other) override; + void MergeInto(TranslatorStreets & other) const override; + +protected: + using Translator::Translator; }; } // namespace generator diff --git a/generator/translator_world.cpp b/generator/translator_world.cpp index 298c486756..6a794463bb 100644 --- a/generator/translator_world.cpp +++ b/generator/translator_world.cpp @@ -1,6 +1,8 @@ #include "generator/translator_world.hpp" +#include "generator/collector_interface.hpp" #include "generator/feature_maker.hpp" +#include "generator/filter_collection.hpp" #include "generator/filter_planet.hpp" #include "generator/filter_elements.hpp" #include "generator/generate_info.hpp" @@ -11,18 +13,33 @@ #include "base/file_name_utils.hpp" +#include +#include + #include "defines.hpp" namespace generator { -TranslatorWorld::TranslatorWorld(std::shared_ptr emitter, cache::IntermediateDataReader & cache, +TranslatorWorld::TranslatorWorld(std::shared_ptr const & processor, + std::shared_ptr const & cache, feature::GenerateInfo const & info) - : Translator(emitter, cache, std::make_shared(cache)) + : Translator(processor, cache, std::make_shared(cache)) , m_tagAdmixer(info.GetIntermediateFileName("ways", ".csv"), info.GetIntermediateFileName("towns", ".csv")) , m_tagReplacer(GetPlatform().ResourcesDir() + REPLACED_TAGS_FILE) { - AddFilter(std::make_shared()); - AddFilter(std::make_shared(base::JoinPath(GetPlatform().ResourcesDir(), SKIPPED_ELEMENTS_FILE))); + auto filters = std::make_shared(); + filters->Append(std::make_shared()); + filters->Append(std::make_shared(base::JoinPath(GetPlatform().ResourcesDir(), SKIPPED_ELEMENTS_FILE))); + SetFilter(filters); +} + +std::shared_ptr +TranslatorWorld::Clone() const +{ + auto copy = Translator::CloneBase(); + copy->m_tagAdmixer = m_tagAdmixer; + copy->m_tagReplacer = m_tagReplacer; + return copy; } void TranslatorWorld::Preprocess(OsmElement & element) @@ -32,11 +49,34 @@ void TranslatorWorld::Preprocess(OsmElement & element) m_tagAdmixer(element); } -TranslatorWorldWithAds::TranslatorWorldWithAds(std::shared_ptr emitter, - cache::IntermediateDataReader & cache, +void TranslatorWorld::Merge(TranslatorInterface const & other) +{ + other.MergeInto(*this); +} + +void TranslatorWorld::MergeInto(TranslatorWorld & other) const +{ + other.m_collector->Merge(*m_collector); + other.m_processor->Merge(*m_processor); +} + +TranslatorWorldWithAds::TranslatorWorldWithAds(std::shared_ptr const & processor, + std::shared_ptr const & cache, feature::GenerateInfo const & info) - : TranslatorWorld(emitter, cache, info) - , m_osmTagMixer(base::JoinPath(GetPlatform().ResourcesDir(), MIXED_TAGS_FILE)) {} + : TranslatorWorld(processor, cache, info) + , m_osmTagMixer(base::JoinPath(GetPlatform().ResourcesDir(), MIXED_TAGS_FILE)) +{ +} + +std::shared_ptr +TranslatorWorldWithAds::Clone() const +{ + auto copy = Translator::CloneBase(); + copy->m_tagAdmixer = m_tagAdmixer; + copy->m_tagReplacer = m_tagReplacer; + copy->m_osmTagMixer = m_osmTagMixer; + return copy; +} void TranslatorWorldWithAds::Preprocess(OsmElement & element) { @@ -45,10 +85,20 @@ void TranslatorWorldWithAds::Preprocess(OsmElement & element) TranslatorWorld::Preprocess(element); } -bool TranslatorWorldWithAds::Finish() +bool TranslatorWorldWithAds::Save() { MixFakeNodes(GetPlatform().ResourcesDir() + MIXED_NODES_FILE, std::bind(&TranslatorWorldWithAds::Emit, this, std::placeholders::_1)); - return TranslatorWorld::Finish(); + return TranslatorWorld::Save(); +} + +void TranslatorWorldWithAds::Merge(TranslatorInterface const & other) +{ + TranslatorWorld::Merge(other); +} + +void TranslatorWorldWithAds::MergeInto(TranslatorWorldWithAds & other) const +{ + TranslatorWorld::MergeInto(other); } } // namespace generator diff --git a/generator/translator_world.hpp b/generator/translator_world.hpp index 565fc113b7..6ca0ae7955 100644 --- a/generator/translator_world.hpp +++ b/generator/translator_world.hpp @@ -1,6 +1,6 @@ #pragma once -#include "generator/emitter_interface.hpp" +#include "generator/processor_interface.hpp" #include "generator/tag_admixer.hpp" #include "generator/translator.hpp" @@ -13,7 +13,7 @@ struct GenerateInfo; namespace cache { -class IntermediateDataReader; +class IntermediateData; } // namespace cache namespace generator @@ -22,13 +22,21 @@ namespace generator class TranslatorWorld : public Translator { public: - explicit TranslatorWorld(std::shared_ptr emitter, cache::IntermediateDataReader & cache, + explicit TranslatorWorld(std::shared_ptr const & processor, + std::shared_ptr const & cache, feature::GenerateInfo const & info); // TranslatorInterface overrides: void Preprocess(OsmElement & element) override; -private: + std::shared_ptr Clone() const override; + + void Merge(TranslatorInterface const & other) override; + void MergeInto(TranslatorWorld & other) const override; + +protected: + using Translator::Translator; + TagAdmixer m_tagAdmixer; TagReplacer m_tagReplacer; }; @@ -37,15 +45,22 @@ private: class TranslatorWorldWithAds : public TranslatorWorld { public: - explicit TranslatorWorldWithAds(std::shared_ptr emitter, - cache::IntermediateDataReader & cache, + explicit TranslatorWorldWithAds(std::shared_ptr const & processor, + std::shared_ptr const & cache, feature::GenerateInfo const & info); // TranslatorInterface overrides: void Preprocess(OsmElement & element) override; - bool Finish() override; + bool Save() override; + + std::shared_ptr Clone() const override; + + void Merge(TranslatorInterface const & other) override; + void MergeInto(TranslatorWorldWithAds & other) const override; + +protected: + using TranslatorWorld::TranslatorWorld; -private: OsmTagMixer m_osmTagMixer; }; } // namespace generator