diff --git a/generator/booking_dataset.cpp b/generator/booking_dataset.cpp index 64a81a88ce..1c8d0755bf 100644 --- a/generator/booking_dataset.cpp +++ b/generator/booking_dataset.cpp @@ -13,6 +13,8 @@ #include "boost/algorithm/string/replace.hpp" +using namespace feature; + namespace generator { // BookingHotel ------------------------------------------------------------------------------------ @@ -46,7 +48,7 @@ BookingHotel::BookingHotel(std::string const & src) // BookingDataset ---------------------------------------------------------------------------------- template <> -bool BookingDataset::NecessaryMatchingConditionHolds(FeatureBuilder1 const & fb) const +bool BookingDataset::NecessaryMatchingConditionHolds(FeatureBuilder const & fb) const { if (fb.GetName(StringUtf8Multilang::kDefaultCode).empty()) return false; @@ -55,17 +57,17 @@ bool BookingDataset::NecessaryMatchingConditionHolds(FeatureBuilder1 const & fb) } template <> -void BookingDataset::PreprocessMatchedOsmObject(ObjectId, FeatureBuilder1 & fb, - std::function const fn) const +void BookingDataset::PreprocessMatchedOsmObject(ObjectId, FeatureBuilder & fb, + std::function const fn) const { // Turn a hotel into a simple building. - if (fb.GetGeomType() == feature::GeomType::Area) + if (fb.GetGeomType() == GeomType::Area) { // Remove all information about the hotel. auto & meta = fb.GetMetadata(); - meta.Drop(feature::Metadata::EType::FMD_STARS); - meta.Drop(feature::Metadata::EType::FMD_WEBSITE); - meta.Drop(feature::Metadata::EType::FMD_PHONE_NUMBER); + meta.Drop(Metadata::EType::FMD_STARS); + meta.Drop(Metadata::EType::FMD_WEBSITE); + meta.Drop(Metadata::EType::FMD_PHONE_NUMBER); auto & params = fb.GetParams(); params.ClearName(); @@ -83,18 +85,18 @@ void BookingDataset::PreprocessMatchedOsmObject(ObjectId, FeatureBuilder1 & fb, template <> void BookingDataset::BuildObject(Object const & hotel, - std::function const & fn) const + std::function const & fn) const { - FeatureBuilder1 fb; + FeatureBuilder fb; fb.SetCenter(MercatorBounds::FromLatLon(hotel.m_latLon.m_lat, hotel.m_latLon.m_lon)); auto & metadata = fb.GetMetadata(); - metadata.Set(feature::Metadata::FMD_SPONSORED_ID, strings::to_string(hotel.m_id.Get())); - metadata.Set(feature::Metadata::FMD_WEBSITE, hotel.m_descUrl); - metadata.Set(feature::Metadata::FMD_RATING, strings::to_string(hotel.m_ratingUser)); - metadata.Set(feature::Metadata::FMD_STARS, strings::to_string(hotel.m_stars)); - metadata.Set(feature::Metadata::FMD_PRICE_RATE, strings::to_string(hotel.m_priceCategory)); + metadata.Set(Metadata::FMD_SPONSORED_ID, strings::to_string(hotel.m_id.Get())); + metadata.Set(Metadata::FMD_WEBSITE, hotel.m_descUrl); + metadata.Set(Metadata::FMD_RATING, strings::to_string(hotel.m_ratingUser)); + metadata.Set(Metadata::FMD_STARS, strings::to_string(hotel.m_stars)); + metadata.Set(Metadata::FMD_PRICE_RATE, strings::to_string(hotel.m_priceCategory)); auto & params = fb.GetParams(); // params.AddAddress(hotel.address); @@ -179,7 +181,7 @@ void BookingDataset::BuildObject(Object const & hotel, } template <> -BookingDataset::ObjectId BookingDataset::FindMatchingObjectIdImpl(FeatureBuilder1 const & fb) const +BookingDataset::ObjectId BookingDataset::FindMatchingObjectIdImpl(FeatureBuilder const & fb) const { auto const name = fb.GetName(StringUtf8Multilang::kDefaultCode); diff --git a/generator/booking_quality_check/booking_quality_check.cpp b/generator/booking_quality_check/booking_quality_check.cpp index 075a3f6a18..eae80da913 100644 --- a/generator/booking_quality_check/booking_quality_check.cpp +++ b/generator/booking_quality_check/booking_quality_check.cpp @@ -43,10 +43,11 @@ DEFINE_uint64(selection_size, 1000, "Selection size"); DEFINE_bool(generate, false, "Generate unmarked sample"); using namespace generator; +using namespace feature; namespace { -string PrintBuilder(FeatureBuilder1 const & fb) +string PrintBuilder(FeatureBuilder const & fb) { ostringstream s; @@ -71,9 +72,9 @@ string PrintBuilder(FeatureBuilder1 const & fb) auto const center = MercatorBounds::ToLatLon(fb.GetKeyPoint()); s << "lat: " << center.m_lat << " lon: " << center.m_lon << '\t'; - if (fb.GetGeomType() == feature::GeomType::Point) + if (fb.GetGeomType() == GeomType::Point) s << "GeomType: Point"; - else if (fb.GetGeomType() == feature::GeomType::Area) + else if (fb.GetGeomType() == GeomType::Area) s << "GeomType: Area"; else CHECK(false, ()); @@ -103,9 +104,9 @@ base::GeoObjectId ReadDebuggedPrintedOsmId(string const & str) MYTHROW(ParseError, ("Can't make osmId from string", str)); } -feature::GenerateInfo GetGenerateInfo() +GenerateInfo GetGenerateInfo() { - feature::GenerateInfo info; + GenerateInfo info; info.m_bookingDatafileName = FLAGS_booking; info.m_opentableDatafileName = FLAGS_opentable; info.m_osmFileName = FLAGS_osm; @@ -203,7 +204,7 @@ vector> ReadSampleFromFile(string const & name) template void GenerateFactors(Dataset const & dataset, - map const & features, + map const & features, vector> const & sampleItems, ostream & ost) { for (auto const & item : sampleItems) @@ -242,7 +243,7 @@ enum class DatasetType template void GenerateSample(Dataset const & dataset, - map const & features, ostream & ost) + map const & features, ostream & ost) { LOG_SHORT(LINFO, ("Num of elements:", features.size())); vector elementIndexes(features.size()); @@ -303,28 +304,28 @@ void GenerateSample(Dataset const & dataset, } template -string GetDatasetFilePath(feature::GenerateInfo const & info); +string GetDatasetFilePath(GenerateInfo const & info); template <> -string GetDatasetFilePath(feature::GenerateInfo const & info) +string GetDatasetFilePath(GenerateInfo const & info) { return info.m_bookingDatafileName; } template <> -string GetDatasetFilePath(feature::GenerateInfo const & info) +string GetDatasetFilePath(GenerateInfo const & info) { return info.m_opentableDatafileName; } template -void RunImpl(feature::GenerateInfo & info) +void RunImpl(GenerateInfo & info) { auto const & dataSetFilePath = GetDatasetFilePath(info); Dataset dataset(dataSetFilePath); LOG_SHORT(LINFO, (dataset.GetStorage().Size(), "objects are loaded from a file:", dataSetFilePath)); - map features; + map features; LOG_SHORT(LINFO, ("OSM data:", FLAGS_osm)); CacheLoader cacheLoader(info); @@ -348,7 +349,7 @@ void RunImpl(feature::GenerateInfo & info) } } -void Run(DatasetType const datasetType, feature::GenerateInfo & info) +void Run(DatasetType const datasetType, GenerateInfo & info) { switch (datasetType) { diff --git a/generator/booking_scoring.cpp b/generator/booking_scoring.cpp index 78b6baa096..7c43706c17 100644 --- a/generator/booking_scoring.cpp +++ b/generator/booking_scoring.cpp @@ -3,6 +3,8 @@ #include "generator/booking_dataset.hpp" #include "generator/feature_builder.hpp" +using namespace feature; + namespace { // Calculated with tools/python/booking_hotels_quality.py. @@ -28,7 +30,7 @@ bool MatchStats::IsMatched() const // TODO(mgsergio): Do I need to specialize this method? template <> -MatchStats Match(BookingHotel const & h, FeatureBuilder1 const & fb) +MatchStats Match(BookingHotel const & h, FeatureBuilder const & fb) { MatchStats score; diff --git a/generator/boost_helpers.hpp b/generator/boost_helpers.hpp index e116b8cb47..c8c7ad2777 100644 --- a/generator/boost_helpers.hpp +++ b/generator/boost_helpers.hpp @@ -19,7 +19,7 @@ void FillBoostGeometry(BoostGeometry & geometry, FbGeometry const & fbGeometry) } template -void FillPolygon(BoostPolygon & polygon, FeatureBuilder1 const & fb) +void FillPolygon(BoostPolygon & polygon, feature::FeatureBuilder const & fb) { using BoostPoint = typename BoostPolygon::point_type; auto const & fbGeometry = fb.GetGeometry(); diff --git a/generator/city_boundary_processor.cpp b/generator/city_boundary_processor.cpp index e2f6b74cdb..c8852d07c5 100644 --- a/generator/city_boundary_processor.cpp +++ b/generator/city_boundary_processor.cpp @@ -6,6 +6,8 @@ #include "base/assert.hpp" +using namespace feature; + namespace generator { namespace @@ -32,9 +34,9 @@ void CityBoundaryProcessor::UnionEqualPlacesIds(Place const & place) }); } -std::vector CityBoundaryProcessor::GetFeatures() const +std::vector CityBoundaryProcessor::GetFeatures() const { - std::vector result; + std::vector result; m_places.ForEach([&result](Place const & p) { result.emplace_back(p.GetFeature()); }); @@ -42,7 +44,7 @@ std::vector CityBoundaryProcessor::GetFeatures() const return result; } -void CityBoundaryProcessor::Add(FeatureBuilder1 const & fb) +void CityBoundaryProcessor::Add(FeatureBuilder const & fb) { auto const type = GetPlaceType(fb); if (type == ftype::GetEmptyValue()) @@ -53,7 +55,7 @@ void CityBoundaryProcessor::Add(FeatureBuilder1 const & fb) UnionEqualPlacesIds(Place(fb, type, false /* saveParams */)); } -void CityBoundaryProcessor::Replace(FeatureBuilder1 const & fb) +void CityBoundaryProcessor::Replace(FeatureBuilder const & fb) { auto const type = GetPlaceType(fb); Place const place(fb, type); diff --git a/generator/city_boundary_processor.hpp b/generator/city_boundary_processor.hpp index 7a9f16582e..c0bd718a72 100644 --- a/generator/city_boundary_processor.hpp +++ b/generator/city_boundary_processor.hpp @@ -17,9 +17,9 @@ class CityBoundaryProcessor public: CityBoundaryProcessor(std::shared_ptr boundariesTable); - void Add(FeatureBuilder1 const & fb); - void Replace(FeatureBuilder1 const & fb); - std::vector GetFeatures() const; + void Add(feature::FeatureBuilder const & fb); + void Replace(feature::FeatureBuilder const & fb); + std::vector GetFeatures() const; private: void UnionEqualPlacesIds(Place const & place); diff --git a/generator/coastlines_generator.cpp b/generator/coastlines_generator.cpp index 7ebda8c57e..3d7f16c28f 100644 --- a/generator/coastlines_generator.cpp +++ b/generator/coastlines_generator.cpp @@ -15,6 +15,7 @@ #include using namespace std; +using namespace feature; using RegionT = m2::RegionI; using PointT = m2::PointI; @@ -78,7 +79,7 @@ namespace }; } // namespace -void CoastlineFeaturesGenerator::AddRegionToTree(FeatureBuilder1 const & fb) +void CoastlineFeaturesGenerator::AddRegionToTree(FeatureBuilder const & fb) { ASSERT ( fb.IsGeometryClosed(), () ); @@ -86,7 +87,7 @@ void CoastlineFeaturesGenerator::AddRegionToTree(FeatureBuilder1 const & fb) fb.ForEachGeometryPointEx(createRgn); } -void CoastlineFeaturesGenerator::Process(FeatureBuilder1 const & fb) +void CoastlineFeaturesGenerator::Process(FeatureBuilder const & fb) { if (fb.IsGeometryClosed()) AddRegionToTree(fb); @@ -106,7 +107,7 @@ namespace explicit DoAddToTree(CoastlineFeaturesGenerator & rMain) : m_rMain(rMain), m_notMergedCoastsCount(0), m_totalNotMergedCoastsPoints(0) {} - virtual void operator() (FeatureBuilder1 const & fb) + virtual void operator() (FeatureBuilder const & fb) { if (fb.IsGeometryClosed()) m_rMain.AddRegionToTree(fb); @@ -196,7 +197,7 @@ public: return count; } - void AssignGeometry(FeatureBuilder1 & fb) + void AssignGeometry(FeatureBuilder & fb) { for (size_t i = 0; i < m_res.size(); ++i) { @@ -317,7 +318,7 @@ public: } }; -void CoastlineFeaturesGenerator::GetFeatures(vector & features) +void CoastlineFeaturesGenerator::GetFeatures(vector & features) { size_t const maxThreads = thread::hardware_concurrency(); CHECK_GREATER(maxThreads, 0, ("Not supported platform")); @@ -327,7 +328,7 @@ void CoastlineFeaturesGenerator::GetFeatures(vector & features) maxThreads, RegionInCellSplitter::kStartLevel, m_tree, [&features, &featuresMutex, this](RegionInCellSplitter::TCell const & cell, DoDifference & cellData) { - FeatureBuilder1 fb; + FeatureBuilder fb; fb.SetCoastCell(cell.ToInt64(RegionInCellSplitter::kHighLevel + 1)); cellData.AssignGeometry(fb); diff --git a/generator/coastlines_generator.hpp b/generator/coastlines_generator.hpp index b520f249d5..ed84f564fa 100644 --- a/generator/coastlines_generator.hpp +++ b/generator/coastlines_generator.hpp @@ -8,7 +8,11 @@ #include "geometry/region2d.hpp" -class FeatureBuilder1; +namespace feature +{ +class FeatureBuilder; +} // namespace feature + class CoastlineFeaturesGenerator { @@ -22,11 +26,11 @@ class CoastlineFeaturesGenerator public: CoastlineFeaturesGenerator(uint32_t coastType); - void AddRegionToTree(FeatureBuilder1 const & fb); + void AddRegionToTree(feature::FeatureBuilder const & fb); - void Process(FeatureBuilder1 const & fb); + void Process(feature::FeatureBuilder const & fb); /// @return false if coasts are not merged and FLAG_fail_on_coasts is set bool Finish(); - void GetFeatures(vector & vecFb); + void GetFeatures(vector & vecFb); }; diff --git a/generator/collector_addresses.cpp b/generator/collector_addresses.cpp index 0b0065fc0e..06c9d65d6d 100644 --- a/generator/collector_addresses.cpp +++ b/generator/collector_addresses.cpp @@ -4,12 +4,14 @@ #include "indexer/ftypes_matcher.hpp" +using namespace feature; + namespace generator { CollectorAddresses::CollectorAddresses(std::string const & filename) : m_addrWriter(std::make_unique(filename)) {} -void CollectorAddresses::CollectFeature(FeatureBuilder1 const & feature, OsmElement const &) +void CollectorAddresses::CollectFeature(FeatureBuilder const & feature, OsmElement const &) { std::string addr; auto const & checker = ftypes::IsBuildingChecker::Instance(); diff --git a/generator/collector_addresses.hpp b/generator/collector_addresses.hpp index 154104d10a..9df5c83e03 100644 --- a/generator/collector_addresses.hpp +++ b/generator/collector_addresses.hpp @@ -16,7 +16,7 @@ public: CollectorAddresses(std::string const & filename); // CollectorInterface overrides: - void CollectFeature(FeatureBuilder1 const & feature, OsmElement const &) override; + void CollectFeature(feature::FeatureBuilder const & feature, OsmElement const &) override; void Save() override {} private: diff --git a/generator/collector_camera.cpp b/generator/collector_camera.cpp index f8c636703a..d2ea040e57 100644 --- a/generator/collector_camera.cpp +++ b/generator/collector_camera.cpp @@ -21,6 +21,8 @@ #include "base/logging.hpp" #include "base/string_utils.hpp" +using namespace feature; + namespace routing { size_t const CameraProcessor::kMaxSpeedSpeedStringLength = 32; @@ -76,7 +78,7 @@ void CameraProcessor::ProcessNode(OsmElement const & element) CameraCollector::CameraCollector(std::string const & writerFile) : m_fileWriter(writerFile) {} -void CameraCollector::CollectFeature(FeatureBuilder1 const & feature, OsmElement const & element) +void CameraCollector::CollectFeature(FeatureBuilder const & feature, OsmElement const & element) { switch (element.m_type) { diff --git a/generator/collector_camera.hpp b/generator/collector_camera.hpp index 2fc5d783ae..4e9059ea4a 100644 --- a/generator/collector_camera.hpp +++ b/generator/collector_camera.hpp @@ -17,7 +17,11 @@ class TestCameraCollector; } // namespace generator_tests struct OsmElement; -class FeatureBuilder1; + +namespace feature +{ +class FeatureBuilder; +} // namespace feature // TODO (@gmoryes) move members of m_routingTagsProcessor to generator namespace routing @@ -69,7 +73,7 @@ public: // generator::CollectorInterface overrides: // We will process all nodes before ways because of o5m format: // all nodes are first, then all ways, then all relations. - void CollectFeature(FeatureBuilder1 const & feature, OsmElement const & element) override; + void CollectFeature(feature::FeatureBuilder const & feature, OsmElement const & element) override; void Save() override; private: diff --git a/generator/collector_collection.cpp b/generator/collector_collection.cpp index 4857365912..7e817103fc 100644 --- a/generator/collector_collection.cpp +++ b/generator/collector_collection.cpp @@ -4,6 +4,8 @@ #include "generator/intermediate_elements.hpp" #include "generator/osm_element.hpp" +using namespace feature; + namespace generator { void CollectorCollection::Collect(OsmElement const & element) @@ -18,7 +20,7 @@ void CollectorCollection::CollectRelation(RelationElement const & element) c->CollectRelation(element); } -void CollectorCollection::CollectFeature(FeatureBuilder1 const & feature, OsmElement const & element) +void CollectorCollection::CollectFeature(FeatureBuilder const & feature, OsmElement const & element) { for (auto & c : m_collection) c->CollectFeature(feature, element); diff --git a/generator/collector_collection.hpp b/generator/collector_collection.hpp index f2dff15c89..09637def1e 100644 --- a/generator/collector_collection.hpp +++ b/generator/collector_collection.hpp @@ -7,7 +7,11 @@ struct OsmElement; class RelationElement; -class FeatureBuilder1; + +namespace feature +{ +class FeatureBuilder; +} // namespace feature namespace generator { @@ -18,7 +22,7 @@ public: // CollectorInterface overrides: void Collect(OsmElement const & element) override; void CollectRelation(RelationElement const & element) override; - void CollectFeature(FeatureBuilder1 const & feature, OsmElement const & element) override; + void CollectFeature(feature::FeatureBuilder const & feature, OsmElement const & element) override; void Save() override; }; } // namespace generator diff --git a/generator/collector_interface.hpp b/generator/collector_interface.hpp index 4ada6f923c..840fd1a618 100644 --- a/generator/collector_interface.hpp +++ b/generator/collector_interface.hpp @@ -3,8 +3,11 @@ #include struct OsmElement; -class FeatureBuilder1; class RelationElement; +namespace feature +{ +class FeatureBuilder; +} // namespace feature namespace base { class GeoObjectId; @@ -21,7 +24,7 @@ public: virtual void Collect(OsmElement const &) {} virtual void CollectRelation(RelationElement const &) {} - virtual void CollectFeature(FeatureBuilder1 const &, OsmElement const &) {} + virtual void CollectFeature(feature::FeatureBuilder const &, OsmElement const &) {} virtual void Save() = 0; }; } // namespace generator diff --git a/generator/emitter_booking.hpp b/generator/emitter_booking.hpp index 99a336d687..64617610e0 100644 --- a/generator/emitter_booking.hpp +++ b/generator/emitter_booking.hpp @@ -19,13 +19,13 @@ template class EmitterBooking : public EmitterInterface { public: - EmitterBooking(Dataset const & dataset, map & features) + EmitterBooking(Dataset const & dataset, map & features) : m_dataset(dataset), m_features(features) { } // EmitterInterface overrides: - void Process(FeatureBuilder1 & fb) override + void Process(feature::FeatureBuilder & fb) override { if (m_dataset.NecessaryMatchingConditionHolds(fb)) m_features.emplace(fb.GetMostGenericOsmId(), fb); @@ -44,6 +44,6 @@ public: private: Dataset const & m_dataset; - map & m_features; + map & m_features; }; } // namespace generator diff --git a/generator/emitter_coastline.cpp b/generator/emitter_coastline.cpp index 6cc745b48d..9fda69cbb3 100644 --- a/generator/emitter_coastline.cpp +++ b/generator/emitter_coastline.cpp @@ -13,6 +13,8 @@ #include "defines.hpp" +using namespace feature; + namespace generator { EmitterCoastline::EmitterCoastline(feature::GenerateInfo const & info) @@ -25,7 +27,7 @@ EmitterCoastline::EmitterCoastline(feature::GenerateInfo const & info) m_processingChain->Add(std::make_shared(m_generator)); } -void EmitterCoastline::Process(FeatureBuilder1 & feature) +void EmitterCoastline::Process(FeatureBuilder & feature) { m_processingChain->Handle(feature); } @@ -43,7 +45,7 @@ bool EmitterCoastline::Finish() size_t totalPoints = 0; size_t totalPolygons = 0; - vector features; + vector features; m_generator->GetFeatures(features); for (auto & feature : features) { diff --git a/generator/emitter_coastline.hpp b/generator/emitter_coastline.hpp index 14b5cd2774..cb4fbc6f60 100644 --- a/generator/emitter_coastline.hpp +++ b/generator/emitter_coastline.hpp @@ -6,11 +6,11 @@ #include #include -class FeatureBuilder1; class CoastlineFeaturesGenerator; namespace feature { struct GenerateInfo; +class FeatureBuilder; } // namespace feature namespace generator @@ -25,7 +25,7 @@ public: explicit EmitterCoastline(feature::GenerateInfo const & info); // EmitterInterface overrides: - void Process(FeatureBuilder1 & feature) override; + void Process(feature::FeatureBuilder & feature) override; bool Finish() override; void GetNames(std::vector & names) const override; diff --git a/generator/emitter_country.cpp b/generator/emitter_country.cpp index 350520a81f..6ccfc3c42f 100644 --- a/generator/emitter_country.cpp +++ b/generator/emitter_country.cpp @@ -11,6 +11,8 @@ #include "defines.hpp" +using namespace feature; + namespace generator { EmitterCountry::EmitterCountry(feature::GenerateInfo const & info) @@ -33,7 +35,7 @@ EmitterCountry::EmitterCountry(feature::GenerateInfo const & info) } } -void EmitterCountry::Process(FeatureBuilder1 & feature) +void EmitterCountry::Process(FeatureBuilder & feature) { m_processingChain->Handle(feature); } diff --git a/generator/emitter_country.hpp b/generator/emitter_country.hpp index 8d247448c2..b996379a07 100644 --- a/generator/emitter_country.hpp +++ b/generator/emitter_country.hpp @@ -6,9 +6,9 @@ #include #include -class FeatureBuilder1; namespace feature { +class FeatureBuilder; struct GenerateInfo; } // namespace feature @@ -24,7 +24,7 @@ public: explicit EmitterCountry(feature::GenerateInfo const & info); // EmitterInterface overrides: - void Process(FeatureBuilder1 & feature) override; + void Process(feature::FeatureBuilder & feature) override; bool Finish() override; void GetNames(std::vector & names) const override; diff --git a/generator/emitter_interface.hpp b/generator/emitter_interface.hpp index 88dcee0b82..14541a2308 100644 --- a/generator/emitter_interface.hpp +++ b/generator/emitter_interface.hpp @@ -3,8 +3,11 @@ #include #include -class FeatureBuilder1; class FeatureParams; +namespace feature +{ +class FeatureBuilder; +} // namespace feature namespace generator { @@ -15,7 +18,7 @@ public: virtual ~EmitterInterface() = default; // This method is used by OsmTranslator to pass |fb| to Emitter for further processing. - virtual void Process(FeatureBuilder1 & fb) = 0; + virtual void Process(feature::FeatureBuilder & fb) = 0; // Finish is used in GenerateFeatureImpl to make whatever work is needed after all OsmElements // are processed. virtual bool Finish() = 0; diff --git a/generator/emitter_noop.hpp b/generator/emitter_noop.hpp index 64202ab11c..0aa82a6e20 100644 --- a/generator/emitter_noop.hpp +++ b/generator/emitter_noop.hpp @@ -5,16 +5,20 @@ #include #include -class FeatureBuilder1; class FeatureParams; +namespace feature +{ +class FeatureBuilder; +} // namespace feature + namespace generator { class EmitterNoop : public EmitterInterface { public: // EmitterInterface overrides: - void Process(FeatureBuilder1 &) override {} + void Process(feature::FeatureBuilder &) override {} bool Finish() override { return true; } void GetNames(std::vector &) const override {} }; diff --git a/generator/emitter_restaurants.cpp b/generator/emitter_restaurants.cpp index ffbca9cc4e..39cfbff3e7 100644 --- a/generator/emitter_restaurants.cpp +++ b/generator/emitter_restaurants.cpp @@ -3,14 +3,16 @@ #include "indexer/ftypes_matcher.hpp" #include "generator/feature_builder.hpp" +using namespace feature; + namespace generator { -EmitterRestaurants::EmitterRestaurants(std::vector & features) +EmitterRestaurants::EmitterRestaurants(std::vector & features) : m_features(features) { } -void EmitterRestaurants::Process(FeatureBuilder1 & fb) +void EmitterRestaurants::Process(FeatureBuilder & fb) { if (!ftypes::IsEatChecker::Instance()(fb.GetParams().m_types) || fb.GetParams().name.IsEmpty()) { diff --git a/generator/emitter_restaurants.hpp b/generator/emitter_restaurants.hpp index 35bcb2200f..e5d32f636d 100644 --- a/generator/emitter_restaurants.hpp +++ b/generator/emitter_restaurants.hpp @@ -9,10 +9,10 @@ namespace generator class EmitterRestaurants : public EmitterInterface { public: - EmitterRestaurants(std::vector & features); + EmitterRestaurants(std::vector & features); // EmitterInterface overrides: - void Process(FeatureBuilder1 & fb) override; + void Process(feature::FeatureBuilder & fb) override; void GetNames(std::vector & names) const override; bool Finish() override; @@ -25,7 +25,7 @@ private: uint32_t m_unexpectedFeatures = 0; }; - std::vector & m_features; + std::vector & m_features; Stats m_stats; }; } // namespace generator diff --git a/generator/emitter_simple.cpp b/generator/emitter_simple.cpp index 28f1836431..9b1d033edc 100644 --- a/generator/emitter_simple.cpp +++ b/generator/emitter_simple.cpp @@ -4,6 +4,8 @@ #include "base/macros.hpp" +using namespace feature; + namespace generator { EmitterSimple::EmitterSimple(feature::GenerateInfo const & info) : @@ -14,7 +16,7 @@ void EmitterSimple::GetNames(std::vector & names) const names = m_regionGenerator->Parent().GetNames(); } -void EmitterSimple::Process(FeatureBuilder1 & fb) +void EmitterSimple::Process(FeatureBuilder & fb) { auto & polygonizer = m_regionGenerator->Parent(); // Emit each feature independently: clear current country names (see Polygonizer::GetCurrentNames()). @@ -23,7 +25,7 @@ void EmitterSimple::Process(FeatureBuilder1 & fb) polygonizer.Finish(); } -void EmitterPreserialize::Process(FeatureBuilder1 & fb) +void EmitterPreserialize::Process(FeatureBuilder & fb) { UNUSED_VALUE(fb.PreSerialize()); EmitterSimple::Process(fb); diff --git a/generator/emitter_simple.hpp b/generator/emitter_simple.hpp index b96f9097ff..161adc7ba0 100644 --- a/generator/emitter_simple.hpp +++ b/generator/emitter_simple.hpp @@ -20,7 +20,7 @@ public: // EmitterInterface overrides: void GetNames(std::vector & names) const override; - void Process(FeatureBuilder1 & fb) override; + void Process(feature::FeatureBuilder & fb) override; bool Finish() override { return true; } private: @@ -35,6 +35,6 @@ public: using EmitterSimple::EmitterSimple; // EmitterInterface overrides: - void Process(FeatureBuilder1 & fb) override; + void Process(feature::FeatureBuilder & fb) override; }; } // namespace generator diff --git a/generator/emitter_world.cpp b/generator/emitter_world.cpp index d864f3ff06..c46a9c5da5 100644 --- a/generator/emitter_world.cpp +++ b/generator/emitter_world.cpp @@ -8,6 +8,8 @@ #include "defines.hpp" +using namespace feature; + namespace generator { EmitterWorld::EmitterWorld(feature::GenerateInfo const & info) @@ -24,7 +26,7 @@ EmitterWorld::EmitterWorld(feature::GenerateInfo const & info) m_processingChain->Add(std::make_shared(m_worldMapper)); } -void EmitterWorld::Process(FeatureBuilder1 & feature) +void EmitterWorld::Process(FeatureBuilder & feature) { m_processingChain->Handle(feature); } diff --git a/generator/emitter_world.hpp b/generator/emitter_world.hpp index b03692d5c5..ff95e574d2 100644 --- a/generator/emitter_world.hpp +++ b/generator/emitter_world.hpp @@ -6,10 +6,9 @@ #include #include -class FeatureBuilder1; - namespace feature { +class FeatureBuilder; struct GenerateInfo; } // namespace feature @@ -26,7 +25,7 @@ public: explicit EmitterWorld(feature::GenerateInfo const & info); // EmitterInterface overrides: - void Process(FeatureBuilder1 & feature) override; + void Process(feature::FeatureBuilder & feature) override; bool Finish() override; void GetNames(std::vector & names) const override; diff --git a/generator/extract_addr/extract_addr.cpp b/generator/extract_addr/extract_addr.cpp index 56617d2a6c..7cedc615d1 100644 --- a/generator/extract_addr/extract_addr.cpp +++ b/generator/extract_addr/extract_addr.cpp @@ -19,9 +19,11 @@ #include #include +using namespace feature; + constexpr int32_t kRoundDigits = 1e6; -std::string GetReadableType(FeatureBuilder1 const & f) +std::string GetReadableType(FeatureBuilder const & f) { auto const isPoiOrBuilding = [](uint32_t type) { auto const & poiChecker = ftypes::IsPoiChecker::Instance(); @@ -38,7 +40,7 @@ std::string GetReadableType(FeatureBuilder1 const & f) return result; } -void PrintFeature(FeatureBuilder1 const & fb, uint64_t) +void PrintFeature(FeatureBuilder const & fb, uint64_t) { std::string const & category = GetReadableType(fb); std::string const & name = fb.GetName(); @@ -47,7 +49,7 @@ void PrintFeature(FeatureBuilder1 const & fb, uint64_t) bool const isPOI = !name.empty() && !category.empty() && category.find("building") == std::string::npos; - if ((house.empty() && !isPOI) || fb.GetGeomType() == feature::GeomType::Line) + if ((house.empty() && !isPOI) || fb.GetGeomType() == GeomType::Line) return; auto const center = MercatorBounds::ToLatLon(fb.GetKeyPoint()); @@ -94,7 +96,7 @@ int main(int argc, char * argv[]) pl.SetResourceDir(argv[2]); classificator::Load(); - feature::ForEachFromDatRawFormat(argv[1], PrintFeature); + ForEachFromDatRawFormat(argv[1], PrintFeature); return 0; } diff --git a/generator/feature_builder.cpp b/generator/feature_builder.cpp index 534902fea5..53fbf34206 100644 --- a/generator/feature_builder.cpp +++ b/generator/feature_builder.cpp @@ -24,170 +24,8 @@ #include #include -using namespace feature; using namespace std; -/////////////////////////////////////////////////////////////////////////////////////////////////// -// FeatureBuilder1 implementation -/////////////////////////////////////////////////////////////////////////////////////////////////// - -FeatureBuilder1::FeatureBuilder1() - : m_coastCell(-1) -{ - m_polygons.push_back(PointSeq()); -} - -bool FeatureBuilder1::IsGeometryClosed() const -{ - PointSeq const & poly = GetOuterGeometry(); - return (poly.size() > 2 && poly.front() == poly.back()); -} - -m2::PointD FeatureBuilder1::GetGeometryCenter() const -{ - //TODO(vng): Check requirements in this assert - //ASSERT ( IsGeometryClosed(), () ); - m2::PointD ret(0.0, 0.0); - - PointSeq const & poly = GetOuterGeometry(); - size_t const count = poly.size(); - for (size_t i = 0; i < count; ++i) - ret += poly[i]; - return ret / count; -} - -m2::PointD FeatureBuilder1::GetKeyPoint() const -{ - switch (GetGeomType()) - { - case GeomType::Point: - return m_center; - case GeomType::Line: - case GeomType::Area: - return GetGeometryCenter(); - default: - CHECK(false, ()); - return m2::PointD(); - } -} - -void FeatureBuilder1::SetCenter(m2::PointD const & p) -{ - m_center = p; - m_params.SetGeomType(GeomType::Point); - m_limitRect.Add(p); -} - -void FeatureBuilder1::SetRank(uint8_t rank) -{ - m_params.rank = rank; -} - -void FeatureBuilder1::AddHouseNumber(string const & houseNumber) -{ - m_params.AddHouseNumber(houseNumber); -} - -void FeatureBuilder1::AddStreet(string const & streetName) { m_params.AddStreet(streetName); } - -void FeatureBuilder1::AddPostcode(string const & postcode) -{ - m_params.GetMetadata().Set(Metadata::FMD_POSTCODE, postcode); -} - -void FeatureBuilder1::AddPoint(m2::PointD const & p) -{ - m_polygons.front().push_back(p); - m_limitRect.Add(p); -} - -void FeatureBuilder1::SetLinear(bool reverseGeometry) -{ - m_params.SetGeomType(feature::GeomType::Line); - m_polygons.resize(1); - - if (reverseGeometry) - { - auto & cont = m_polygons.front(); - ASSERT(!cont.empty(), ()); - reverse(cont.begin(), cont.end()); - } -} - -void FeatureBuilder1::SetAreaAddHoles(FeatureBuilder1::Geometry const & holes) -{ - m_params.SetGeomType(GeomType::Area); - m_polygons.resize(1); - - if (holes.empty()) return; - - PointSeq const & poly = GetOuterGeometry(); - m2::Region rgn(poly.begin(), poly.end()); - - for (PointSeq const & points : holes) - { - ASSERT ( !points.empty(), (*this) ); - - size_t j = 0; - size_t const count = points.size(); - for (; j < count; ++j) - if (!rgn.Contains(points[j])) - break; - - if (j == count) - m_polygons.push_back(points); - } -} - -void FeatureBuilder1::AddPolygon(vector & poly) -{ - // check for closing - if (poly.size() < 3) - return; - - if (poly.front() != poly.back()) - poly.push_back(poly.front()); - - CalcRect(poly, m_limitRect); - - if (!m_polygons.back().empty()) - m_polygons.push_back(PointSeq()); - - m_polygons.back().swap(poly); -} - -void FeatureBuilder1::ResetGeometry() -{ - m_polygons.clear(); - m_polygons.push_back(PointSeq()); - m_limitRect.MakeEmpty(); -} - -bool FeatureBuilder1::RemoveInvalidTypes() -{ - if (!m_params.FinishAddingTypes()) - return false; - - return feature::RemoveUselessTypes(m_params.m_types, m_params.GetGeomType(), - m_params.IsEmptyNames()); -} - -bool FeatureBuilder1::FormatFullAddress(string & res) const -{ - return m_params.FormatFullAddress(m_limitRect.Center(), res); -} - -TypesHolder FeatureBuilder1::GetTypesHolder() const -{ - CHECK ( CheckValid(), (*this) ); - - TypesHolder holder(m_params.GetGeomType()); - for (auto const t : m_params.m_types) - holder.Add(t); - - return holder; -} - namespace { bool IsEqual(double d1, double d2) @@ -213,14 +51,167 @@ bool IsEqual(vector const & v1, vector const & v2) return equal(cbegin(v1), cend(v1), cbegin(v2), cend(v2), [](m2::PointD const & p1, m2::PointD const & p2) { return IsEqual(p1, p2); }); } -} +} // namespace -bool FeatureBuilder1::IsRoad() const +namespace feature { - return routing::IsRoad(m_params.m_types); +FeatureBuilder::FeatureBuilder() + : m_coastCell(-1) +{ + m_polygons.push_back(PointSeq()); } -bool FeatureBuilder1::PreSerialize() +bool FeatureBuilder::IsGeometryClosed() const +{ + PointSeq const & poly = GetOuterGeometry(); + return (poly.size() > 2 && poly.front() == poly.back()); +} + +m2::PointD FeatureBuilder::GetGeometryCenter() const +{ + //TODO(vng): Check requirements in this assert + //ASSERT ( IsGeometryClosed(), () ); + m2::PointD ret(0.0, 0.0); + + PointSeq const & poly = GetOuterGeometry(); + size_t const count = poly.size(); + for (size_t i = 0; i < count; ++i) + ret += poly[i]; + return ret / count; +} + +m2::PointD FeatureBuilder::GetKeyPoint() const +{ + switch (GetGeomType()) + { + case GeomType::Point: + return m_center; + case GeomType::Line: + case GeomType::Area: + return GetGeometryCenter(); + default: + CHECK(false, ()); + return m2::PointD(); + } +} + +void FeatureBuilder::SetCenter(m2::PointD const & p) +{ + m_center = p; + m_params.SetGeomType(GeomType::Point); + m_limitRect.Add(p); +} + +void FeatureBuilder::SetRank(uint8_t rank) +{ + m_params.rank = rank; +} + +void FeatureBuilder::AddHouseNumber(string const & houseNumber) +{ + m_params.AddHouseNumber(houseNumber); +} + +void FeatureBuilder::AddStreet(string const & streetName) { m_params.AddStreet(streetName); } + +void FeatureBuilder::AddPostcode(string const & postcode) +{ + m_params.GetMetadata().Set(Metadata::FMD_POSTCODE, postcode); +} + +void FeatureBuilder::AddPoint(m2::PointD const & p) +{ + m_polygons.front().push_back(p); + m_limitRect.Add(p); +} + +void FeatureBuilder::SetLinear(bool reverseGeometry) +{ + m_params.SetGeomType(GeomType::Line); + m_polygons.resize(1); + + if (reverseGeometry) + { + auto & cont = m_polygons.front(); + ASSERT(!cont.empty(), ()); + reverse(cont.begin(), cont.end()); + } +} + +void FeatureBuilder::AddHoles(FeatureBuilder::Geometry const & holes) +{ + m_polygons.resize(1); + + if (holes.empty()) return; + + PointSeq const & poly = GetOuterGeometry(); + m2::Region rgn(poly.begin(), poly.end()); + + for (PointSeq const & points : holes) + { + ASSERT ( !points.empty(), (*this) ); + + size_t j = 0; + size_t const count = points.size(); + for (; j < count; ++j) + if (!rgn.Contains(points[j])) + break; + + if (j == count) + m_polygons.push_back(points); + } +} + +void FeatureBuilder::AddPolygon(vector & poly) +{ + // check for closing + if (poly.size() < 3) + return; + + if (poly.front() != poly.back()) + poly.push_back(poly.front()); + + CalcRect(poly, m_limitRect); + + if (!m_polygons.back().empty()) + m_polygons.push_back(PointSeq()); + + m_polygons.back().swap(poly); +} + +void FeatureBuilder::ResetGeometry() +{ + m_polygons.clear(); + m_polygons.push_back(PointSeq()); + m_limitRect.MakeEmpty(); +} + +bool FeatureBuilder::RemoveInvalidTypes() +{ + if (!m_params.FinishAddingTypes()) + return false; + + return RemoveUselessTypes(m_params.m_types, m_params.GetGeomType(), + m_params.IsEmptyNames()); +} + +bool FeatureBuilder::FormatFullAddress(string & res) const +{ + return m_params.FormatFullAddress(m_limitRect.Center(), res); +} + +TypesHolder FeatureBuilder::GetTypesHolder() const +{ + Check(*this); + + TypesHolder holder(m_params.GetGeomType()); + for (auto const t : m_params.m_types) + holder.Add(t); + + return holder; +} + +bool FeatureBuilder::PreSerialize() { if (!m_params.IsValid()) return false; @@ -245,7 +236,7 @@ bool FeatureBuilder1::PreSerialize() case GeomType::Line: { // We need refs for road's numbers. - if (!IsRoad()) + if (!routing::IsRoad(GetTypes())) m_params.ref.clear(); m_params.rank = 0; @@ -265,7 +256,7 @@ bool FeatureBuilder1::PreSerialize() return true; } -bool FeatureBuilder1::PreSerializeAndRemoveUselessNames() +bool FeatureBuilder::PreSerializeAndRemoveUselessNamesForTmpMwm() { if (!PreSerialize()) return false; @@ -279,11 +270,10 @@ bool FeatureBuilder1::PreSerializeAndRemoveUselessNames() return true; } -void FeatureBuilder1::RemoveUselessNames() +void FeatureBuilder::RemoveUselessNames() { if (!m_params.name.IsEmpty() && !IsCoastCell()) { - using namespace feature; // Use lambda syntax to correctly compile according to standard: // http://en.cppreference.com/w/cpp/algorithm/remove // The signature of the predicate function should be equivalent to the following: @@ -308,7 +298,7 @@ void FeatureBuilder1::RemoveUselessNames() } } -void FeatureBuilder1::RemoveNameIfInvisible(int minS, int maxS) +void FeatureBuilder::RemoveNameIfInvisible(int minS, int maxS) { if (!m_params.name.IsEmpty() && !IsCoastCell()) { @@ -318,7 +308,7 @@ void FeatureBuilder1::RemoveNameIfInvisible(int minS, int maxS) } } -bool FeatureBuilder1::operator==(FeatureBuilder1 const & fb) const +bool FeatureBuilder::operator==(FeatureBuilder const & fb) const { if (!(m_params == fb.m_params)) return false; @@ -347,24 +337,8 @@ bool FeatureBuilder1::operator==(FeatureBuilder1 const & fb) const return true; } -bool FeatureBuilder1::CheckValid() const -{ - CHECK(m_params.CheckValid(), (*this)); - - GeomType const type = m_params.GetGeomType(); - - if (type == GeomType::Line) - CHECK(GetOuterGeometry().size() >= 2, (*this)); - - if (type == GeomType::Area) - for (PointSeq const & points : m_polygons) - CHECK(points.size() >= 3, (*this)); - - return true; -} - -void FeatureBuilder1::SerializeBase(Buffer & data, serial::GeometryCodingParams const & params, - bool saveAddInfo) const +void FeatureBuilder::SerializeBase(Buffer & data, serial::GeometryCodingParams const & params, + bool saveAddInfo) const { PushBackByteSink sink(data); @@ -374,9 +348,9 @@ void FeatureBuilder1::SerializeBase(Buffer & data, serial::GeometryCodingParams serial::SavePoint(sink, m_center, params); } -void FeatureBuilder1::Serialize(Buffer & data) const +void FeatureBuilder::SerializeForTmpMwm(Buffer & data) const { - CHECK ( CheckValid(), (*this) ); + Check(*this); data.clear(); @@ -402,14 +376,14 @@ void FeatureBuilder1::Serialize(Buffer & data) const // check for correct serialization #ifdef DEBUG Buffer tmp(data); - FeatureBuilder1 fb; + FeatureBuilder fb; fb.Deserialize(tmp); ASSERT ( fb == *this, ("Source feature: ", *this, "Deserialized feature: ", fb) ); #endif } -void FeatureBuilder1::SerializeBorder(serial::GeometryCodingParams const & params, - Buffer & data) const +void FeatureBuilder::SerializeBorderForTmpMwm(serial::GeometryCodingParams const & params, + Buffer & data) const { data.clear(); @@ -434,7 +408,7 @@ void FeatureBuilder1::SerializeBorder(serial::GeometryCodingParams const & param } } -void FeatureBuilder1::Deserialize(Buffer & data) +void FeatureBuilder::DeserializeForTmpMwm(Buffer & data) { serial::GeometryCodingParams cp; @@ -467,26 +441,26 @@ void FeatureBuilder1::Deserialize(Buffer & data) rw::ReadVectorOfPOD(source, m_osmIds); - CHECK ( CheckValid(), (*this) ); + Check(*this); } -void FeatureBuilder1::AddOsmId(base::GeoObjectId id) { m_osmIds.push_back(id); } +void FeatureBuilder::AddOsmId(base::GeoObjectId id) { m_osmIds.push_back(id); } -void FeatureBuilder1::SetOsmId(base::GeoObjectId id) { m_osmIds.assign(1, id); } +void FeatureBuilder::SetOsmId(base::GeoObjectId id) { m_osmIds.assign(1, id); } -base::GeoObjectId FeatureBuilder1::GetFirstOsmId() const +base::GeoObjectId FeatureBuilder::GetFirstOsmId() const { ASSERT(!m_osmIds.empty(), ()); return m_osmIds.front(); } -base::GeoObjectId FeatureBuilder1::GetLastOsmId() const +base::GeoObjectId FeatureBuilder::GetLastOsmId() const { ASSERT(!m_osmIds.empty(), ()); return m_osmIds.back(); } -base::GeoObjectId FeatureBuilder1::GetMostGenericOsmId() const +base::GeoObjectId FeatureBuilder::GetMostGenericOsmId() const { ASSERT(!m_osmIds.empty(), ()); auto result = m_osmIds.front(); @@ -507,7 +481,7 @@ base::GeoObjectId FeatureBuilder1::GetMostGenericOsmId() const return result; } -bool FeatureBuilder1::HasOsmId(base::GeoObjectId const & id) const +bool FeatureBuilder::HasOsmId(base::GeoObjectId const & id) const { for (auto const & cid : m_osmIds) { @@ -517,27 +491,27 @@ bool FeatureBuilder1::HasOsmId(base::GeoObjectId const & id) const return false; } -int FeatureBuilder1::GetMinFeatureDrawScale() const +int FeatureBuilder::GetMinFeatureDrawScale() const { - int const minScale = feature::GetMinDrawableScale(GetTypesHolder(), m_limitRect); + int const minScale = GetMinDrawableScale(GetTypesHolder(), m_limitRect); // some features become invisible after merge processing, so -1 is possible return (minScale == -1 ? 1000 : minScale); } -bool FeatureBuilder1::AddName(string const & lang, string const & name) +bool FeatureBuilder::AddName(string const & lang, string const & name) { return m_params.AddName(lang, name); } -string FeatureBuilder1::GetName(int8_t lang) const +string FeatureBuilder::GetName(int8_t lang) const { string s; VERIFY(m_params.name.GetString(lang, s) != s.empty(), ()); return s; } -size_t FeatureBuilder1::GetPointsCount() const +size_t FeatureBuilder::GetPointsCount() const { size_t counter = 0; for (auto const & p : m_polygons) @@ -545,30 +519,14 @@ size_t FeatureBuilder1::GetPointsCount() const return counter; } -string DebugPrint(FeatureBuilder1 const & f) -{ - ostringstream out; - - switch (f.GetGeomType()) - { - case GeomType::Point: out << DebugPrint(f.m_center); break; - case GeomType::Line: out << "line with " << f.GetPointsCount() << " points"; break; - case GeomType::Area: out << "area with " << f.GetPointsCount() << " points"; break; - default: out << "ERROR: unknown geometry type"; break; - } - - out << " " << DebugPrint(f.m_limitRect) << " " << DebugPrint(f.m_params) << " " << DebugPrint(f.m_osmIds); - return out.str(); -} - -bool FeatureBuilder1::IsDrawableInRange(int lowScale, int highScale) const +bool FeatureBuilder::IsDrawableInRange(int lowScale, int highScale) const { if (!GetOuterGeometry().empty()) { auto const types = GetTypesHolder(); while (lowScale <= highScale) { - if (feature::IsDrawableForIndex(types, m_limitRect, lowScale++)) + if (IsDrawableForIndex(types, m_limitRect, lowScale++)) return true; } } @@ -576,20 +534,7 @@ bool FeatureBuilder1::IsDrawableInRange(int lowScale, int highScale) const return false; } -uint64_t FeatureBuilder1::GetWayIDForRouting() const -{ - if (m_osmIds.size() == 1 && m_osmIds[0].GetType() == base::GeoObjectId::Type::ObsoleteOsmWay && - IsLine() && IsRoad()) - return m_osmIds[0].GetSerialId(); - return 0; -} - -string DebugPrint(FeatureBuilder2 const & f) -{ - return DebugPrint(static_cast(f)); -} - -bool FeatureBuilder2::PreSerializeAndRemoveUselessNames(SupportingData const & data) +bool FeatureBuilder::PreSerializeAndRemoveUselessNamesForMwm(SupportingData const & data) { // make flags actual before header serialization GeomType const geomType = m_params.GetGeomType(); @@ -605,11 +550,11 @@ bool FeatureBuilder2::PreSerializeAndRemoveUselessNames(SupportingData const & d } // we don't need empty features without geometry - return Base::PreSerializeAndRemoveUselessNames(); + return PreSerializeAndRemoveUselessNamesForTmpMwm(); } -void FeatureBuilder2::SerializeLocalityObject(serial::GeometryCodingParams const & params, - SupportingData & data) const +void FeatureBuilder::SerializeLocalityObject(serial::GeometryCodingParams const & params, + SupportingData & data) const { data.m_buffer.clear(); @@ -635,8 +580,8 @@ void FeatureBuilder2::SerializeLocalityObject(serial::GeometryCodingParams const serial::SaveInnerTriangles(data.m_innerTrg, params, sink); } -void FeatureBuilder2::Serialize(SupportingData & data, - serial::GeometryCodingParams const & params) const +void FeatureBuilder::SerializeForMwm(SupportingData & data, + serial::GeometryCodingParams const & params) const { data.m_buffer.clear(); @@ -713,3 +658,35 @@ void FeatureBuilder2::Serialize(SupportingData & data, } } } + +// Functions +void Check(FeatureBuilder const fb) +{ + CHECK(fb.GetParams().CheckValid(), (fb)); + + if (fb.IsLine()) + CHECK(fb.GetOuterGeometry().size() >= 2, (fb)); + + if (fb.IsArea()) + for (auto const & points : fb.GetGeometry()) + CHECK(points.size() >= 3, (fb)); +} + +string DebugPrint(FeatureBuilder const & fb) +{ + ostringstream out; + + switch (fb.GetGeomType()) + { + case GeomType::Point: out << DebugPrint(fb.GetKeyPoint()); break; + case GeomType::Line: out << "line with " << fb.GetPointsCount() << " points"; break; + case GeomType::Area: out << "area with " << fb.GetPointsCount() << " points"; break; + default: out << "ERROR: unknown geometry type"; break; + } + + out << " " << DebugPrint(fb.GetLimitRect()) + << " " << DebugPrint(fb.GetParams()) + << " " << ::DebugPrint(fb.GetOsmIds()); + return out.str(); +} +} // namespace feature diff --git a/generator/feature_builder.hpp b/generator/feature_builder.hpp index e2c8f0d828..72486a235d 100644 --- a/generator/feature_builder.hpp +++ b/generator/feature_builder.hpp @@ -18,137 +18,63 @@ namespace serial class GeometryCodingParams; } // namespace serial -/// Used for serialization\deserialization of features during --generate_features. -class FeatureBuilder1 +namespace feature +{ +class FeatureBuilder { - /// For debugging - friend std::string DebugPrint(FeatureBuilder1 const & f); - public: using PointSeq = std::vector; using Geometry = std::list; - using Buffer = std::vector; + using Offsets = std::vector; - FeatureBuilder1(); + struct SupportingData + { + Offsets m_ptsOffset; + Offsets m_trgOffset; + uint8_t m_ptsMask = 0; + uint8_t m_trgMask = 0; + uint32_t m_ptsSimpMask = 0; + PointSeq m_innerPts; + PointSeq m_innerTrg; + Buffer m_buffer; + }; - /// @name Geometry manipulating functions. - //@{ - /// Set center (origin) point of feature and set that feature is point. - void SetCenter(m2::PointD const & p); + FeatureBuilder(); + bool operator==(FeatureBuilder const &) const; - void SetRank(uint8_t rank); - - void AddHouseNumber(std::string const & houseNumber); - - void AddStreet(std::string const & streetName); - - void AddPostcode(std::string const & postcode); - - /// Add point to geometry. + // To work with geometry. void AddPoint(m2::PointD const & p); - - /// Set that feature is linear type. - void SetLinear(bool reverseGeometry = false); - - /// Set that feature is area and get ownership of holes. - void SetAreaAddHoles(Geometry const & holes); - void SetArea() { m_params.SetGeomType(feature::GeomType::Area); } - - bool IsPoint() const { return (GetGeomType() == feature::GeomType::Point); } - bool IsLine() const { return (GetGeomType() == feature::GeomType::Line); } - bool IsArea() const { return (GetGeomType() == feature::GeomType::Area); } - + void AddHoles(Geometry const & holes); void AddPolygon(std::vector & poly); - void ResetGeometry(); - //@} - - - feature::Metadata const & GetMetadata() const { return m_params.GetMetadata(); } - feature::Metadata & GetMetadata() { return m_params.GetMetadata(); } + m2::RectD const & GetLimitRect() const { return m_limitRect; } Geometry const & GetGeometry() const { return m_polygons; } PointSeq const & GetOuterGeometry() const { return m_polygons.front(); } - feature::GeomType GetGeomType() const { return m_params.GetGeomType(); } - - void AddType(uint32_t type) { m_params.AddType(type); } - bool HasType(uint32_t t) const { return m_params.IsTypeExist(t); } - bool PopExactType(uint32_t type) { return m_params.PopExactType(type); } - void SetType(uint32_t type) { m_params.SetType(type); } - uint32_t FindType(uint32_t comp, uint8_t level) const { return m_params.FindType(comp, level); } - FeatureParams::Types const & GetTypes() const { return m_params.m_types; } - - /// Check classificator types for their compatibility with feature geometry type. - /// Need to call when using any classificator types manipulating. - /// @return false If no any valid types. - bool RemoveInvalidTypes(); - - /// Clear name if it's not visible in scale range [minS, maxS]. - void RemoveNameIfInvisible(int minS = 0, int maxS = 1000); - void RemoveUselessNames(); - - template bool RemoveTypesIf(FnT fn) - { - base::EraseIf(m_params.m_types, fn); - return m_params.m_types.empty(); - } - - /// @name Serialization. - //@{ - void Serialize(Buffer & data) const; - void SerializeBase(Buffer & data, serial::GeometryCodingParams const & params, - bool saveAddInfo) const; - void SerializeBorder(serial::GeometryCodingParams const & params, Buffer & data) const; - - void Deserialize(Buffer & data); - //@} - - /// @name Selectors. - //@{ - m2::RectD GetLimitRect() const { return m_limitRect; } - - bool FormatFullAddress(std::string & res) const; - - /// Get common parameters of feature. - feature::TypesHolder GetTypesHolder() const; - + GeomType GetGeomType() const { return m_params.GetGeomType(); } bool IsGeometryClosed() const; m2::PointD GetGeometryCenter() const; m2::PointD GetKeyPoint() const; - size_t GetPointsCount() const; size_t GetPolygonsCount() const { return m_polygons.size(); } size_t GetTypesCount() const { return m_params.m_types.size(); } - //@} - /// @name Iterate through polygons points. - /// Stops processing when functor returns false. - //@{ -private: - template class ToDoWrapper - { - public: - ToDoWrapper(ToDo && toDo) : m_toDo(std::forward(toDo)) {} - bool operator() (m2::PointD const & p) { return m_toDo(p); } - void EndRegion() {} - - private: - ToDo && m_toDo; - }; - -public: template void ForEachGeometryPointEx(ToDo && toDo) const { - if (m_params.GetGeomType() == feature::GeomType::Point) + if (IsPoint()) + { toDo(m_center); + } else { for (PointSeq const & points : m_polygons) { for (auto const & pt : points) + { if (!toDo(pt)) return; + } toDo.EndRegion(); } } @@ -160,12 +86,11 @@ public: ToDoWrapper wrapper(std::forward(toDo)); ForEachGeometryPointEx(std::move(wrapper)); } - //@} template bool ForAnyGeometryPointEx(ToDo && toDo) const { - if (m_params.GetGeomType() == feature::GeomType::Point) + if (IsPoint()) return toDo(m_center); for (PointSeq const & points : m_polygons) @@ -187,146 +112,146 @@ public: return ForAnyGeometryPointEx(std::move(wrapper)); } - bool PreSerialize(); + // To work with geometry type. + void SetCenter(m2::PointD const & p); + void SetLinear(bool reverseGeometry = false); + void SetArea() { m_params.SetGeomType(GeomType::Area); } + bool IsPoint() const { return GetGeomType() == GeomType::Point; } + bool IsLine() const { return GetGeomType() == GeomType::Line; } + bool IsArea() const { return GetGeomType() == GeomType::Area; } - bool PreSerializeAndRemoveUselessNames(); + // To work with types. + void SetType(uint32_t type) { m_params.SetType(type); } + void AddType(uint32_t type) { m_params.AddType(type); } + bool PopExactType(uint32_t type) { return m_params.PopExactType(type); } + template + bool RemoveTypesIf(FnT fn) + { + base::EraseIf(m_params.m_types, fn); + return m_params.m_types.empty(); + } + bool HasType(uint32_t t) const { return m_params.IsTypeExist(t); } + uint32_t FindType(uint32_t comp, uint8_t level) const { return m_params.FindType(comp, level); } + FeatureParams::Types const & GetTypes() const { return m_params.m_types; } - /// @note This function overrides all previous assigned types. - /// Set all the parameters, except geometry type (it's set by other functions). + // To work with additional information. + void SetRank(uint8_t rank); + void AddHouseNumber(std::string const & houseNumber); + void AddStreet(std::string const & streetName); + void AddPostcode(std::string const & postcode); + bool AddName(std::string const & lang, std::string const & name); void SetParams(FeatureParams const & params) { m_params.SetParams(params); } FeatureParams const & GetParams() const { return m_params; } FeatureParams & GetParams() { return m_params; } + std::string GetName(int8_t lang = StringUtf8Multilang::kDefaultCode) const; + uint8_t GetRank() const { return m_params.rank; } + bool FormatFullAddress(std::string & res) const; + AddressData const & GetAddressData() const { return m_params.GetAddressData(); } - /// @name For OSM debugging and osm objects replacement, store original OSM id - //@{ + Metadata const & GetMetadata() const { return m_params.GetMetadata(); } + Metadata & GetMetadata() { return m_params.GetMetadata(); } + + // To work with types and names based on drawing. + // Check classificator types for their compatibility with feature geometry type. + // Need to call when using any classificator types manipulating. + // Return false If no any valid types. + bool RemoveInvalidTypes(); + // Clear name if it's not visible in scale range [minS, maxS]. + void RemoveNameIfInvisible(int minS = 0, int maxS = 1000); + void RemoveUselessNames(); + int GetMinFeatureDrawScale() const; + bool IsDrawableInRange(int lowScale, int highScale) const; + + // Serialization. + bool PreSerialize(); + void SerializeBase(Buffer & data, serial::GeometryCodingParams const & params, + bool saveAddInfo) const; + + bool PreSerializeAndRemoveUselessNamesForTmpMwm(); + void SerializeForTmpMwm(Buffer & data) const; + void SerializeBorderForTmpMwm(serial::GeometryCodingParams const & params, Buffer & data) const; + void DeserializeForTmpMwm(Buffer & data); + + bool PreSerializeAndRemoveUselessNamesForMwm(SupportingData const & data); + void SerializeLocalityObject(serial::GeometryCodingParams const & params, + SupportingData & data) const; + void SerializeForMwm(SupportingData & data, serial::GeometryCodingParams const & params) const; + + // Get common parameters of feature. + TypesHolder GetTypesHolder() const; + + // TO work with osm ids. void AddOsmId(base::GeoObjectId id); void SetOsmId(base::GeoObjectId id); base::GeoObjectId GetFirstOsmId() const; base::GeoObjectId GetLastOsmId() const; - /// @returns an id of the most general element: node's one if there is no area or relation, - /// area's one if there is no relation, and relation id otherwise. + // Returns an id of the most general element: node's one if there is no area or relation, + // area's one if there is no relation, and relation id otherwise. base::GeoObjectId GetMostGenericOsmId() const; bool HasOsmId(base::GeoObjectId const & id) const; std::vector const & GetOsmIds() const { return m_osmIds; } - //@} - - uint64_t GetWayIDForRouting() const; - - int GetMinFeatureDrawScale() const; - bool IsDrawableInRange(int lowScale, int highScale) const; + // To work with coasts. void SetCoastCell(int64_t iCell) { m_coastCell = iCell; } bool IsCoastCell() const { return (m_coastCell != -1); } - bool AddName(std::string const & lang, std::string const & name); - std::string GetName(int8_t lang = StringUtf8Multilang::kDefaultCode) const; - - uint8_t GetRank() const { return m_params.rank; } - - /// @name For diagnostic use only. - //@{ - bool operator== (FeatureBuilder1 const &) const; - - bool CheckValid() const; - //@} - - bool IsRoad() const; - protected: - /// Used for features debugging - std::vector m_osmIds; + template class ToDoWrapper + { + public: + ToDoWrapper(ToDo && toDo) : m_toDo(std::forward(toDo)) {} + bool operator() (m2::PointD const & p) { return m_toDo(p); } + void EndRegion() {} - FeatureParams m_params; + private: + ToDo && m_toDo; + }; - m2::RectD m_limitRect; - - /// Can be one of the following: - /// - point in point-feature - /// - origin point of text [future] in line-feature - /// - origin point of text or symbol in area-feature + // Can be one of the following: + // - point in point-feature + // - origin point of text [future] in line-feature + // - origin point of text or symbol in area-feature m2::PointD m_center; // Check HEADER_HAS_POINT - - /// List of geometry polygons. + // List of geometry polygons. Geometry m_polygons; // Check HEADER_IS_AREA - + m2::RectD m_limitRect; + std::vector m_osmIds; + FeatureParams m_params; /// Not used in GEOM_POINTs int64_t m_coastCell; }; -/// Used for serialization of features during final pass. -class FeatureBuilder2 : public FeatureBuilder1 +void Check(FeatureBuilder const fb); +std::string DebugPrint(FeatureBuilder const & fb); + +// Read feature from feature source. +template +void ReadFromSourceRawFormat(TSource & src, FeatureBuilder & fb) { - using Base = FeatureBuilder1; - using Offsets = std::vector; + uint32_t const sz = ReadVarUint(src); + typename FeatureBuilder::Buffer buffer(sz); + src.Read(&buffer[0], sz); + fb.DeserializeForTmpMwm(buffer); +} - static void SerializeOffsets(uint32_t mask, Offsets const & offsets, Buffer & buffer); - - /// For debugging - friend std::string DebugPrint(FeatureBuilder2 const & f); - -public: - struct SupportingData - { - /// @name input - //@{ - Offsets m_ptsOffset; - Offsets m_trgOffset; - uint8_t m_ptsMask; - uint8_t m_trgMask; - - uint32_t m_ptsSimpMask; - - PointSeq m_innerPts; - PointSeq m_innerTrg; - //@} - - /// @name output - Base::Buffer m_buffer; - - SupportingData() : m_ptsMask(0), m_trgMask(0), m_ptsSimpMask(0) {} - }; - - /// @name Overwrite from base_type. - //@{ - bool PreSerializeAndRemoveUselessNames(SupportingData const & data); - void SerializeLocalityObject(serial::GeometryCodingParams const & params, - SupportingData & data) const; - void Serialize(SupportingData & data, serial::GeometryCodingParams const & params) const; - //@} - - feature::AddressData const & GetAddressData() const { return m_params.GetAddressData(); } -}; - -namespace feature +// Process features in .dat file. +template +void ForEachFromDatRawFormat(std::string const & fName, ToDo && toDo) { - /// Read feature from feature source. - template - void ReadFromSourceRawFormat(TSource & src, FeatureBuilder1 & fb) + FileReader reader(fName); + ReaderSource src(reader); + + uint64_t currPos = 0; + uint64_t const fSize = reader.Size(); + + // read features one by one + while (currPos < fSize) { - uint32_t const sz = ReadVarUint(src); - typename FeatureBuilder1::Buffer buffer(sz); - src.Read(&buffer[0], sz); - fb.Deserialize(buffer); - } - - /// Process features in .dat file. - template - void ForEachFromDatRawFormat(std::string const & fName, ToDo && toDo) - { - FileReader reader(fName); - ReaderSource src(reader); - - uint64_t currPos = 0; - uint64_t const fSize = reader.Size(); - - // read features one by one - while (currPos < fSize) - { - FeatureBuilder1 fb; - ReadFromSourceRawFormat(src, fb); - toDo(fb, currPos); - currPos = src.Pos(); - } + FeatureBuilder fb; + ReadFromSourceRawFormat(src, fb); + toDo(fb, currPos); + currPos = src.Pos(); } } +} // namespace feature diff --git a/generator/feature_emitter_iface.hpp b/generator/feature_emitter_iface.hpp index 35ccaf829c..35904eeb25 100644 --- a/generator/feature_emitter_iface.hpp +++ b/generator/feature_emitter_iface.hpp @@ -1,10 +1,13 @@ #pragma once -class FeatureBuilder1; +namespace feature +{ +class FeatureBuilder; +} // namespace feature class FeatureEmitterIFace { public: virtual ~FeatureEmitterIFace() {} - virtual void operator() (FeatureBuilder1 const &) = 0; + virtual void operator() (feature::FeatureBuilder const &) = 0; }; diff --git a/generator/feature_generator.cpp b/generator/feature_generator.cpp index deba8d226a..be8e1954b5 100644 --- a/generator/feature_generator.cpp +++ b/generator/feature_generator.cpp @@ -79,7 +79,7 @@ void FeaturesCollector::Write(char const * src, size_t size) } while (size > 0); } -uint32_t FeaturesCollector::WriteFeatureBase(std::vector const & bytes, FeatureBuilder1 const & fb) +uint32_t FeaturesCollector::WriteFeatureBase(std::vector const & bytes, FeatureBuilder const & fb) { size_t const sz = bytes.size(); CHECK(sz != 0, ("Empty feature not allowed here!")); @@ -92,10 +92,10 @@ uint32_t FeaturesCollector::WriteFeatureBase(std::vector const & bytes, Fe return m_featureID++; } -uint32_t FeaturesCollector::Collect(FeatureBuilder1 const & fb) +uint32_t FeaturesCollector::Collect(FeatureBuilder const & fb) { - FeatureBuilder1::Buffer bytes; - fb.Serialize(bytes); + FeatureBuilder::Buffer bytes; + fb.SerializeForTmpMwm(bytes); uint32_t const featureId = WriteFeatureBase(bytes, fb); CHECK_LESS(0, m_featureID, ()); return featureId; @@ -112,10 +112,10 @@ FeaturesAndRawGeometryCollector::~FeaturesAndRawGeometryCollector() LOG(LINFO, ("Write", m_rawGeometryCounter, "geometries into", m_rawGeometryFileStream.GetName())); } -uint32_t FeaturesAndRawGeometryCollector::Collect(FeatureBuilder1 const & fb) +uint32_t FeaturesAndRawGeometryCollector::Collect(FeatureBuilder const & fb) { uint32_t const featureId = FeaturesCollector::Collect(fb); - FeatureBuilder1::Geometry const & geom = fb.GetGeometry(); + FeatureBuilder::Geometry const & geom = fb.GetGeometry(); if (geom.empty()) return featureId; @@ -123,12 +123,12 @@ uint32_t FeaturesAndRawGeometryCollector::Collect(FeatureBuilder1 const & fb) uint64_t numGeometries = geom.size(); m_rawGeometryFileStream.Write(&numGeometries, sizeof(numGeometries)); - for (FeatureBuilder1::PointSeq const & points : geom) + for (FeatureBuilder::PointSeq const & points : geom) { uint64_t numPoints = points.size(); m_rawGeometryFileStream.Write(&numPoints, sizeof(numPoints)); m_rawGeometryFileStream.Write(points.data(), - sizeof(FeatureBuilder1::PointSeq::value_type) * points.size()); + sizeof(FeatureBuilder::PointSeq::value_type) * points.size()); } return featureId; } diff --git a/generator/feature_generator.hpp b/generator/feature_generator.hpp index 358eef32db..09c535c126 100644 --- a/generator/feature_generator.hpp +++ b/generator/feature_generator.hpp @@ -9,10 +9,10 @@ #include #include -class FeatureBuilder1; - namespace feature { +class FeatureBuilder; + // Writes features to dat file. class FeaturesCollector { @@ -29,10 +29,10 @@ public: /// and |kInvalidFeatureId| if not. /// \note See implementation operator() in derived class for cases when |f| cannot be /// serialized. - virtual uint32_t Collect(FeatureBuilder1 const & f); - virtual uint32_t Collect(FeatureBuilder1 & f) + virtual uint32_t Collect(FeatureBuilder const & f); + virtual uint32_t Collect(FeatureBuilder & f) { - return Collect(const_cast(f)); + return Collect(const_cast(f)); } virtual void Finish() {} @@ -40,7 +40,7 @@ protected: static uint32_t constexpr kInvalidFeatureId = std::numeric_limits::max(); /// \return Feature offset in the file, which is used as an ID later - uint32_t WriteFeatureBase(std::vector const & bytes, FeatureBuilder1 const & fb); + uint32_t WriteFeatureBase(std::vector const & bytes, FeatureBuilder const & fb); void Flush(); FileWriter m_datFile; @@ -65,7 +65,7 @@ public: std::string const & rawGeometryFileName); ~FeaturesAndRawGeometryCollector() override; - uint32_t Collect(FeatureBuilder1 const & f) override; + uint32_t Collect(FeatureBuilder const & f) override; }; uint32_t CheckedFilePosCast(FileWriter const & f); diff --git a/generator/feature_helpers.cpp b/generator/feature_helpers.cpp index 5bfaa49bc6..db4e668038 100644 --- a/generator/feature_helpers.cpp +++ b/generator/feature_helpers.cpp @@ -20,7 +20,7 @@ CalculateMidPoints::CalculateMidPoints(MinDrawableScalePolicy const & minDrawabl : m_minDrawableScalePolicy{minDrawableScalePolicy} { } -void CalculateMidPoints::operator()(FeatureBuilder1 const & ft, uint64_t pos) +void CalculateMidPoints::operator()(FeatureBuilder const & ft, uint64_t pos) { // Reset state. m_midLoc = m2::PointD::Zero();; diff --git a/generator/feature_helpers.hpp b/generator/feature_helpers.hpp index 77dc260411..0fe9bb5ec8 100644 --- a/generator/feature_helpers.hpp +++ b/generator/feature_helpers.hpp @@ -20,10 +20,10 @@ #include #include -class FeatureBuilder1; - namespace feature { +class FeatureBuilder; + class CalculateMidPoints { public: @@ -33,7 +33,7 @@ public: CalculateMidPoints(); CalculateMidPoints(MinDrawableScalePolicy const & minDrawableScalePolicy); - void operator()(FeatureBuilder1 const & ft, uint64_t pos); + void operator()(FeatureBuilder const & ft, uint64_t pos); bool operator()(m2::PointD const & p); m2::PointD GetCenter() const; diff --git a/generator/feature_maker.cpp b/generator/feature_maker.cpp index 560612b6da..fc0972c9dd 100644 --- a/generator/feature_maker.cpp +++ b/generator/feature_maker.cpp @@ -11,6 +11,8 @@ #include +using namespace feature; + namespace generator { void FeatureMakerSimple::ParseParams(FeatureParams & params, OsmElement & p) const @@ -22,7 +24,7 @@ void FeatureMakerSimple::ParseParams(FeatureParams & params, OsmElement & p) con bool FeatureMakerSimple::BuildFromNode(OsmElement & p, FeatureParams const & params) { - FeatureBuilder1 fb; + FeatureBuilder fb; fb.SetCenter(MercatorBounds::FromLatLon(p.m_lat, p.m_lon)); fb.SetOsmId(base::MakeOsmNode(p.m_id)); fb.SetParams(params); @@ -36,7 +38,7 @@ bool FeatureMakerSimple::BuildFromWay(OsmElement & p, FeatureParams const & para if (nodes.size() < 2) return false; - FeatureBuilder1 fb; + FeatureBuilder fb; m2::PointD pt; for (uint64_t ref : nodes) { @@ -52,7 +54,8 @@ bool FeatureMakerSimple::BuildFromWay(OsmElement & p, FeatureParams const & para { HolesProcessor processor(p.m_id, m_cache); m_cache.ForEachRelationByWay(p.m_id, processor); - fb.SetAreaAddHoles(processor.GetHoles()); + fb.AddHoles(processor.GetHoles()); + fb.SetArea(); } else { @@ -70,9 +73,9 @@ bool FeatureMakerSimple::BuildFromRelation(OsmElement & p, FeatureParams const & auto const & holesGeometry = helper.GetHoles(); auto & outer = helper.GetOuter(); auto const size = m_queue.size(); - auto const func = [&](FeatureBuilder1::PointSeq const & pts, std::vector const & ids) + auto const func = [&](FeatureBuilder::PointSeq const & pts, std::vector const & ids) { - FeatureBuilder1 fb; + FeatureBuilder fb; for (uint64_t id : ids) fb.AddOsmId(base::MakeOsmWay(id)); @@ -83,8 +86,9 @@ bool FeatureMakerSimple::BuildFromRelation(OsmElement & p, FeatureParams const & if (!fb.IsGeometryClosed()) return; - fb.SetAreaAddHoles(holesGeometry); + fb.AddHoles(holesGeometry); fb.SetParams(params); + fb.SetArea(); m_queue.push(std::move(fb)); }; diff --git a/generator/feature_maker_base.cpp b/generator/feature_maker_base.cpp index 69dbff50c9..334c90f536 100644 --- a/generator/feature_maker_base.cpp +++ b/generator/feature_maker_base.cpp @@ -6,6 +6,8 @@ #include +using namespace feature; + namespace generator { FeatureMakerBase::FeatureMakerBase(cache::IntermediateDataReader & cache) : m_cache(cache) {} @@ -37,7 +39,7 @@ bool FeatureMakerBase::Empty() const return m_queue.empty(); } -bool FeatureMakerBase::GetNextFeature(FeatureBuilder1 & feature) +bool FeatureMakerBase::GetNextFeature(FeatureBuilder & feature) { if (m_queue.empty()) return false; @@ -48,7 +50,7 @@ bool FeatureMakerBase::GetNextFeature(FeatureBuilder1 & feature) } -void TransformAreaToPoint(FeatureBuilder1 & feature) +void TransformAreaToPoint(FeatureBuilder & feature) { CHECK(feature.IsArea(), ()); auto const center = feature.GetGeometryCenter(); @@ -58,22 +60,22 @@ void TransformAreaToPoint(FeatureBuilder1 & feature) feature.SetCenter(center); } -void TransformAreaToLine(FeatureBuilder1 & feature) +void TransformAreaToLine(FeatureBuilder & feature) { CHECK(feature.IsArea(), ()); feature.SetLinear(feature.GetParams().m_reverseGeometry); } -FeatureBuilder1 MakePointFromArea(FeatureBuilder1 const & feature) +FeatureBuilder MakePointFromArea(FeatureBuilder const & feature) { - FeatureBuilder1 tmp(feature); + FeatureBuilder tmp(feature); TransformAreaToPoint(tmp); return tmp; } -FeatureBuilder1 MakeLineFromArea(FeatureBuilder1 const & feature) +FeatureBuilder MakeLineFromArea(FeatureBuilder const & feature) { - FeatureBuilder1 tmp(feature); + FeatureBuilder tmp(feature); TransformAreaToLine(tmp); return tmp; } diff --git a/generator/feature_maker_base.hpp b/generator/feature_maker_base.hpp index 8eff7ad891..d1ebe1aa70 100644 --- a/generator/feature_maker_base.hpp +++ b/generator/feature_maker_base.hpp @@ -24,7 +24,7 @@ public: bool Add(OsmElement & element); // The function returns true when the receiving feature was successful and a false when not successful. - bool GetNextFeature(FeatureBuilder1 & feature); + bool GetNextFeature(feature::FeatureBuilder & feature); size_t Size() const; bool Empty() const; @@ -36,12 +36,12 @@ protected: virtual void ParseParams(FeatureParams & params, OsmElement & element) const = 0; cache::IntermediateDataReader & m_cache; - std::queue m_queue; + std::queue m_queue; }; -void TransformAreaToPoint(FeatureBuilder1 & feature); -void TransformAreaToLine(FeatureBuilder1 & feature); +void TransformAreaToPoint(feature::FeatureBuilder & feature); +void TransformAreaToLine(feature::FeatureBuilder & feature); -FeatureBuilder1 MakePointFromArea(FeatureBuilder1 const & feature); -FeatureBuilder1 MakeLineFromArea(FeatureBuilder1 const & feature); +feature::FeatureBuilder MakePointFromArea(feature::FeatureBuilder const & feature); +feature::FeatureBuilder MakeLineFromArea(feature::FeatureBuilder const & feature); } // namespace generator diff --git a/generator/feature_merger.cpp b/generator/feature_merger.cpp index 004931b0ea..546bb75bad 100644 --- a/generator/feature_merger.cpp +++ b/generator/feature_merger.cpp @@ -6,8 +6,10 @@ #include "coding/point_coding.hpp" -MergedFeatureBuilder1::MergedFeatureBuilder1(FeatureBuilder1 const & fb) - : FeatureBuilder1(fb), m_isRound(false) +using namespace feature; + +MergedFeatureBuilder1::MergedFeatureBuilder1(FeatureBuilder const & fb) + : FeatureBuilder(fb), m_isRound(false) { m_params.FinishAddingTypes(); } @@ -128,7 +130,7 @@ FeatureMergeProcessor::FeatureMergeProcessor(uint32_t coordBits) { } -void FeatureMergeProcessor::operator() (FeatureBuilder1 const & fb) +void FeatureMergeProcessor::operator() (FeatureBuilder const & fb) { this->operator() (new MergedFeatureBuilder1(fb)); } @@ -302,7 +304,7 @@ void FeatureTypesProcessor::SetMappingTypes(char const * arr1[2], char const * a m_mapping[GetType(arr1, 2)] = GetType(arr2, 2); } -MergedFeatureBuilder1 * FeatureTypesProcessor::operator() (FeatureBuilder1 const & fb) +MergedFeatureBuilder1 * FeatureTypesProcessor::operator() (FeatureBuilder const & fb) { MergedFeatureBuilder1 * p = new MergedFeatureBuilder1(fb); @@ -355,7 +357,7 @@ public: } }; -bool PreprocessForWorldMap(FeatureBuilder1 & fb) +bool PreprocessForWorldMap(FeatureBuilder & fb) { int const upperScale = scales::GetUpperWorldScale(); @@ -367,7 +369,7 @@ bool PreprocessForWorldMap(FeatureBuilder1 & fb) return true; } -bool PreprocessForCountryMap(FeatureBuilder1 & fb) +bool PreprocessForCountryMap(FeatureBuilder & fb) { if (fb.RemoveTypesIf(IsInvisibleFn(scales::GetUpperWorldScale() + 1, scales::GetUpperStyleScale(), diff --git a/generator/feature_merger.hpp b/generator/feature_merger.hpp index 10ea7cdee1..c75abc7312 100644 --- a/generator/feature_merger.hpp +++ b/generator/feature_merger.hpp @@ -9,7 +9,7 @@ #include /// Feature builder class that used while feature type processing and merging. -class MergedFeatureBuilder1 : public FeatureBuilder1 +class MergedFeatureBuilder1 : public feature::FeatureBuilder { bool m_isRound; @@ -17,7 +17,7 @@ class MergedFeatureBuilder1 : public FeatureBuilder1 public: MergedFeatureBuilder1() : m_isRound(false) {} - MergedFeatureBuilder1(FeatureBuilder1 const & fb); + MergedFeatureBuilder1(feature::FeatureBuilder const & fb); void SetRound(); bool IsRound() const { return m_isRound; } @@ -80,7 +80,7 @@ class FeatureMergeProcessor public: FeatureMergeProcessor(uint32_t coordBits); - void operator() (FeatureBuilder1 const & fb); + void operator() (feature::FeatureBuilder const & fb); void operator() (MergedFeatureBuilder1 * p); void DoMerge(FeatureEmitterIFace & emitter); @@ -115,14 +115,14 @@ public: m_dontNormalize.insert(GetType(arr, N)); } - MergedFeatureBuilder1 * operator() (FeatureBuilder1 const & fb); + MergedFeatureBuilder1 * operator() (feature::FeatureBuilder const & fb); }; namespace feature { /// @return false If fb became invalid (no any suitable types). //@{ - bool PreprocessForWorldMap(FeatureBuilder1 & fb); - bool PreprocessForCountryMap(FeatureBuilder1 & fb); + bool PreprocessForWorldMap(FeatureBuilder & fb); + bool PreprocessForCountryMap(FeatureBuilder & fb); //@} } diff --git a/generator/feature_processing_layers.cpp b/generator/feature_processing_layers.cpp index 388225239e..74079588a2 100644 --- a/generator/feature_processing_layers.cpp +++ b/generator/feature_processing_layers.cpp @@ -14,11 +14,13 @@ #include "base/assert.hpp" #include "base/geo_object_id.hpp" +using namespace feature; + namespace generator { namespace { -void FixLandType(FeatureBuilder1 & feature) +void FixLandType(FeatureBuilder & feature) { auto const & types = feature.GetTypes(); auto const & isIslandChecker = ftypes::IsIslandChecker::Instance(); @@ -41,7 +43,7 @@ std::string LogBuffer::GetAsString() const return m_buffer.str(); } -void LayerBase::Handle(FeatureBuilder1 & feature) +void LayerBase::Handle(FeatureBuilder & feature) { if (m_next) m_next->Handle(feature); @@ -83,7 +85,7 @@ std::string LayerBase::GetAsStringRecursive() const RepresentationLayer::RepresentationLayer(std::shared_ptr processor) : m_processor(processor) {} -void RepresentationLayer::Handle(FeatureBuilder1 & feature) +void RepresentationLayer::Handle(FeatureBuilder & feature) { auto const sourceType = feature.GetMostGenericOsmId().GetType(); auto const geomType = feature.GetGeomType(); @@ -137,7 +139,7 @@ void RepresentationLayer::Handle(FeatureBuilder1 & feature) } } -void RepresentationLayer::HandleArea(FeatureBuilder1 & feature, FeatureParams const & params) +void RepresentationLayer::HandleArea(FeatureBuilder & feature, FeatureParams const & params) { if (ftypes::IsCityTownOrVillage(params.m_types)) m_processor->Add(feature); @@ -172,7 +174,7 @@ bool RepresentationLayer::CanBeLine(FeatureParams const & params) return feature::HasUsefulType(params.m_types, feature::GeomType::Line); } -void PrepareFeatureLayer::Handle(FeatureBuilder1 & feature) +void PrepareFeatureLayer::Handle(FeatureBuilder & feature) { auto const type = feature.GetGeomType(); auto const & types = feature.GetParams().m_types; @@ -181,7 +183,7 @@ void PrepareFeatureLayer::Handle(FeatureBuilder1 & feature) auto & params = feature.GetParams(); feature::RemoveUselessTypes(params.m_types, type); - feature.PreSerializeAndRemoveUselessNames(); + feature.PreSerializeAndRemoveUselessNamesForTmpMwm(); FixLandType(feature); LayerBase::Handle(feature); } @@ -189,7 +191,7 @@ void PrepareFeatureLayer::Handle(FeatureBuilder1 & feature) CityBoundaryLayer::CityBoundaryLayer(std::shared_ptr processor) : m_processor(processor) {} -void CityBoundaryLayer::Handle(FeatureBuilder1 & feature) +void CityBoundaryLayer::Handle(FeatureBuilder & feature) { auto const type = GetPlaceType(feature); if (type != ftype::GetEmptyValue() && !feature.GetName().empty()) @@ -200,7 +202,7 @@ void CityBoundaryLayer::Handle(FeatureBuilder1 & feature) BookingLayer::~BookingLayer() { - m_dataset.BuildOsmObjects([&] (FeatureBuilder1 & feature) { + m_dataset.BuildOsmObjects([&] (FeatureBuilder & feature) { m_countryMapper->RemoveInvalidTypesAndMap(feature); }); } @@ -208,7 +210,7 @@ BookingLayer::~BookingLayer() BookingLayer::BookingLayer(std::string const & filename, std::shared_ptr countryMapper) : m_dataset(filename), m_countryMapper(countryMapper) {} -void BookingLayer::Handle(FeatureBuilder1 & feature) +void BookingLayer::Handle(FeatureBuilder & feature) { auto const id = m_dataset.FindMatchingObjectId(feature); if (id == BookingHotel::InvalidObjectId()) @@ -217,7 +219,7 @@ void BookingLayer::Handle(FeatureBuilder1 & feature) return; } - m_dataset.PreprocessMatchedOsmObject(id, feature, [&](FeatureBuilder1 & newFeature) { + m_dataset.PreprocessMatchedOsmObject(id, feature, [&](FeatureBuilder & newFeature) { AppendLine("BOOKING", DebugPrint(newFeature.GetMostGenericOsmId()), DebugPrint(id)); m_countryMapper->RemoveInvalidTypesAndMap(newFeature); }); @@ -226,7 +228,7 @@ void BookingLayer::Handle(FeatureBuilder1 & feature) OpentableLayer::OpentableLayer(std::string const & filename, std::shared_ptr countryMapper) : m_dataset(filename), m_countryMapper(countryMapper) {} -void OpentableLayer::Handle(FeatureBuilder1 & feature) +void OpentableLayer::Handle(FeatureBuilder & feature) { auto const id = m_dataset.FindMatchingObjectId(feature); if (id == OpentableRestaurant::InvalidObjectId()) @@ -235,7 +237,7 @@ void OpentableLayer::Handle(FeatureBuilder1 & feature) return; } - m_dataset.PreprocessMatchedOsmObject(id, feature, [&](FeatureBuilder1 & newFeature) { + m_dataset.PreprocessMatchedOsmObject(id, feature, [&](FeatureBuilder & newFeature) { AppendLine("OPENTABLE", DebugPrint(newFeature.GetMostGenericOsmId()), DebugPrint(id)); m_countryMapper->RemoveInvalidTypesAndMap(newFeature); }); @@ -244,13 +246,13 @@ void OpentableLayer::Handle(FeatureBuilder1 & feature) CountryMapperLayer::CountryMapperLayer(std::shared_ptr countryMapper) : m_countryMapper(countryMapper) {} -void CountryMapperLayer::Handle(FeatureBuilder1 & feature) +void CountryMapperLayer::Handle(FeatureBuilder & feature) { m_countryMapper->RemoveInvalidTypesAndMap(feature); LayerBase::Handle(feature); } -void RepresentationCoastlineLayer::Handle(FeatureBuilder1 & feature) +void RepresentationCoastlineLayer::Handle(FeatureBuilder & feature) { auto const sourceType = feature.GetMostGenericOsmId().GetType(); auto const geomType = feature.GetGeomType(); @@ -282,7 +284,7 @@ void RepresentationCoastlineLayer::Handle(FeatureBuilder1 & feature) } } -void PrepareCoastlineFeatureLayer::Handle(FeatureBuilder1 & feature) +void PrepareCoastlineFeatureLayer::Handle(FeatureBuilder & feature) { if (feature.IsArea()) { @@ -290,14 +292,14 @@ void PrepareCoastlineFeatureLayer::Handle(FeatureBuilder1 & feature) feature::RemoveUselessTypes(params.m_types, feature.GetGeomType()); } - feature.PreSerializeAndRemoveUselessNames(); + feature.PreSerializeAndRemoveUselessNamesForTmpMwm(); LayerBase::Handle(feature); } CoastlineMapperLayer::CoastlineMapperLayer(std::shared_ptr coastlineMapper) : m_coastlineGenerator(coastlineMapper) {} -void CoastlineMapperLayer::Handle(FeatureBuilder1 & feature) +void CoastlineMapperLayer::Handle(FeatureBuilder & feature) { auto const & isCoastlineChecker = ftypes::IsCoastlineChecker::Instance(); auto const kCoastType = isCoastlineChecker.GetCoastlineType(); @@ -315,7 +317,7 @@ WorldAreaLayer::~WorldAreaLayer() m_mapper->Merge(); } -void WorldAreaLayer::Handle(FeatureBuilder1 & feature) +void WorldAreaLayer::Handle(FeatureBuilder & feature) { m_mapper->RemoveInvalidTypesAndMap(feature); LayerBase::Handle(feature); @@ -329,7 +331,7 @@ EmitCoastsLayer::EmitCoastsLayer(std::string const & worldCoastsFilename, std::s EmitCoastsLayer::~EmitCoastsLayer() { - feature::ForEachFromDatRawFormat(m_geometryFilename, [&](FeatureBuilder1 fb, uint64_t) + feature::ForEachFromDatRawFormat(m_geometryFilename, [&](FeatureBuilder fb, uint64_t) { auto & emitter = m_countryMapper->Parent(); emitter.Start(); @@ -341,7 +343,7 @@ EmitCoastsLayer::~EmitCoastsLayer() }); } -void EmitCoastsLayer::Handle(FeatureBuilder1 & feature) +void EmitCoastsLayer::Handle(FeatureBuilder & feature) { LayerBase::Handle(feature); } @@ -349,12 +351,12 @@ void EmitCoastsLayer::Handle(FeatureBuilder1 & feature) CountryMapper::CountryMapper(feature::GenerateInfo const & info) : m_countries(std::make_unique(info)) {} -void CountryMapper::Map(FeatureBuilder1 & feature) +void CountryMapper::Map(FeatureBuilder & feature) { m_countries->Process(feature); } -void CountryMapper::RemoveInvalidTypesAndMap(FeatureBuilder1 & feature) +void CountryMapper::RemoveInvalidTypesAndMap(FeatureBuilder & feature) { if (!feature.RemoveInvalidTypes()) return; @@ -376,12 +378,12 @@ WorldMapper::WorldMapper(std::string const & worldFilename, std::string const & std::string const & popularPlacesFilename) : m_world(std::make_unique(worldFilename, rawGeometryFilename, popularPlacesFilename)) {} -void WorldMapper::Map(FeatureBuilder1 & feature) +void WorldMapper::Map(FeatureBuilder & feature) { m_world->Process(feature); } -void WorldMapper::RemoveInvalidTypesAndMap(FeatureBuilder1 & feature) +void WorldMapper::RemoveInvalidTypesAndMap(FeatureBuilder & feature) { if (!feature.RemoveInvalidTypes()) return; diff --git a/generator/feature_processing_layers.hpp b/generator/feature_processing_layers.hpp index af60293b25..a05988a81c 100644 --- a/generator/feature_processing_layers.hpp +++ b/generator/feature_processing_layers.hpp @@ -10,11 +10,11 @@ #include #include -class FeatureBuilder1; class CoastlineFeaturesGenerator; namespace feature { +class FeatureBuilder; struct GenerateInfo; } // namespace feature @@ -60,7 +60,7 @@ public: virtual ~LayerBase() = default; // The function works in linear time from the number of layers that exist after that. - virtual void Handle(FeatureBuilder1 & feature); + virtual void Handle(feature::FeatureBuilder & feature); void SetNext(std::shared_ptr next); std::shared_ptr Add(std::shared_ptr next); @@ -92,14 +92,14 @@ public: explicit RepresentationLayer(std::shared_ptr processor); // LayerBase overrides: - void Handle(FeatureBuilder1 & feature) override; + void Handle(feature::FeatureBuilder & feature) override; private: static bool CanBeArea(FeatureParams const & params); static bool CanBePoint(FeatureParams const & params); static bool CanBeLine(FeatureParams const & params); - void HandleArea(FeatureBuilder1 & feature, FeatureParams const & params); + void HandleArea(feature::FeatureBuilder & feature, FeatureParams const & params); std::shared_ptr m_processor; }; @@ -110,7 +110,7 @@ class PrepareFeatureLayer : public LayerBase { public: // LayerBase overrides: - void Handle(FeatureBuilder1 & feature) override; + void Handle(feature::FeatureBuilder & feature) override; }; // Responsibility of class CityBoundaryLayer - transfering control to the CityBoundaryProcessor @@ -121,7 +121,7 @@ public: explicit CityBoundaryLayer(std::shared_ptr processor); // LayerBase overrides: - void Handle(FeatureBuilder1 & feature) override; + void Handle(feature::FeatureBuilder & feature) override; private: std::shared_ptr m_processor; @@ -137,7 +137,7 @@ public: // LayerBase overrides: ~BookingLayer() override; - void Handle(FeatureBuilder1 & feature) override; + void Handle(feature::FeatureBuilder & feature) override; private: BookingDataset m_dataset; @@ -152,7 +152,7 @@ public: explicit OpentableLayer(std::string const & filename, std::shared_ptr countryMapper); // LayerBase overrides: - void Handle(FeatureBuilder1 & feature) override; + void Handle(feature::FeatureBuilder & feature) override; private: OpentableDataset m_dataset; @@ -166,7 +166,7 @@ public: explicit CountryMapperLayer(std::shared_ptr countryMapper); // LayerBase overrides: - void Handle(FeatureBuilder1 & feature) override; + void Handle(feature::FeatureBuilder & feature) override; private: std::shared_ptr m_countryMapper; @@ -182,7 +182,7 @@ public: // LayerBase overrides: ~EmitCoastsLayer() override; - void Handle(FeatureBuilder1 & feature) override; + void Handle(feature::FeatureBuilder & feature) override; private: std::shared_ptr m_collector; @@ -196,7 +196,7 @@ class RepresentationCoastlineLayer : public LayerBase { public: // LayerBase overrides: - void Handle(FeatureBuilder1 & feature) override; + void Handle(feature::FeatureBuilder & feature) override; }; // Responsibility of class PrepareCoastlineFeatureLayer is the removal of unused types and names, @@ -205,7 +205,7 @@ class PrepareCoastlineFeatureLayer : public LayerBase { public: // LayerBase overrides: - void Handle(FeatureBuilder1 & feature) override; + void Handle(feature::FeatureBuilder & feature) override; }; // Responsibility of class CoastlineMapperLayer - mapping of features on coastline. @@ -215,7 +215,7 @@ public: explicit CoastlineMapperLayer(std::shared_ptr coastlineMapper); // LayerBase overrides: - void Handle(FeatureBuilder1 & feature) override; + void Handle(feature::FeatureBuilder & feature) override; private: std::shared_ptr m_coastlineGenerator; @@ -232,7 +232,7 @@ public: // LayerBase overrides: ~WorldAreaLayer() override; - void Handle(FeatureBuilder1 & feature) override; + void Handle(feature::FeatureBuilder & feature) override; private: std::shared_ptr m_mapper; @@ -247,8 +247,8 @@ public: explicit CountryMapper(feature::GenerateInfo const & info); - void Map(FeatureBuilder1 & feature); - void RemoveInvalidTypesAndMap(FeatureBuilder1 & feature); + void Map(feature::FeatureBuilder & feature); + void RemoveInvalidTypesAndMap(feature::FeatureBuilder & feature); Polygonizer & Parent(); std::vector const & GetNames() const; @@ -265,8 +265,8 @@ public: explicit WorldMapper(std::string const & worldFilename, std::string const & rawGeometryFilename, std::string const & popularPlacesFilename); - void Map(FeatureBuilder1 & feature); - void RemoveInvalidTypesAndMap(FeatureBuilder1 & feature); + void Map(feature::FeatureBuilder & feature); + void RemoveInvalidTypesAndMap(feature::FeatureBuilder & feature); void Merge(); private: diff --git a/generator/feature_sorter.cpp b/generator/feature_sorter.cpp index cd679681c0..6567b2ea5d 100644 --- a/generator/feature_sorter.cpp +++ b/generator/feature_sorter.cpp @@ -8,6 +8,7 @@ #include "generator/region_meta.hpp" #include "generator/tesselator.hpp" +#include "routing/routing_helpers.hpp" #include "routing/speed_camera_prohibition.hpp" #include "indexer/classificator.hpp" @@ -139,7 +140,7 @@ public: void SetBounds(m2::RectD bounds) { m_bounds = bounds; } - uint32_t operator()(FeatureBuilder2 & fb) + uint32_t operator()(FeatureBuilder & fb) { GeometryHolder holder([this](int i) -> FileWriter & { return *m_geoFile[i]; }, [this](int i) -> FileWriter & { return *m_trgFile[i]; }, fb, m_header); @@ -160,7 +161,7 @@ public: Points points; // Do not change linear geometry for the upper scale. - if (isLine && i == scalesStart && IsCountry() && fb.IsRoad()) + if (isLine && i == scalesStart && IsCountry() && routing::IsRoad(fb.GetTypes())) points = holder.GetSourcePoints(); else SimplifyPoints(level, isCoast, rect, holder.GetSourcePoints(), points); @@ -218,9 +219,9 @@ public: uint32_t featureId = kInvalidFeatureId; auto & buffer = holder.GetBuffer(); - if (fb.PreSerializeAndRemoveUselessNames(buffer)) + if (fb.PreSerializeAndRemoveUselessNamesForMwm(buffer)) { - fb.Serialize(buffer, m_header.GetDefGeometryCodingParams()); + fb.SerializeForMwm(buffer, m_header.GetDefGeometryCodingParams()); featureId = WriteFeatureBase(buffer.m_buffer, fb); @@ -311,12 +312,6 @@ private: DISALLOW_COPY_AND_MOVE(FeaturesCollector2); }; -/// Simplify geometry for the upper scale. -FeatureBuilder2 & GetFeatureBuilder2(FeatureBuilder1 & fb) -{ - return static_cast(fb); -} - bool GenerateFinalFeatures(feature::GenerateInfo const & info, string const & name, int mapType) { string const srcFilePath = info.GetTmpFileName(name); @@ -328,7 +323,7 @@ bool GenerateFinalFeatures(feature::GenerateInfo const & info, string const & na bool const speedCamerasProhibitedMwm = routing::AreSpeedCamerasProhibited(country); uint32_t const speedCameraType = classif().GetTypeByPath({"highway", "speed_camera"}); ForEachFromDatRawFormat(srcFilePath, [&speedCamerasProhibitedMwm, &speedCameraType, &midPoints]( - FeatureBuilder1 const & ft, uint64_t pos) { + FeatureBuilder const & ft, uint64_t pos) { // Removing point features with speed cameras type from geometry index for some countries. if (speedCamerasProhibitedMwm && ft.IsPoint() && ft.HasType(speedCameraType)) return; @@ -379,11 +374,11 @@ bool GenerateFinalFeatures(feature::GenerateInfo const & info, string const & na ReaderSource src(reader); src.Skip(point.second); - FeatureBuilder1 f; - ReadFromSourceRawFormat(src, f); + FeatureBuilder fb; + ReadFromSourceRawFormat(src, fb); // emit the feature - collector(GetFeatureBuilder2(f)); + collector(fb); } // Update bounds with the limit rect corresponding to region borders. diff --git a/generator/filter_collection.cpp b/generator/filter_collection.cpp index 19873820c8..511025647a 100644 --- a/generator/filter_collection.cpp +++ b/generator/filter_collection.cpp @@ -5,6 +5,8 @@ #include +using namespace feature; + namespace generator { bool FilterCollection::IsAccepted(OsmElement const & element) @@ -14,7 +16,7 @@ bool FilterCollection::IsAccepted(OsmElement const & element) }); } -bool FilterCollection::IsAccepted(FeatureBuilder1 const & feature) +bool FilterCollection::IsAccepted(FeatureBuilder const & feature) { return std::all_of(std::begin(m_collection), std::end(m_collection), [&] (auto & filter) { return filter->IsAccepted(feature); diff --git a/generator/filter_collection.hpp b/generator/filter_collection.hpp index bdb0afcce9..f4690ce20d 100644 --- a/generator/filter_collection.hpp +++ b/generator/filter_collection.hpp @@ -6,7 +6,11 @@ #include struct OsmElement; -class FeatureBuilder1; +namespace feature +{ +class FeatureBuilder; +} // namespace feature + namespace generator { // This class allows you to work with a group of filters as with one. @@ -15,6 +19,6 @@ class FilterCollection : public CollectionBase> public: // FilterInterface overrides: bool IsAccepted(OsmElement const & element) override; - bool IsAccepted(FeatureBuilder1 const & feature) override; + bool IsAccepted(feature::FeatureBuilder const & feature) override; }; } // namespace generator diff --git a/generator/filter_interface.hpp b/generator/filter_interface.hpp index fec8cdceff..e786938503 100644 --- a/generator/filter_interface.hpp +++ b/generator/filter_interface.hpp @@ -1,7 +1,10 @@ #pragma once struct OsmElement; -class FeatureBuilder1; +namespace feature +{ +class FeatureBuilder; +} // namespace feature namespace generator { @@ -12,6 +15,6 @@ public: virtual ~FilterInterface() = default; virtual bool IsAccepted(OsmElement const &) { return true; } - virtual bool IsAccepted(FeatureBuilder1 const &) { return true; } + virtual bool IsAccepted(feature::FeatureBuilder const &) { return true; } }; } // namespace generator diff --git a/generator/filter_planet.cpp b/generator/filter_planet.cpp index e477976d28..3e92123613 100644 --- a/generator/filter_planet.cpp +++ b/generator/filter_planet.cpp @@ -11,6 +11,8 @@ #include +using namespace feature; + namespace generator { bool FilterPlanet::IsAccepted(OsmElement const & element) @@ -23,7 +25,7 @@ bool FilterPlanet::IsAccepted(OsmElement const & element) return true; } -bool FilterPlanet::IsAccepted(FeatureBuilder1 const & feature) +bool FilterPlanet::IsAccepted(FeatureBuilder const & feature) { auto const & params = feature.GetParams(); return params.IsValid(); diff --git a/generator/filter_planet.hpp b/generator/filter_planet.hpp index e1055596ef..c35c86dcae 100644 --- a/generator/filter_planet.hpp +++ b/generator/filter_planet.hpp @@ -8,6 +8,6 @@ class FilterPlanet : public FilterInterface { public: bool IsAccepted(OsmElement const & element) override; - bool IsAccepted(FeatureBuilder1 const & feature) override; + bool IsAccepted(feature::FeatureBuilder const & feature) override; }; } // namespace generator diff --git a/generator/generator_tests/coasts_test.cpp b/generator/generator_tests/coasts_test.cpp index 30b7513c61..0fd1e110ed 100644 --- a/generator/generator_tests/coasts_test.cpp +++ b/generator/generator_tests/coasts_test.cpp @@ -19,6 +19,7 @@ #include using namespace std; +using namespace feature; namespace { @@ -30,7 +31,7 @@ public: explicit ProcessCoastsBase(vector const & vID) : m_vID(vID) {} protected: - bool HasID(FeatureBuilder1 const & fb) const + bool HasID(FeatureBuilder const & fb) const { TEST(fb.IsCoastCell(), ()); return (find(m_vID.begin(), m_vID.end(), fb.GetName()) != m_vID.end()); @@ -45,38 +46,36 @@ class DoPrintCoasts : public ProcessCoastsBase public: explicit DoPrintCoasts(vector const & vID) : ProcessCoastsBase(vID) {} - void operator()(FeatureBuilder1 const & fb1, uint64_t) + void operator()(FeatureBuilder const & fb, uint64_t) { - if (HasID(fb1)) + if (HasID(fb)) { - FeatureBuilder2 const & fb2 = reinterpret_cast(fb1); - // Check common params. - TEST(fb2.IsArea(), ()); + TEST(fb.IsArea(), ()); int const upperScale = scales::GetUpperScale(); - TEST(fb2.IsDrawableInRange(0, upperScale), ()); + TEST(fb.IsDrawableInRange(0, upperScale), ()); - m2::RectD const rect = fb2.GetLimitRect(); - LOG(LINFO, ("ID =", fb1.GetName(), "Rect =", rect, "Polygons =", fb2.GetGeometry())); + m2::RectD const rect = fb.GetLimitRect(); + LOG(LINFO, ("ID =", fb.GetName(), "Rect =", rect, "Polygons =", fb.GetGeometry())); // Make bound rect inflated a little. - feature::DistanceToSegmentWithRectBounds distFn(rect); + DistanceToSegmentWithRectBounds distFn(rect); m2::RectD const boundRect = m2::Inflate(rect, distFn.GetEpsilon(), distFn.GetEpsilon()); using Points = vector; using Polygons = list; - Polygons const & poly = fb2.GetGeometry(); + Polygons const & poly = fb.GetGeometry(); // Check that all simplifications are inside bound rect. for (int level = 0; level <= upperScale; ++level) { - TEST(fb2.IsDrawableInRange(level, level), ()); + TEST(fb.IsDrawableInRange(level, level), ()); for (auto const & rawPts : poly) { Points pts; - feature::SimplifyPoints(distFn, level, rawPts, pts); + SimplifyPoints(distFn, level, rawPts, pts); LOG(LINFO, ("Simplified. Level =", level, "Points =", pts)); @@ -96,14 +95,14 @@ public: { } - void operator()(FeatureBuilder1 const & fb1, uint64_t) + void operator()(FeatureBuilder const & fb1, uint64_t) { if (HasID(fb1)) m_collector.Collect(fb1); } private: - feature::FeaturesCollector m_collector; + FeaturesCollector m_collector; }; } // namespace @@ -206,6 +205,6 @@ UNIT_TEST(WorldCoasts_CheckBounds) //DoPrintCoasts doProcess(vID); DoCopyCoasts doProcess("/Users/alena/omim/omim/data/WorldCoasts.mwm.tmp", vID); - feature::ForEachFromDatRawFormat("/Users/alena/omim/omim-indexer-tmp/WorldCoasts.mwm.tmp", doProcess); + ForEachFromDatRawFormat("/Users/alena/omim/omim-indexer-tmp/WorldCoasts.mwm.tmp", doProcess); } */ diff --git a/generator/generator_tests/feature_builder_test.cpp b/generator/generator_tests/feature_builder_test.cpp index 99f537ed32..6b29ec8885 100644 --- a/generator/generator_tests/feature_builder_test.cpp +++ b/generator/generator_tests/feature_builder_test.cpp @@ -16,12 +16,14 @@ #include +using namespace feature; + using namespace generator::tests_support; using namespace tests; UNIT_CLASS_TEST(TestWithClassificator, FBuilder_ManyTypes) { - FeatureBuilder1 fb1; + FeatureBuilder fb1; FeatureParams params; char const * arr1[][1] = { @@ -49,23 +51,23 @@ UNIT_CLASS_TEST(TestWithClassificator, FBuilder_ManyTypes) fb1.SetCenter(m2::PointD(0, 0)); TEST(fb1.RemoveInvalidTypes(), ()); - TEST(fb1.CheckValid(), ()); + Check(fb1); - FeatureBuilder1::Buffer buffer; - TEST(fb1.PreSerializeAndRemoveUselessNames(), ()); - fb1.Serialize(buffer); + FeatureBuilder::Buffer buffer; + TEST(fb1.PreSerializeAndRemoveUselessNamesForTmpMwm(), ()); + fb1.SerializeForTmpMwm(buffer); - FeatureBuilder1 fb2; - fb2.Deserialize(buffer); + FeatureBuilder fb2; + fb2.DeserializeForTmpMwm(buffer); - TEST(fb2.CheckValid(), ()); + Check(fb2); TEST_EQUAL(fb1, fb2, ()); TEST_EQUAL(fb2.GetTypesCount(), 6, ()); } UNIT_CLASS_TEST(TestWithClassificator, FBuilder_LineTypes) { - FeatureBuilder1 fb1; + FeatureBuilder fb1; FeatureParams params; char const * arr2[][2] = { @@ -85,23 +87,23 @@ UNIT_CLASS_TEST(TestWithClassificator, FBuilder_LineTypes) fb1.SetLinear(); TEST(fb1.RemoveInvalidTypes(), ()); - TEST(fb1.CheckValid(), ()); + Check(fb1); - FeatureBuilder1::Buffer buffer; - TEST(fb1.PreSerializeAndRemoveUselessNames(), ()); - fb1.Serialize(buffer); + FeatureBuilder::Buffer buffer; + TEST(fb1.PreSerializeAndRemoveUselessNamesForTmpMwm(), ()); + fb1.SerializeForTmpMwm(buffer); - FeatureBuilder1 fb2; - fb2.Deserialize(buffer); + FeatureBuilder fb2; + fb2.DeserializeForTmpMwm(buffer); - TEST(fb2.CheckValid(), ()); + Check(fb2); TEST_EQUAL(fb1, fb2, ()); TEST_EQUAL(fb2.GetTypesCount(), 5, ()); } UNIT_CLASS_TEST(TestWithClassificator, FBuilder_Waterfall) { - FeatureBuilder1 fb1; + FeatureBuilder fb1; FeatureParams params; char const * arr[][2] = {{"waterway", "waterfall"}}; @@ -112,23 +114,23 @@ UNIT_CLASS_TEST(TestWithClassificator, FBuilder_Waterfall) fb1.SetCenter(m2::PointD(1, 1)); TEST(fb1.RemoveInvalidTypes(), ()); - TEST(fb1.CheckValid(), ()); + Check(fb1); - FeatureBuilder1::Buffer buffer; - TEST(fb1.PreSerializeAndRemoveUselessNames(), ()); - fb1.Serialize(buffer); + FeatureBuilder::Buffer buffer; + TEST(fb1.PreSerializeAndRemoveUselessNamesForTmpMwm(), ()); + fb1.SerializeForTmpMwm(buffer); - FeatureBuilder1 fb2; - fb2.Deserialize(buffer); + FeatureBuilder fb2; + fb2.DeserializeForTmpMwm(buffer); - TEST(fb2.CheckValid(), ()); + Check(fb2); TEST_EQUAL(fb1, fb2, ()); TEST_EQUAL(fb2.GetTypesCount(), 1, ()); } UNIT_CLASS_TEST(TestWithClassificator, FBbuilder_GetMostGeneralOsmId) { - FeatureBuilder1 fb; + FeatureBuilder fb; fb.AddOsmId(base::MakeOsmNode(1)); TEST_EQUAL(fb.GetMostGenericOsmId(), base::MakeOsmNode(1), ()); @@ -152,7 +154,7 @@ UNIT_CLASS_TEST(TestWithClassificator, FVisibility_RemoveUselessTypes) types.push_back(c.GetTypeByPath({ "building" })); types.push_back(c.GetTypeByPath({ "amenity", "theatre" })); - TEST(feature::RemoveUselessTypes(types, feature::GeomType::Area), ()); + TEST(RemoveUselessTypes(types, GeomType::Area), ()); TEST_EQUAL(types.size(), 2, ()); } @@ -161,7 +163,7 @@ UNIT_CLASS_TEST(TestWithClassificator, FVisibility_RemoveUselessTypes) types.push_back(c.GetTypeByPath({ "highway", "primary" })); types.push_back(c.GetTypeByPath({ "building" })); - TEST(feature::RemoveUselessTypes(types, feature::GeomType::Area, true /* emptyName */), ()); + TEST(RemoveUselessTypes(types, GeomType::Area, true /* emptyName */), ()); TEST_EQUAL(types.size(), 1, ()); TEST_EQUAL(types[0], c.GetTypeByPath({ "building" }), ()); } @@ -180,7 +182,7 @@ UNIT_CLASS_TEST(TestWithClassificator, FBuilder_RemoveUselessNames) params.AddName("default", "Name"); params.AddName("ru", "Имя"); - FeatureBuilder1 fb1; + FeatureBuilder fb1; fb1.SetParams(params); fb1.AddPoint(m2::PointD(0, 0)); @@ -195,7 +197,7 @@ UNIT_CLASS_TEST(TestWithClassificator, FBuilder_RemoveUselessNames) TEST(fb1.GetName(0).empty(), ()); TEST(fb1.GetName(8).empty(), ()); - TEST(fb1.CheckValid(), ()); + Check(fb1); } UNIT_CLASS_TEST(TestWithClassificator, FeatureParams_Parsing) diff --git a/generator/generator_tests/feature_merger_test.cpp b/generator/generator_tests/feature_merger_test.cpp index ea6b4ef022..5949c7b36d 100644 --- a/generator/generator_tests/feature_merger_test.cpp +++ b/generator/generator_tests/feature_merger_test.cpp @@ -6,15 +6,17 @@ #include "coding/point_coding.hpp" +using namespace feature; + namespace { typedef m2::PointD P; class VectorEmitter : public FeatureEmitterIFace { - vector m_vec; + vector m_vec; public: - virtual void operator() (FeatureBuilder1 const & fb) + virtual void operator() (FeatureBuilder const & fb) { m_vec.push_back(fb); } @@ -40,7 +42,7 @@ UNIT_TEST(FeatureMerger_MultipleTypes) P arrPt[] = { P(0, 0), P(1, 1), P(2, 2), P(3, 3) }; size_t const count = ARRAY_SIZE(arrPt)-1; - FeatureBuilder1 arrF[count]; + FeatureBuilder arrF[count]; for (size_t i = 0; i < count; ++i) { @@ -90,37 +92,37 @@ UNIT_TEST(FeatureMerger_Branches) o */ - vector vF; + vector vF; - vF.push_back(FeatureBuilder1()); + vF.push_back(FeatureBuilder()); vF.back().AddPoint(P(-2, 0)); vF.back().AddPoint(P(-1, 0)); - vF.push_back(FeatureBuilder1()); + vF.push_back(FeatureBuilder()); vF.back().AddPoint(P(-1, 0)); vF.back().AddPoint(P(0, 1)); - vF.push_back(FeatureBuilder1()); + vF.push_back(FeatureBuilder()); vF.back().AddPoint(P(-1, 0)); vF.back().AddPoint(P(0, 0)); - vF.push_back(FeatureBuilder1()); + vF.push_back(FeatureBuilder()); vF.back().AddPoint(P(-1, 0)); vF.back().AddPoint(P(0, -1)); - vF.push_back(FeatureBuilder1()); + vF.push_back(FeatureBuilder()); vF.back().AddPoint(P(0, 1)); vF.back().AddPoint(P(1, 0)); - vF.push_back(FeatureBuilder1()); + vF.push_back(FeatureBuilder()); vF.back().AddPoint(P(0, 0)); vF.back().AddPoint(P(1, 0)); - vF.push_back(FeatureBuilder1()); + vF.push_back(FeatureBuilder()); vF.back().AddPoint(P(0, -1)); vF.back().AddPoint(P(1, 0)); - vF.push_back(FeatureBuilder1()); + vF.push_back(FeatureBuilder()); vF.back().AddPoint(P(1, 0)); vF.back().AddPoint(P(2, 0)); @@ -144,33 +146,33 @@ UNIT_TEST(FeatureMerger_Rounds) { classificator::Load(); - vector vF; + vector vF; - vF.push_back(FeatureBuilder1()); + vF.push_back(FeatureBuilder()); vF.back().AddPoint(P(-10, 0)); vF.back().AddPoint(P(-5, 0)); // make first round feature - vF.push_back(FeatureBuilder1()); + vF.push_back(FeatureBuilder()); vF.back().AddPoint(P(-4, 1)); vF.back().AddPoint(P(-3, 0)); vF.back().AddPoint(P(-4, -1)); vF.back().AddPoint(P(-5, 0)); vF.back().AddPoint(P(-4, 1)); - vF.push_back(FeatureBuilder1()); + vF.push_back(FeatureBuilder()); vF.back().AddPoint(P(-3, 0)); vF.back().AddPoint(P(3, 0)); // make second round feature - vF.push_back(FeatureBuilder1()); + vF.push_back(FeatureBuilder()); vF.back().AddPoint(P(4, -1)); vF.back().AddPoint(P(3, 0)); vF.back().AddPoint(P(4, 1)); vF.back().AddPoint(P(5, 0)); vF.back().AddPoint(P(4, -1)); - vF.push_back(FeatureBuilder1()); + vF.push_back(FeatureBuilder()); vF.back().AddPoint(P(5, 0)); vF.back().AddPoint(P(10, 0)); diff --git a/generator/generator_tests/popularity_builder_tests.cpp b/generator/generator_tests/popularity_builder_tests.cpp index 26a025ca0b..4c0ce70900 100644 --- a/generator/generator_tests/popularity_builder_tests.cpp +++ b/generator/generator_tests/popularity_builder_tests.cpp @@ -23,6 +23,7 @@ using namespace generator; using namespace generator::popularity; +using namespace feature; namespace generator_tests { @@ -38,7 +39,7 @@ public: void GetType() const { { - FeatureBuilder1 fb; + FeatureBuilder fb; auto const type = m_cl.GetTypeByPath({"tourism", "museum"}); auto const checkableType = m_cl.GetReadableObjectName(type); fb.AddType(m_cl.GetTypeByPath({"building"})); @@ -47,13 +48,13 @@ public: } { - FeatureBuilder1 fb; + FeatureBuilder fb; fb.AddType(m_cl.GetTypeByPath({"building"})); TEST_EQUAL(PopularityBuilder::GetType(fb), "", ()); } { - FeatureBuilder1 fb; + FeatureBuilder fb; TEST_EQUAL(PopularityBuilder::GetType(fb), "", ()); } } @@ -61,7 +62,7 @@ public: static void GetFeatureName() { { - FeatureBuilder1 fb; + FeatureBuilder fb; std::string checkableName = "Фича"; fb.AddName("ru", checkableName); fb.AddName("en", "Feature"); @@ -69,7 +70,7 @@ public: } { - FeatureBuilder1 fb; + FeatureBuilder fb; std::string checkableName = "Feature"; fb.AddName("en", checkableName); fb.AddName("default", "Fonctionnalité"); @@ -77,20 +78,20 @@ public: } { - FeatureBuilder1 fb; + FeatureBuilder fb; std::string checkableName = "Fonctionnalité"; fb.AddName("default", checkableName); TEST_EQUAL(PopularityBuilder::GetFeatureName(fb), checkableName, ()); } { - FeatureBuilder1 fb; + FeatureBuilder fb; fb.AddName("fr", "Fonctionnalité"); TEST_EQUAL(PopularityBuilder::GetFeatureName(fb), "", ()); } { - FeatureBuilder1 fb; + FeatureBuilder fb; TEST_EQUAL(PopularityBuilder::GetFeatureName(fb), "", ()); } } @@ -98,7 +99,7 @@ public: void FindPointParent() const { auto const filtered = FilterPoint(m_testSet); - std::map pointMap; + std::map pointMap; for (auto const & f : filtered) pointMap.emplace(f.GetName(), f); @@ -226,7 +227,7 @@ public: void MakeNodes() { - std::vector v = FilterArea(m_testSet); + std::vector v = FilterArea(m_testSet); auto const nodes = PopularityBuilder::MakeNodes(v); TEST_EQUAL(nodes.size(), v.size(), ()); for (size_t i = 0; i < v.size(); ++i) @@ -240,7 +241,7 @@ public: auto const typeName = m_cl.GetReadableObjectName(type); { - feature::FeaturesCollector collector(filename); + FeaturesCollector collector(filename); for (auto const & feature : m_testSet) collector.Collect(feature); } @@ -278,13 +279,13 @@ public: } private: - static std::vector GetTestSet() + static std::vector GetTestSet() { - std::vector v; + std::vector v; v.reserve(5); { - FeatureBuilder1 feature; + FeatureBuilder feature; feature.AddOsmId(base::GeoObjectId(1)); auto const firstLast = m2::PointD{0.0, 0.0}; feature.AddPoint(firstLast); @@ -299,7 +300,7 @@ private: } { - FeatureBuilder1 feature; + FeatureBuilder feature; feature.AddOsmId(base::GeoObjectId(2)); auto const firstLast = m2::PointD{2.0, 3.0}; feature.AddPoint(firstLast); @@ -314,7 +315,7 @@ private: } { - FeatureBuilder1 feature; + FeatureBuilder feature; feature.AddOsmId(base::GeoObjectId(3)); auto const firstLast = m2::PointD{6.0, 0.0}; feature.AddPoint(firstLast); @@ -329,7 +330,7 @@ private: } { - FeatureBuilder1 feature; + FeatureBuilder feature; feature.AddOsmId(base::GeoObjectId(4)); feature.SetCenter(m2::PointD{8.0, 2.0}); feature.AddName("default", "1_3_4"); @@ -338,7 +339,7 @@ private: } { - FeatureBuilder1 feature; + FeatureBuilder feature; feature.AddOsmId(base::GeoObjectId(5)); feature.SetCenter(m2::PointD{7.0, 2.0}); feature.AddName("default", "1_3_5"); @@ -349,9 +350,9 @@ private: return v; } - static std::vector FilterArea(std::vector const & v) + static std::vector FilterArea(std::vector const & v) { - std::vector filtered; + std::vector filtered; std::copy_if(std::begin(v), std::end(v), std::back_inserter(filtered), [](auto const & feature) { return feature.IsArea() && feature.IsGeometryClosed(); }); @@ -359,9 +360,9 @@ private: return filtered; } - static std::vector FilterPoint(std::vector const & v) + static std::vector FilterPoint(std::vector const & v) { - std::vector filtered; + std::vector filtered; std::copy_if(std::begin(v), std::end(v), std::back_inserter(filtered), [](auto const & feature) { return feature.IsPoint(); }); @@ -379,18 +380,18 @@ private: return nameToNode; } - static PopularityBuilder::Node::PtrList MakePopularityGeomPlaces(std::vector const & v) + static PopularityBuilder::Node::PtrList MakePopularityGeomPlaces(std::vector const & v) { PopularityBuilder::Node::PtrList nodes; nodes.reserve(v.size()); - std::transform(std::begin(v), std::end(v), std::back_inserter(nodes), [](FeatureBuilder1 const & f) { + std::transform(std::begin(v), std::end(v), std::back_inserter(nodes), [](FeatureBuilder const & f) { return std::make_shared(PopularityGeomPlace(f)); }); return nodes; } - static std::vector AddTypes(std::vector v, std::vector const & types) + static std::vector AddTypes(std::vector v, std::vector const & types) { for (auto & feature : v) { @@ -402,7 +403,7 @@ private: } Classificator const & m_cl = classif(); - std::vector m_testSet; + std::vector m_testSet; }; } // namespace generator_tests diff --git a/generator/generator_tests/region_info_collector_tests.cpp b/generator/generator_tests/region_info_collector_tests.cpp index ab41dc02ba..12e2558220 100644 --- a/generator/generator_tests/region_info_collector_tests.cpp +++ b/generator/generator_tests/region_info_collector_tests.cpp @@ -19,6 +19,7 @@ using namespace generator_tests; using namespace generator::regions; +using namespace feature; using namespace base; namespace @@ -33,7 +34,7 @@ auto const kOsmElementCountry = MakeOsmElement(2, {{"admin_level", "2"}, {"ISO3166-1:alpha3", "RUS"}, {"ISO3166-1:numeric", "643"}}, OsmElement::EntityType::Relation); -FeatureBuilder1 const kEmptyFeature; +FeatureBuilder const kEmptyFeature; } // namespace UNIT_TEST(RegionInfoCollector_Collect) diff --git a/generator/generator_tests/regions_tests.cpp b/generator/generator_tests/regions_tests.cpp index ba9528222e..776e2c10ee 100644 --- a/generator/generator_tests/regions_tests.cpp +++ b/generator/generator_tests/regions_tests.cpp @@ -23,13 +23,14 @@ using namespace generator_tests; using namespace generator::regions; +using namespace feature; using namespace base; namespace { using Tags = std::vector>; -FeatureBuilder1 const kEmptyFeature; +FeatureBuilder const kEmptyFeature; OsmElement CreateOsmRelation(uint64_t id, std::string const & adminLevel, std::string const & place = "") @@ -63,86 +64,95 @@ RegionsBuilder::Regions MakeTestDataSet1(RegionInfo & collector) { RegionsBuilder::Regions regions; { - FeatureBuilder1 fb1; + FeatureBuilder fb1; fb1.AddName("default", "Country_1"); fb1.SetOsmId(MakeOsmRelation(1 /* id */)); vector poly = {{2, 8}, {3, 12}, {8, 15}, {13, 12}, {15, 7}, {11, 2}, {4, 4}, {2, 8}}; fb1.AddPolygon(poly); - fb1.SetAreaAddHoles({{{5, 8}, {7, 10}, {10, 10}, {11, 7}, {10, 4}, {7, 5}, {5, 8}}}); + fb1.AddHoles({{{5, 8}, {7, 10}, {10, 10}, {11, 7}, {10, 4}, {7, 5}, {5, 8}}}); + fb1.SetArea(); regions.emplace_back(Region(fb1, collector.Get(MakeOsmRelation(1 /* id */)))); } { - FeatureBuilder1 fb1; + FeatureBuilder fb1; fb1.AddName("default", "Country_2"); fb1.SetOsmId(MakeOsmRelation(2 /* id */)); vector poly = {{5, 8}, {7, 10}, {10, 10}, {11, 7}, {10, 4}, {7, 5}, {5, 8}}; fb1.AddPolygon(poly); + fb1.SetArea(); regions.emplace_back(Region(fb1, collector.Get(MakeOsmRelation(2 /* id */)))); } { - FeatureBuilder1 fb1; + FeatureBuilder fb1; fb1.AddName("default", "Country_2"); fb1.SetOsmId(MakeOsmRelation(2 /* id */)); vector poly = {{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}}; fb1.AddPolygon(poly); + fb1.SetArea(); regions.emplace_back(Region(fb1, collector.Get(MakeOsmRelation(2 /* id */)))); } { - FeatureBuilder1 fb1; + FeatureBuilder fb1; fb1.AddName("default", "Country_1_Region_3"); fb1.SetOsmId(MakeOsmRelation(3 /* id */)); vector poly = {{4, 4}, {7, 5}, {10, 4}, {12, 9}, {15, 7}, {11, 2}, {4, 4}}; fb1.AddPolygon(poly); + fb1.SetArea(); regions.emplace_back(Region(fb1, collector.Get(MakeOsmRelation(3 /* id */)))); } { - FeatureBuilder1 fb1; + FeatureBuilder fb1; fb1.AddName("default", "Country_1_Region_4"); fb1.SetOsmId(MakeOsmRelation(4 /* id */)); vector poly = {{7, 10}, {9, 12}, {8, 15}, {13, 12}, {15, 7}, {12, 9}, {11, 7}, {10, 10}, {7, 10}}; fb1.AddPolygon(poly); + fb1.SetArea(); regions.emplace_back(Region(fb1, collector.Get(MakeOsmRelation(4 /* id */)))); } { - FeatureBuilder1 fb1; + FeatureBuilder fb1; fb1.AddName("default", "Country_1_Region_5"); fb1.SetOsmId(MakeOsmRelation(5 /* id */)); vector poly = {{4, 4}, {2, 8}, {3, 12}, {8, 15}, {9, 12}, {7, 10}, {5, 8}, {7, 5}, {4, 4}}; fb1.AddPolygon(poly); + fb1.SetArea(); regions.emplace_back(Region(fb1, collector.Get(MakeOsmRelation(5 /* id */)))); } { - FeatureBuilder1 fb1; + FeatureBuilder fb1; fb1.AddName("default", "Country_1_Region_5_Subregion_6"); fb1.SetOsmId(MakeOsmRelation(6 /* id */)); vector poly = {{4, 4}, {2, 8}, {3, 12}, {4, 10}, {5, 10}, {5, 8}, {7, 5}, {4, 4}}; fb1.AddPolygon(poly); + fb1.SetArea(); regions.emplace_back(Region(fb1, collector.Get(MakeOsmRelation(6 /* id */)))); } { - FeatureBuilder1 fb1; + FeatureBuilder fb1; fb1.AddName("default", "Country_1_Region_5_Subregion_7"); fb1.SetOsmId(MakeOsmRelation(7 /* id */)); vector poly = {{3, 12}, {8, 15}, {9, 12}, {7, 10}, {5, 8}, {5, 10}, {4, 10}, {3, 12}}; fb1.AddPolygon(poly); + fb1.SetArea(); regions.emplace_back(Region(fb1, collector.Get(MakeOsmRelation(7 /* id */)))); } { - FeatureBuilder1 fb1; + FeatureBuilder fb1; fb1.AddName("default", "Country_2_Region_8"); fb1.SetOsmId(MakeOsmRelation(8 /* id */)); vector poly = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; fb1.AddPolygon(poly); + fb1.SetArea(); regions.emplace_back(Region(fb1, collector.Get(MakeOsmRelation(8 /* id */)))); } diff --git a/generator/generator_tests_support/test_feature.cpp b/generator/generator_tests_support/test_feature.cpp index 14fd20412f..f0bcbf4cdd 100644 --- a/generator/generator_tests_support/test_feature.cpp +++ b/generator/generator_tests_support/test_feature.cpp @@ -23,6 +23,7 @@ #include using namespace std; +using namespace feature; namespace generator { @@ -77,18 +78,18 @@ TestFeature::TestFeature(vector const & boundary, string const & nam void TestFeature::Init() { - m_metadata.Set(feature::Metadata::FMD_TEST_ID, strings::to_string(m_id)); + m_metadata.Set(Metadata::FMD_TEST_ID, strings::to_string(m_id)); } bool TestFeature::Matches(FeatureType & feature) const { - istringstream is(feature.GetMetadata().Get(feature::Metadata::FMD_TEST_ID)); + istringstream is(feature.GetMetadata().Get(Metadata::FMD_TEST_ID)); uint64_t id; is >> id; return id == m_id; } -void TestFeature::Serialize(FeatureBuilder1 & fb) const +void TestFeature::Serialize(FeatureBuilder & fb) const { using feature::Metadata; // Metadata::EType::FMD_CUISINE is the first enum value. @@ -139,7 +140,7 @@ TestCountry::TestCountry(m2::PointD const & center, string const & name, string { } -void TestCountry::Serialize(FeatureBuilder1 & fb) const +void TestCountry::Serialize(FeatureBuilder & fb) const { TestFeature::Serialize(fb); auto const & classificator = classif(); @@ -166,7 +167,7 @@ TestCity::TestCity(vector const & boundary, string const & name, str { } -void TestCity::Serialize(FeatureBuilder1 & fb) const +void TestCity::Serialize(FeatureBuilder & fb) const { TestFeature::Serialize(fb); auto const & classificator = classif(); @@ -189,7 +190,7 @@ TestVillage::TestVillage(m2::PointD const & center, string const & name, string { } -void TestVillage::Serialize(FeatureBuilder1 & fb) const +void TestVillage::Serialize(FeatureBuilder & fb) const { TestFeature::Serialize(fb); auto const & classificator = classif(); @@ -215,7 +216,7 @@ TestStreet::TestStreet(vector const & points, StringUtf8Multilang co { } -void TestStreet::Serialize(FeatureBuilder1 & fb) const +void TestStreet::Serialize(FeatureBuilder & fb) const { TestFeature::Serialize(fb); @@ -240,7 +241,7 @@ TestSquare::TestSquare(m2::RectD const & rect, string const & name, string const { } -void TestSquare::Serialize(FeatureBuilder1 & fb) const +void TestSquare::Serialize(FeatureBuilder & fb) const { TestFeature::Serialize(fb); @@ -287,7 +288,7 @@ pair TestPOI::AddWithEditor(osm::Editor & editor, MwmSet::Mw return {poi, emo.GetID()}; } -void TestPOI::Serialize(FeatureBuilder1 & fb) const +void TestPOI::Serialize(FeatureBuilder & fb) const { TestFeature::Serialize(fb); auto const & classificator = classif(); @@ -313,9 +314,9 @@ string TestPOI::ToDebugString() const return os.str(); } -feature::TypesHolder TestPOI::GetTypes() const +TypesHolder TestPOI::GetTypes() const { - feature::TypesHolder types; + TypesHolder types; for (auto const path : m_types) types.Add(classif().GetTypeByPath(path)); return types; @@ -328,7 +329,7 @@ TestMultilingualPOI::TestMultilingualPOI(m2::PointD const & center, string const { } -void TestMultilingualPOI::Serialize(FeatureBuilder1 & fb) const +void TestMultilingualPOI::Serialize(FeatureBuilder & fb) const { TestPOI::Serialize(fb); @@ -376,7 +377,7 @@ TestBuilding::TestBuilding(vector const & boundary, string const & n { } -void TestBuilding::Serialize(FeatureBuilder1 & fb) const +void TestBuilding::Serialize(FeatureBuilder & fb) const { TestFeature::Serialize(fb); @@ -404,7 +405,7 @@ TestPark::TestPark(vector const & boundary, string const & name, str { } -void TestPark::Serialize(FeatureBuilder1 & fb) const +void TestPark::Serialize(FeatureBuilder & fb) const { TestFeature::Serialize(fb); for (auto const & point : m_boundary) @@ -429,7 +430,7 @@ TestRoad::TestRoad(vector const & points, string const & name, strin { } -void TestRoad::Serialize(FeatureBuilder1 & fb) const +void TestRoad::Serialize(FeatureBuilder & fb) const { TestFeature::Serialize(fb); diff --git a/generator/generator_tests_support/test_feature.hpp b/generator/generator_tests_support/test_feature.hpp index a98a606822..21ee64c729 100644 --- a/generator/generator_tests_support/test_feature.hpp +++ b/generator/generator_tests_support/test_feature.hpp @@ -16,9 +16,11 @@ #include #include -class FeatureBuilder1; class FeatureType; - +namespace feature +{ +class FeatureBuilder; +} // namespace feature namespace osm { class Editor; @@ -47,7 +49,7 @@ public: feature::Metadata & GetMetadata() { return m_metadata; } - virtual void Serialize(FeatureBuilder1 & fb) const; + virtual void Serialize(feature::FeatureBuilder & fb) const; virtual std::string ToDebugString() const = 0; protected: @@ -83,7 +85,7 @@ public: TestCountry(m2::PointD const & center, std::string const & name, std::string const & lang); // TestFeature overrides: - void Serialize(FeatureBuilder1 & fb) const override; + void Serialize(feature::FeatureBuilder & fb) const override; std::string ToDebugString() const override; }; @@ -96,7 +98,7 @@ public: std::string const & lang, uint8_t rank); // TestFeature overrides: - void Serialize(FeatureBuilder1 & fb) const override; + void Serialize(feature::FeatureBuilder & fb) const override; std::string ToDebugString() const override; private: @@ -109,7 +111,7 @@ public: TestVillage(m2::PointD const & center, std::string const & name, std::string const & lang, uint8_t rank); // TestFeature overrides: - void Serialize(FeatureBuilder1 & fb) const override; + void Serialize(feature::FeatureBuilder & fb) const override; std::string ToDebugString() const override; private: @@ -125,7 +127,7 @@ public: void SetHighwayType(std::string const & type) { m_highwayType = type; } // TestFeature overrides: - void Serialize(FeatureBuilder1 & fb) const override; + void Serialize(feature::FeatureBuilder & fb) const override; std::string ToDebugString() const override; private: @@ -139,7 +141,7 @@ public: TestSquare(m2::RectD const & rect, std::string const & name, std::string const & lang); // TestFeature overrides: - void Serialize(FeatureBuilder1 & fb) const override; + void Serialize(feature::FeatureBuilder & fb) const override; std::string ToDebugString() const override; private: @@ -157,7 +159,7 @@ public: m2::PointD const & pt); // TestFeature overrides: - void Serialize(FeatureBuilder1 & fb) const override; + void Serialize(feature::FeatureBuilder & fb) const override; std::string ToDebugString() const override; feature::TypesHolder GetTypes() const; @@ -177,7 +179,7 @@ public: TestMultilingualPOI(m2::PointD const & center, std::string const & defaultName, std::map const & multilingualNames); // TestFeature overrides: - void Serialize(FeatureBuilder1 & fb) const override; + void Serialize(feature::FeatureBuilder & fb) const override; std::string ToDebugString() const override; private: @@ -196,7 +198,7 @@ public: std::string const & lang); // TestFeature overrides: - void Serialize(FeatureBuilder1 & fb) const override; + void Serialize(feature::FeatureBuilder & fb) const override; std::string ToDebugString() const override; void AddType(std::vector const & path) { m_types.push_back(path); } @@ -215,7 +217,7 @@ public: TestPark(std::vector const & boundary, std::string const & name, std::string const & lang); // TestFeature overrides: - void Serialize(FeatureBuilder1 & fb) const override; + void Serialize(feature::FeatureBuilder & fb) const override; std::string ToDebugString() const override; private: @@ -228,7 +230,7 @@ public: TestRoad(std::vector const & points, std::string const & name, std::string const & lang); // TestFeature overrides: - void Serialize(FeatureBuilder1 & fb) const override; + void Serialize(feature::FeatureBuilder & fb) const override; std::string ToDebugString() const override; private: diff --git a/generator/generator_tests_support/test_mwm_builder.cpp b/generator/generator_tests_support/test_mwm_builder.cpp index 1f8c806e82..b014279e02 100644 --- a/generator/generator_tests_support/test_mwm_builder.cpp +++ b/generator/generator_tests_support/test_mwm_builder.cpp @@ -27,6 +27,7 @@ #include using namespace std; +using namespace feature; namespace { @@ -35,7 +36,7 @@ bool WriteRegionDataForTests(string const & path, vector const & languag try { FilesContainerW writer(path, FileWriter::OP_WRITE_EXISTING); - feature::RegionData regionData; + RegionData regionData; regionData.SetLanguages(languages); FileWriter w = writer.GetWriter(REGION_INFO_FILE_TAG); regionData.Serialize(w); @@ -53,12 +54,12 @@ namespace generator { namespace tests_support { -TestMwmBuilder::TestMwmBuilder(platform::LocalCountryFile & file, feature::DataHeader::MapType type, +TestMwmBuilder::TestMwmBuilder(platform::LocalCountryFile & file, DataHeader::MapType type, uint32_t version) : m_file(file) , m_type(type) , m_collector( - make_unique(m_file.GetPath(MapOptions::Map) + EXTENSION_TMP)) + make_unique(m_file.GetPath(MapOptions::Map) + EXTENSION_TMP)) , m_version(version) { } @@ -71,20 +72,20 @@ TestMwmBuilder::~TestMwmBuilder() void TestMwmBuilder::Add(TestFeature const & feature) { - FeatureBuilder1 fb; + FeatureBuilder fb; feature.Serialize(fb); CHECK(Add(fb), (fb)); } -bool TestMwmBuilder::Add(FeatureBuilder1 & fb) +bool TestMwmBuilder::Add(FeatureBuilder & fb) { CHECK(m_collector, ("It's not possible to add features after call to Finish().")); - if (ftypes::IsCityTownOrVillage(fb.GetTypes()) && fb.GetGeomType() == feature::GeomType::Area) + if (ftypes::IsCityTownOrVillage(fb.GetTypes()) && fb.GetGeomType() == GeomType::Area) { auto const & metadata = fb.GetMetadata(); uint64_t testId; - CHECK(strings::to_uint64(metadata.Get(feature::Metadata::FMD_TEST_ID), testId), ()); + CHECK(strings::to_uint64(metadata.Get(Metadata::FMD_TEST_ID), testId), ()); m_boundariesTable.Append(testId, indexer::CityBoundary(fb.GetOuterGeometry())); auto const center = fb.GetGeometryCenter(); @@ -92,7 +93,7 @@ bool TestMwmBuilder::Add(FeatureBuilder1 & fb) fb.SetCenter(center); } - if (!fb.PreSerializeAndRemoveUselessNames()) + if (!fb.PreSerializeAndRemoveUselessNamesForTmpMwm()) { LOG(LWARNING, ("Can't pre-serialize feature.")); return false; @@ -120,7 +121,7 @@ void TestMwmBuilder::Finish() CHECK(m_collector, ("Finish() already was called.")); m_collector.reset(); - feature::GenerateInfo info; + GenerateInfo info; info.m_targetDir = m_file.GetDirectory(); info.m_tmpDir = m_file.GetDirectory(); info.m_versionDate = static_cast(base::YYMMDDToSecondsSinceEpoch(m_version)); @@ -132,14 +133,14 @@ void TestMwmBuilder::Finish() string const path = m_file.GetPath(MapOptions::Map); (void)base::DeleteFileX(path + OSM2FEATURE_FILE_EXTENSION); - CHECK(feature::BuildOffsetsTable(path), ("Can't build feature offsets table.")); + CHECK(BuildOffsetsTable(path), ("Can't build feature offsets table.")); CHECK(indexer::BuildIndexFromDataFile(path, path), ("Can't build geometry index.")); CHECK(indexer::BuildSearchIndexFromDataFile(path, true /* forceRebuild */, 1 /* threadsCount */), ("Can't build search index.")); - if (m_type == feature::DataHeader::world) + if (m_type == DataHeader::world) CHECK(generator::BuildCitiesBoundariesForTesting(path, m_boundariesTable), ()); CHECK(indexer::BuildCentersTableFromDataFile(path, true /* forceRebuild */), diff --git a/generator/generator_tests_support/test_mwm_builder.hpp b/generator/generator_tests_support/test_mwm_builder.hpp index 28011cdc60..d43b8fc223 100644 --- a/generator/generator_tests_support/test_mwm_builder.hpp +++ b/generator/generator_tests_support/test_mwm_builder.hpp @@ -13,13 +13,12 @@ namespace feature { class FeaturesCollector; +class FeatureBuilder; } namespace platform { class LocalCountryFile; } -class FeatureBuilder1; - namespace generator { namespace tests_support @@ -35,7 +34,7 @@ public: ~TestMwmBuilder(); void Add(TestFeature const & feature); - bool Add(FeatureBuilder1 & fb); + bool Add(feature::FeatureBuilder & fb); void SetMwmLanguages(std::vector const & languages); void Finish(); diff --git a/generator/geo_objects/geo_objects.cpp b/generator/geo_objects/geo_objects.cpp index f2b7ce1440..6b4234dbcd 100644 --- a/generator/geo_objects/geo_objects.cpp +++ b/generator/geo_objects/geo_objects.cpp @@ -32,6 +32,8 @@ #include #include "3party/jansson/myjansson.hpp" +using namespace feature; + namespace generator { namespace geo_objects @@ -60,7 +62,7 @@ void UpdateCoordinates(m2::PointD const & point, base::JSONPtr & json) } } -base::JSONPtr AddAddress(FeatureBuilder1 const & fb, KeyValue const & regionKeyValue) +base::JSONPtr AddAddress(FeatureBuilder const & fb, KeyValue const & regionKeyValue) { auto result = regionKeyValue.second->MakeDeepCopyJson(); int const kHouseOrPoiRank = 30; @@ -87,7 +89,7 @@ base::JSONPtr AddAddress(FeatureBuilder1 const & fb, KeyValue const & regionKeyV } std::unique_ptr -MakeGeoObjectValueWithAddress(FeatureBuilder1 const & fb, KeyValue const & keyValue) +MakeGeoObjectValueWithAddress(FeatureBuilder const & fb, KeyValue const & keyValue) { auto const jsonWithAddress = AddAddress(fb, keyValue); auto const cstr = json_dumps(jsonWithAddress.get(), JSON_COMPACT); @@ -95,13 +97,13 @@ MakeGeoObjectValueWithAddress(FeatureBuilder1 const & fb, KeyValue const & keyVa } std::shared_ptr -FindHousePoi(FeatureBuilder1 const & fb, GeoObjectInfoGetter const & geoObjectInfoGetter) +FindHousePoi(FeatureBuilder const & fb, GeoObjectInfoGetter const & geoObjectInfoGetter) { return geoObjectInfoGetter.Find(fb.GetKeyPoint(), HouseHasAddress); } std::unique_ptr -MakeGeoObjectValueWithoutAddress(FeatureBuilder1 const & fb, JsonValue const & json) +MakeGeoObjectValueWithoutAddress(FeatureBuilder const & fb, JsonValue const & json) { auto jsonWithAddress = json.MakeDeepCopyJson(); auto properties = json_object_get(jsonWithAddress.get(), "properties"); @@ -116,7 +118,7 @@ MakeTempGeoObjectsIndex(std::string const & pathToGeoObjectsTmpMwm) { auto const dataFile = Platform().TmpPathForFile(); SCOPE_GUARD(removeDataFile, std::bind(Platform::RemoveFileIfExists, std::cref(dataFile))); - if (!feature::GenerateGeoObjectsData(pathToGeoObjectsTmpMwm, "" /* nodesFile */, dataFile)) + if (!GenerateGeoObjectsData(pathToGeoObjectsTmpMwm, "" /* nodesFile */, dataFile)) { LOG(LCRITICAL, ("Error generating geo objects data.")); return {}; @@ -138,9 +140,9 @@ void FilterAddresslessByCountryAndRepackMwm(std::string const & pathInGeoObjects regions::RegionInfoGetter const & regionInfoGetter) { auto const path = Platform().TmpPathForFile(); - feature::FeaturesCollector collector(path); + FeaturesCollector collector(path); - auto const filteringCollector = [&](FeatureBuilder1 const & fb, uint64_t /* currPos */) + auto const filteringCollector = [&](FeatureBuilder const & fb, uint64_t /* currPos */) { if (GeoObjectsFilter::HasHouse(fb)) { @@ -160,7 +162,7 @@ void FilterAddresslessByCountryAndRepackMwm(std::string const & pathInGeoObjects if (pos != std::string::npos) collector.Collect(fb); }; - feature::ForEachFromDatRawFormat(pathInGeoObjectsTmpMwm, filteringCollector); + ForEachFromDatRawFormat(pathInGeoObjectsTmpMwm, filteringCollector); Platform().RemoveFileIfExists(pathInGeoObjectsTmpMwm); if (std::rename(path.c_str(), pathInGeoObjectsTmpMwm.c_str()) != 0) @@ -172,7 +174,7 @@ void BuildGeoObjectsWithAddresses(regions::RegionInfoGetter const & regionInfoGe std::ostream & streamGeoObjectsKv, bool) { size_t countGeoObjects = 0; - auto const fn = [&](FeatureBuilder1 & fb, uint64_t /* currPos */) { + auto const fn = [&](FeatureBuilder & fb, uint64_t /* currPos */) { if (!GeoObjectsFilter::IsBuilding(fb) && !GeoObjectsFilter::HasHouse(fb)) return; @@ -186,7 +188,7 @@ void BuildGeoObjectsWithAddresses(regions::RegionInfoGetter const & regionInfoGe ++countGeoObjects; }; - feature::ForEachFromDatRawFormat(pathInGeoObjectsTmpMwm, fn); + ForEachFromDatRawFormat(pathInGeoObjectsTmpMwm, fn); LOG(LINFO, ("Added ", countGeoObjects, "geo objects with addresses.")); } @@ -196,7 +198,7 @@ void BuildGeoObjectsWithoutAddresses(GeoObjectInfoGetter const & geoObjectInfoGe std::ostream & streamIdsWithoutAddress, bool) { size_t countGeoObjects = 0; - auto const fn = [&](FeatureBuilder1 & fb, uint64_t /* currPos */) { + auto const fn = [&](FeatureBuilder & fb, uint64_t /* currPos */) { if (!GeoObjectsFilter::IsPoi(fb)) return; if (GeoObjectsFilter::IsBuilding(fb) || GeoObjectsFilter::HasHouse(fb)) @@ -213,7 +215,7 @@ void BuildGeoObjectsWithoutAddresses(GeoObjectInfoGetter const & geoObjectInfoGe ++countGeoObjects; }; - feature::ForEachFromDatRawFormat(pathInGeoObjectsTmpMwm, fn); + ForEachFromDatRawFormat(pathInGeoObjectsTmpMwm, fn); LOG(LINFO, ("Added ", countGeoObjects, "geo objects without addresses.")); } } // namespace diff --git a/generator/geo_objects/geo_objects_filter.cpp b/generator/geo_objects/geo_objects_filter.cpp index adfaa7cf67..446c09b251 100644 --- a/generator/geo_objects/geo_objects_filter.cpp +++ b/generator/geo_objects/geo_objects_filter.cpp @@ -4,6 +4,8 @@ #include "indexer/ftypes_matcher.hpp" +using namespace feature; + namespace generator { namespace geo_objects @@ -13,7 +15,7 @@ bool GeoObjectsFilter::IsAccepted(OsmElement const & element) return osm_element::IsBuilding(element) || osm_element::HasHouse(element) || osm_element::IsPoi(element); } -bool GeoObjectsFilter::IsAccepted(FeatureBuilder1 const & feature) +bool GeoObjectsFilter::IsAccepted(FeatureBuilder const & feature) { if (!feature.GetParams().IsValid()) return false; @@ -22,20 +24,20 @@ bool GeoObjectsFilter::IsAccepted(FeatureBuilder1 const & feature) } // static -bool GeoObjectsFilter::IsBuilding(FeatureBuilder1 const & fb) +bool GeoObjectsFilter::IsBuilding(FeatureBuilder const & fb) { auto const & checker = ftypes::IsBuildingChecker::Instance(); return checker(fb.GetTypes()); } // static -bool GeoObjectsFilter::HasHouse(FeatureBuilder1 const & fb) +bool GeoObjectsFilter::HasHouse(FeatureBuilder const & fb) { return !fb.GetParams().house.IsEmpty(); } // static -bool GeoObjectsFilter::IsPoi(FeatureBuilder1 const & fb) +bool GeoObjectsFilter::IsPoi(FeatureBuilder const & fb) { auto const & poiChecker = ftypes::IsPoiChecker::Instance(); return poiChecker(fb.GetTypes()); diff --git a/generator/geo_objects/geo_objects_filter.hpp b/generator/geo_objects/geo_objects_filter.hpp index 97d3d6ed1d..fccdbdd2fa 100644 --- a/generator/geo_objects/geo_objects_filter.hpp +++ b/generator/geo_objects/geo_objects_filter.hpp @@ -13,11 +13,11 @@ class GeoObjectsFilter : public FilterInterface public: // FilterInterface overrides: bool IsAccepted(OsmElement const & element) override; - bool IsAccepted(FeatureBuilder1 const & feature) override; + bool IsAccepted(feature::FeatureBuilder const & feature) override; - static bool IsBuilding(FeatureBuilder1 const & fb); - static bool HasHouse(FeatureBuilder1 const & fb); - static bool IsPoi(FeatureBuilder1 const & fb); + static bool IsBuilding(feature::FeatureBuilder const & fb); + static bool HasHouse(feature::FeatureBuilder const & fb); + static bool IsPoi(feature::FeatureBuilder const & fb); }; } // namespace geo_objects } // namespace generator diff --git a/generator/geometry_holder.hpp b/generator/geometry_holder.hpp index 780d1700cc..31d85d646e 100644 --- a/generator/geometry_holder.hpp +++ b/generator/geometry_holder.hpp @@ -29,7 +29,7 @@ public: // For FeatureType serialization maxNumTriangles should be less than numeric_limits::max // because FeatureType format uses uint8_t to encode the number of triangles. - GeometryHolder(FileGetter geoFileGetter, FileGetter trgFileGetter, FeatureBuilder2 & fb, + GeometryHolder(FileGetter geoFileGetter, FileGetter trgFileGetter, FeatureBuilder & fb, feature::DataHeader const & header, size_t maxNumTriangles = 14) : m_geoFileGetter(geoFileGetter) , m_trgFileGetter(trgFileGetter) @@ -41,7 +41,7 @@ public: { } - GeometryHolder(FeatureBuilder2 & fb, feature::DataHeader const & header, + GeometryHolder(FeatureBuilder & fb, feature::DataHeader const & header, size_t maxNumTriangles = 14) : m_fb(fb) , m_ptsInner(true) @@ -53,7 +53,7 @@ public: void SetInner() { m_trgInner = true; } - FeatureBuilder2::SupportingData & GetBuffer() { return m_buffer; } + FeatureBuilder::SupportingData & GetBuffer() { return m_buffer; } Points const & GetSourcePoints() { @@ -238,9 +238,9 @@ private: FileGetter m_geoFileGetter = {}; FileGetter m_trgFileGetter = {}; - FeatureBuilder2 & m_fb; + FeatureBuilder & m_fb; - FeatureBuilder2::SupportingData m_buffer; + FeatureBuilder::SupportingData m_buffer; Points m_current; bool m_ptsInner, m_trgInner; diff --git a/generator/holes.cpp b/generator/holes.cpp index da6083d54c..88b9273a35 100644 --- a/generator/holes.cpp +++ b/generator/holes.cpp @@ -5,6 +5,8 @@ #include +using namespace feature; + namespace generator { HolesAccumulator::HolesAccumulator(cache::IntermediateDataReader & cache) : @@ -12,10 +14,10 @@ HolesAccumulator::HolesAccumulator(cache::IntermediateDataReader & cache) : { } -FeatureBuilder1::Geometry & HolesAccumulator::GetHoles() +FeatureBuilder::Geometry & HolesAccumulator::GetHoles() { ASSERT(m_holes.empty(), ("It is allowed to call only once.")); - m_merger.ForEachArea(false, [this](FeatureBuilder1::PointSeq const & v, + m_merger.ForEachArea(false, [this](FeatureBuilder::PointSeq const & v, std::vector const & /* way osm ids */) { m_holes.push_back(std::move(v)); diff --git a/generator/holes.hpp b/generator/holes.hpp index e8a4cb997c..c85587acb3 100644 --- a/generator/holes.hpp +++ b/generator/holes.hpp @@ -22,11 +22,11 @@ public: explicit HolesAccumulator(cache::IntermediateDataReader & cache); void operator() (uint64_t id) { m_merger.AddWay(id); } - FeatureBuilder1::Geometry & GetHoles(); + feature::FeatureBuilder::Geometry & GetHoles(); private: AreaWayMerger m_merger; - FeatureBuilder1::Geometry m_holes; + feature::FeatureBuilder::Geometry m_holes; }; /// Find holes for way with 'id' in first relation. @@ -39,7 +39,7 @@ public: base::ControlFlow operator() (uint64_t /* id */, RelationElement const & e); /// 2. "ways in relation" process function void operator() (uint64_t id, std::string const & role); - FeatureBuilder1::Geometry & GetHoles() { return m_holes.GetHoles(); } + feature::FeatureBuilder::Geometry & GetHoles() { return m_holes.GetHoles(); } private: uint64_t m_id; ///< id of way to find it's holes @@ -52,7 +52,7 @@ public: explicit HolesRelation(cache::IntermediateDataReader & cache); void Build(OsmElement const * p); - FeatureBuilder1::Geometry & GetHoles() { return m_holes.GetHoles(); } + feature::FeatureBuilder::Geometry & GetHoles() { return m_holes.GetHoles(); } AreaWayMerger & GetOuter() { return m_outer; } private: diff --git a/generator/locality_sorter.cpp b/generator/locality_sorter.cpp index f869b7ff32..995a239c9a 100644 --- a/generator/locality_sorter.cpp +++ b/generator/locality_sorter.cpp @@ -44,12 +44,12 @@ public: } // FeaturesCollector overrides: - uint32_t Collect(FeatureBuilder1 & fb) override + uint32_t Collect(FeatureBuilder & fb) override { if (fb.IsArea()) { - FeatureBuilder1::Buffer buffer; - fb.SerializeBorder(serial::GeometryCodingParams(), buffer); + FeatureBuilder::Buffer buffer; + fb.SerializeBorderForTmpMwm(serial::GeometryCodingParams(), buffer); WriteFeatureBase(buffer, fb); } return 0; @@ -101,12 +101,10 @@ public: m_writer.Finish(); } - uint32_t Collect(FeatureBuilder1 & fb1) override + uint32_t Collect(FeatureBuilder & fb) override { - auto & fb2 = static_cast(fb1); - // Do not limit inner triangles number to save all geometry without additional sections. - GeometryHolder holder(fb2, m_header, numeric_limits::max() /* maxTrianglesNumber */); + GeometryHolder holder(fb, m_header, numeric_limits::max() /* maxTrianglesNumber */); // Simplify and serialize geometry. vector points; @@ -115,11 +113,11 @@ public: SimplifyPoints(distFn, scales::GetUpperScale(), holder.GetSourcePoints(), points); // For areas we save outer geometry only. - if (fb2.IsArea() && holder.NeedProcessTriangles()) + if (fb.IsArea() && holder.NeedProcessTriangles()) { // At this point we don't need last point equal to first. points.pop_back(); - auto const & polys = fb2.GetGeometry(); + auto const & polys = fb.GetGeometry(); if (polys.size() != 1) { points.clear(); @@ -134,7 +132,7 @@ public: m2::ConvexHull hull(points, 1e-16); vector hullPoints = hull.Points(); holder.SetInner(); - auto const id = fb2.GetMostGenericOsmId(); + auto const id = fb.GetMostGenericOsmId(); if (!holder.TryToMakeStrip(hullPoints)) { LOG(LWARNING, ("Error while building tringles for object with OSM Id:", id.GetSerialId(), @@ -146,10 +144,10 @@ public: } auto & buffer = holder.GetBuffer(); - if (fb2.PreSerializeAndRemoveUselessNames(buffer)) + if (fb.PreSerializeAndRemoveUselessNamesForMwm(buffer)) { - fb2.SerializeLocalityObject(serial::GeometryCodingParams(), buffer); - WriteFeatureBase(buffer.m_buffer, fb2); + fb.SerializeLocalityObject(serial::GeometryCodingParams(), buffer); + WriteFeatureBase(buffer.m_buffer, fb); } return 0; } @@ -192,7 +190,7 @@ bool ParseNodes(string nodesFile, set & nodeIds) return true; } -using NeedSerialize = function; +using NeedSerialize = function; bool GenerateLocalityDataImpl(FeaturesCollector & collector, CalculateMidPoints::MinDrawableScalePolicy const & minDrawableScalePolicy, NeedSerialize const & needSerialize, @@ -215,7 +213,7 @@ bool GenerateLocalityDataImpl(FeaturesCollector & collector, ReaderSource src(reader); src.Skip(point.second); - FeatureBuilder1 f; + FeatureBuilder f; ReadFromSourceRawFormat(src, f); // Emit object. if (needSerialize(f)) @@ -243,9 +241,8 @@ bool GenerateGeoObjectsData(string const & featuresFile, string const & nodesFil if (!ParseNodes(nodesFile, nodeIds)) return false; - auto const needSerialize = [&nodeIds](FeatureBuilder1 & fb) { - auto & fb2 = static_cast(fb); - return fb2.IsPoint() || fb2.IsArea() || + auto const needSerialize = [&nodeIds](FeatureBuilder & fb) { + return fb.IsPoint() || fb.IsArea() || (!fb.GetOsmIds().empty() && nodeIds.count(fb.GetMostGenericOsmId().GetEncodedId()) != 0); }; @@ -269,7 +266,7 @@ bool GenerateRegionsData(string const & featuresFile, string const & dataFile) LocalityCollector regionsCollector(dataFile, header, static_cast(base::SecondsSinceEpoch())); - auto const needSerialize = [](FeatureBuilder1 const & fb) { return fb.IsArea(); }; + auto const needSerialize = [](FeatureBuilder const & fb) { return fb.IsArea(); }; return GenerateLocalityDataImpl(regionsCollector, GetMinDrawableScaleGeometryOnly, needSerialize, featuresFile, dataFile); } @@ -277,7 +274,7 @@ bool GenerateRegionsData(string const & featuresFile, string const & dataFile) bool GenerateBorders(string const & featuresFile, string const & dataFile) { BordersCollector bordersCollector(dataFile); - auto const needSerialize = [](FeatureBuilder1 const & fb) { return fb.IsArea(); }; + auto const needSerialize = [](FeatureBuilder const & fb) { return fb.IsArea(); }; return GenerateLocalityDataImpl(bordersCollector, GetMinDrawableScaleGeometryOnly, needSerialize, featuresFile, dataFile); } diff --git a/generator/maxspeeds_collector.cpp b/generator/maxspeeds_collector.cpp index fab398f1d2..ff1ff33de4 100644 --- a/generator/maxspeeds_collector.cpp +++ b/generator/maxspeeds_collector.cpp @@ -16,6 +16,7 @@ using namespace base; using namespace generator; using namespace routing; +using namespace feature; using namespace std; namespace @@ -32,7 +33,7 @@ bool ParseMaxspeedAndWriteToStream(string const & maxspeed, SpeedInUnits & speed namespace generator { -void MaxspeedsCollector::CollectFeature(FeatureBuilder1 const &, OsmElement const & p) +void MaxspeedsCollector::CollectFeature(FeatureBuilder const &, OsmElement const & p) { if (!p.IsWay()) return; diff --git a/generator/maxspeeds_collector.hpp b/generator/maxspeeds_collector.hpp index b1961e3366..bd10dc61bb 100644 --- a/generator/maxspeeds_collector.hpp +++ b/generator/maxspeeds_collector.hpp @@ -18,7 +18,7 @@ public: explicit MaxspeedsCollector(std::string const & filePath) : m_filePath(filePath) {} // CollectorInterface overrides: - void CollectFeature(FeatureBuilder1 const &, OsmElement const & p) override; + void CollectFeature(feature::FeatureBuilder const &, OsmElement const & p) override; void Save() override; private: diff --git a/generator/metalines_builder.cpp b/generator/metalines_builder.cpp index 299b266d99..1b97d48ead 100644 --- a/generator/metalines_builder.cpp +++ b/generator/metalines_builder.cpp @@ -140,7 +140,7 @@ public: }; // MetalinesBuilder -------------------------------------------------------------------------------- -void MetalinesBuilder::CollectFeature(FeatureBuilder1 const & feature, OsmElement const & element) +void MetalinesBuilder::CollectFeature(FeatureBuilder const & feature, OsmElement const & element) { if (!feature.IsLine()) return; diff --git a/generator/metalines_builder.hpp b/generator/metalines_builder.hpp index a42e8aa148..d2e9577444 100644 --- a/generator/metalines_builder.hpp +++ b/generator/metalines_builder.hpp @@ -21,7 +21,7 @@ public: // CollectorInterface overrides: /// Add a highway segment to the collection of metalines. - void CollectFeature(FeatureBuilder1 const & feature, OsmElement const & element) override; + void CollectFeature(FeatureBuilder const & feature, OsmElement const & element) override; void Save() override; diff --git a/generator/opentable_dataset.cpp b/generator/opentable_dataset.cpp index 6cdbb801f0..63475aa6b5 100644 --- a/generator/opentable_dataset.cpp +++ b/generator/opentable_dataset.cpp @@ -14,6 +14,8 @@ #include "boost/algorithm/string/replace.hpp" +using namespace feature; + namespace generator { // OpentableRestaurant ------------------------------------------------------------------------------ @@ -35,7 +37,7 @@ OpentableRestaurant::OpentableRestaurant(std::string const & src) // OpentableDataset --------------------------------------------------------------------------------- template <> -bool OpentableDataset::NecessaryMatchingConditionHolds(FeatureBuilder1 const & fb) const +bool OpentableDataset::NecessaryMatchingConditionHolds(FeatureBuilder const & fb) const { if (fb.GetName(StringUtf8Multilang::kDefaultCode).empty()) return false; @@ -44,12 +46,12 @@ bool OpentableDataset::NecessaryMatchingConditionHolds(FeatureBuilder1 const & f } template <> -void OpentableDataset::PreprocessMatchedOsmObject(ObjectId const matchedObjId, FeatureBuilder1 & fb, - function const fn) const +void OpentableDataset::PreprocessMatchedOsmObject(ObjectId const matchedObjId, FeatureBuilder & fb, + function const fn) const { auto const & restaurant = m_storage.GetObjectById(matchedObjId); auto & metadata = fb.GetMetadata(); - metadata.Set(feature::Metadata::FMD_SPONSORED_ID, strings::to_string(restaurant.m_id.Get())); + metadata.Set(Metadata::FMD_SPONSORED_ID, strings::to_string(restaurant.m_id.Get())); FeatureParams & params = fb.GetParams(); // params.AddAddress(restaurant.address); @@ -65,7 +67,7 @@ void OpentableDataset::PreprocessMatchedOsmObject(ObjectId const matchedObjId, F } template <> -OpentableDataset::ObjectId OpentableDataset::FindMatchingObjectIdImpl(FeatureBuilder1 const & fb) const +OpentableDataset::ObjectId OpentableDataset::FindMatchingObjectIdImpl(FeatureBuilder const & fb) const { auto const name = fb.GetName(StringUtf8Multilang::kDefaultCode); diff --git a/generator/opentable_scoring.cpp b/generator/opentable_scoring.cpp index a45f7fbe40..8b385eb416 100644 --- a/generator/opentable_scoring.cpp +++ b/generator/opentable_scoring.cpp @@ -3,6 +3,8 @@ #include "generator/opentable_dataset.hpp" #include "generator/feature_builder.hpp" +using namespace feature; + namespace { // Calculated with tools/python/booking_hotels_quality.py. @@ -27,7 +29,7 @@ bool MatchStats::IsMatched() const } template <> -MatchStats Match(OpentableRestaurant const & r, FeatureBuilder1 const & fb) +MatchStats Match(OpentableRestaurant const & r, FeatureBuilder const & fb) { MatchStats score; diff --git a/generator/osm_source.hpp b/generator/osm_source.hpp index fd1ba1ae65..2c69a4da87 100644 --- a/generator/osm_source.hpp +++ b/generator/osm_source.hpp @@ -13,7 +13,6 @@ #include struct OsmElement; -class FeatureBuilder1; class FeatureParams; namespace generator diff --git a/generator/place.cpp b/generator/place.cpp index 59874d0780..c9d776ab22 100644 --- a/generator/place.cpp +++ b/generator/place.cpp @@ -5,9 +5,11 @@ #include "geometry/mercator.hpp" +using namespace feature; + namespace generator { -Place::Place(FeatureBuilder1 const & ft, uint32_t type, bool saveParams) : +Place::Place(FeatureBuilder const & ft, uint32_t type, bool saveParams) : m_ft(ft), m_pt(ft.GetKeyPoint()), m_type(type) diff --git a/generator/place.hpp b/generator/place.hpp index 444cbf9ca9..b96ec87a68 100644 --- a/generator/place.hpp +++ b/generator/place.hpp @@ -13,9 +13,9 @@ namespace generator class Place { public: - Place(FeatureBuilder1 const & ft, uint32_t type, bool saveParams = true); + Place(feature::FeatureBuilder const & ft, uint32_t type, bool saveParams = true); - FeatureBuilder1 const & GetFeature() const { return m_ft; } + feature::FeatureBuilder const & GetFeature() const { return m_ft; } m2::RectD GetLimitRect() const; bool IsEqual(Place const & r) const; /// Check whether we need to replace place @r with place @this. @@ -25,7 +25,7 @@ private: bool IsPoint() const { return (m_ft.GetGeomType() == feature::GeomType::Point); } static bool AreTypesEqual(uint32_t t1, uint32_t t2); - FeatureBuilder1 m_ft; + feature::FeatureBuilder m_ft; m2::PointD m_pt; uint32_t m_type; double m_thresholdM; diff --git a/generator/polygonizer.hpp b/generator/polygonizer.hpp index ea1af9556e..69af0965ab 100644 --- a/generator/polygonizer.hpp +++ b/generator/polygonizer.hpp @@ -45,7 +45,7 @@ public: Finish(); } - void operator()(FeatureBuilder1 & fb) + void operator()(FeatureBuilder & fb) { m_countries.ForEachInRect(fb.GetLimitRect(), [&](auto const & countryPolygons) { auto const need = fb.ForAnyGeometryPoint([&](auto const & point) { @@ -69,7 +69,7 @@ public: { } - void EmitFeature(borders::CountryPolygons const & countryPolygons, FeatureBuilder1 const & fb) + void EmitFeature(borders::CountryPolygons const & countryPolygons, FeatureBuilder const & fb) { if (countryPolygons.m_index == -1) { diff --git a/generator/popularity.cpp b/generator/popularity.cpp index 887cb389c3..3ee3651050 100644 --- a/generator/popularity.cpp +++ b/generator/popularity.cpp @@ -19,11 +19,13 @@ #include #include +using namespace feature; + namespace generator { namespace popularity { -PopularityGeomPlace::PopularityGeomPlace(FeatureBuilder1 const & feature) +PopularityGeomPlace::PopularityGeomPlace(FeatureBuilder const & feature) : m_id(feature.GetMostGenericOsmId()) , m_feature(feature) , m_polygon(std::make_unique()) @@ -55,10 +57,10 @@ PopularityBuilder::PopularityBuilder(std::string const & dataFilename) std::vector PopularityBuilder::Build() const { - std::vector pointObjs; - std::vector geomObjs; + std::vector pointObjs; + std::vector geomObjs; auto const & checker = ftypes::IsPopularityPlaceChecker::Instance(); - feature::ForEachFromDatRawFormat(m_dataFilename, [&](FeatureBuilder1 const & fb, uint64_t /* currPos */) { + ForEachFromDatRawFormat(m_dataFilename, [&](FeatureBuilder const & fb, uint64_t /* currPos */) { if (!checker(fb.GetTypesHolder()) || GetFeatureName(fb).empty()) return; @@ -80,7 +82,7 @@ std::vector PopularityBuilder::Build() const } // static -std::string PopularityBuilder::GetType(FeatureBuilder1 const & feature) +std::string PopularityBuilder::GetType(FeatureBuilder const & feature) { auto const & c = classif(); auto const & checker = ftypes::IsPopularityPlaceChecker::Instance(); @@ -90,19 +92,19 @@ std::string PopularityBuilder::GetType(FeatureBuilder1 const & feature) } // static -std::string PopularityBuilder::GetFeatureName(FeatureBuilder1 const & feature) +std::string PopularityBuilder::GetFeatureName(FeatureBuilder const & feature) { auto const & str = feature.GetParams().name; auto const deviceLang = StringUtf8Multilang::GetLangIndex("ru"); std::string result; - feature::GetReadableName({}, str, deviceLang, false /* allowTranslit */, result); + GetReadableName({}, str, deviceLang, false /* allowTranslit */, result); std::replace(std::begin(result), std::end(result), ';', ','); std::replace(std::begin(result), std::end(result), '\n', ','); return result; } // static -void PopularityBuilder::FillLinesFromPointObjects(std::vector const & pointObjs, +void PopularityBuilder::FillLinesFromPointObjects(std::vector const & pointObjs, MapIdToNode const & m, Tree4d const & tree, std::vector & lines) { @@ -246,11 +248,11 @@ void PopularityBuilder::LinkGeomPlaces(MapIdToNode const & m, Tree4d const & tre // static PopularityBuilder::Node::PtrList -PopularityBuilder::MakeNodes(std::vector const & features) +PopularityBuilder::MakeNodes(std::vector const & features) { Node::PtrList nodes; nodes.reserve(features.size()); - std::transform(std::begin(features), std::end(features), std::back_inserter(nodes), [](FeatureBuilder1 const & f) { + std::transform(std::begin(features), std::end(features), std::back_inserter(nodes), [](FeatureBuilder const & f) { return std::make_shared(PopularityGeomPlace(f)); }); diff --git a/generator/popularity.hpp b/generator/popularity.hpp index acb5ee8fb9..f5758fcbfc 100644 --- a/generator/popularity.hpp +++ b/generator/popularity.hpp @@ -48,11 +48,11 @@ void BuildPopularitySrcFromAllData(std::vector const & dataFilename class PopularityGeomPlace { public: - explicit PopularityGeomPlace(FeatureBuilder1 const & feature); + explicit PopularityGeomPlace(feature::FeatureBuilder const & feature); bool Contains(PopularityGeomPlace const & smaller) const; bool Contains(m2::PointD const & point) const; - FeatureBuilder1 const & GetFeature() const { return m_feature; } + feature::FeatureBuilder const & GetFeature() const { return m_feature; } void DeletePolygon() { m_polygon = nullptr; } double GetArea() const { return m_area; } base::GeoObjectId GetId() const { return m_id; } @@ -62,7 +62,7 @@ private: using BoostPolygon = boost::geometry::model::polygon; base::GeoObjectId m_id; - std::reference_wrapper m_feature; + std::reference_wrapper m_feature; std::unique_ptr m_polygon; double m_area; }; @@ -90,9 +90,9 @@ private: using Tree4d = m4::Tree; using MapIdToNode = std::unordered_map; - static std::string GetType(FeatureBuilder1 const & feature); - static std::string GetFeatureName(FeatureBuilder1 const & feature); - static void FillLinesFromPointObjects(std::vector const & pointObjs, MapIdToNode const & m, + static std::string GetType(feature::FeatureBuilder const & feature); + static std::string GetFeatureName(feature::FeatureBuilder const & feature); + static void FillLinesFromPointObjects(std::vector const & pointObjs, MapIdToNode const & m, Tree4d const & tree, std::vector & lines); static boost::optional FindPointParent(m2::PointD const & point, MapIdToNode const & m, Tree4d const & tree); @@ -105,7 +105,7 @@ private: static void FillLinesFromGeomObjectPtrs(Node::PtrList const & nodes, std::vector & lines); static void LinkGeomPlaces(MapIdToNode const & m, Tree4d const & tree, Node::PtrList & nodes); - static Node::PtrList MakeNodes(std::vector const & features); + static Node::PtrList MakeNodes(std::vector const & features); std::string m_dataFilename; }; diff --git a/generator/regions/collector_region_info.cpp b/generator/regions/collector_region_info.cpp index 78b02b3011..4a6c470c3c 100644 --- a/generator/regions/collector_region_info.cpp +++ b/generator/regions/collector_region_info.cpp @@ -11,6 +11,8 @@ #include +using namespace feature; + namespace generator { namespace regions @@ -60,7 +62,7 @@ char const * GetLabel(PlaceLevel level) CollectorRegionInfo::CollectorRegionInfo(std::string const & filename) : m_filename(filename) {} -void CollectorRegionInfo::CollectFeature(const FeatureBuilder1 &, OsmElement const & el) +void CollectorRegionInfo::CollectFeature(const FeatureBuilder &, OsmElement const & el) { base::GeoObjectId const osmId = GetGeoObjectId(el); RegionData regionData; diff --git a/generator/regions/collector_region_info.hpp b/generator/regions/collector_region_info.hpp index 2a4f5b02dd..42edd19d4f 100644 --- a/generator/regions/collector_region_info.hpp +++ b/generator/regions/collector_region_info.hpp @@ -112,7 +112,7 @@ public: CollectorRegionInfo(std::string const & filename); // CollectorInterface overrides: - void CollectFeature(FeatureBuilder1 const &, OsmElement const & el) override; + void CollectFeature(feature::FeatureBuilder const &, OsmElement const & el) override; void Save() override; private: diff --git a/generator/regions/place_point.hpp b/generator/regions/place_point.hpp index f7109fcd03..ca06caef86 100644 --- a/generator/regions/place_point.hpp +++ b/generator/regions/place_point.hpp @@ -22,7 +22,7 @@ using PlacePointsMap = std::unordered_map; class PlacePoint : public RegionWithName, public RegionWithData { public: - explicit PlacePoint(FeatureBuilder1 const & fb, RegionDataProxy const & rd) + explicit PlacePoint(feature::FeatureBuilder const & fb, RegionDataProxy const & rd) : RegionWithName(fb.GetParams().name), RegionWithData(rd) { diff --git a/generator/regions/region.cpp b/generator/regions/region.cpp index 371a1657ef..83efaa9a00 100644 --- a/generator/regions/region.cpp +++ b/generator/regions/region.cpp @@ -13,6 +13,8 @@ #include +using namespace feature; + namespace generator { namespace regions @@ -33,7 +35,7 @@ BoostPolygon MakePolygonWithRadius(BoostPoint const & point, double radius, size CHECK_EQUAL(result.size(), 1, ()); return std::move(result.front()); } -Region::Region(FeatureBuilder1 const & fb, RegionDataProxy const & rd) +Region::Region(FeatureBuilder const & fb, RegionDataProxy const & rd) : RegionWithName(fb.GetParams().name) , RegionWithData(rd) , m_polygon(std::make_shared()) @@ -84,7 +86,7 @@ void Region::DeletePolygon() m_polygon = nullptr; } -void Region::FillPolygon(FeatureBuilder1 const & fb) +void Region::FillPolygon(FeatureBuilder const & fb) { CHECK(m_polygon, ()); boost_helpers::FillPolygon(*m_polygon, fb); @@ -154,7 +156,7 @@ bool Region::Contains(BoostPoint const & point) const boost::geometry::covered_by(point, *m_polygon); } -bool FeaturePlacePointToRegion(RegionInfo const & regionInfo, FeatureBuilder1 & feature) +bool FeaturePlacePointToRegion(RegionInfo const & regionInfo, FeatureBuilder & feature) { if (!feature.IsPoint()) return false; @@ -172,14 +174,14 @@ bool FeaturePlacePointToRegion(RegionInfo const & regionInfo, FeatureBuilder1 & auto const radius = Region::GetRadiusByPlaceType(placeType); polygon = MakePolygonWithRadius({center.x, center.y}, radius); auto const & outer = polygon.outer(); - FeatureBuilder1::PointSeq seq; + FeatureBuilder::PointSeq seq; std::transform(std::begin(outer), std::end(outer), std::back_inserter(seq), [](BoostPoint const & p) { return m2::PointD(p.get<0>(), p.get<1>()); }); feature.ResetGeometry(); feature.AddPolygon(seq); - feature.SetAreaAddHoles({}); feature.SetRank(0); + feature.SetArea(); return true; } } // namespace regions diff --git a/generator/regions/region.hpp b/generator/regions/region.hpp index f888c9508f..95013be5fa 100644 --- a/generator/regions/region.hpp +++ b/generator/regions/region.hpp @@ -5,7 +5,10 @@ #include -class FeatureBuilder1; +namespace feature +{ +class FeatureBuilder; +} // namespace feature namespace generator { @@ -20,7 +23,7 @@ class PlacePoint; class Region : public RegionWithName, public RegionWithData { public: - explicit Region(FeatureBuilder1 const & fb, RegionDataProxy const & rd); + explicit Region(feature::FeatureBuilder const & fb, RegionDataProxy const & rd); // Build a region and its boundary based on the heuristic. explicit Region(PlacePoint const & place); @@ -41,13 +44,13 @@ public: static double GetRadiusByPlaceType(PlaceType place); private: - void FillPolygon(FeatureBuilder1 const & fb); + void FillPolygon(feature::FeatureBuilder const & fb); std::shared_ptr m_polygon; BoostRect m_rect; double m_area; }; -bool FeaturePlacePointToRegion(RegionInfo const & regionInfo, FeatureBuilder1 & feature); +bool FeaturePlacePointToRegion(RegionInfo const & regionInfo, feature::FeatureBuilder & feature); } // namespace regions } // namespace generator diff --git a/generator/regions/region_base.hpp b/generator/regions/region_base.hpp index 2198b28f0d..464540db53 100644 --- a/generator/regions/region_base.hpp +++ b/generator/regions/region_base.hpp @@ -18,7 +18,7 @@ namespace generator { namespace regions { -using Point = FeatureBuilder1::PointSeq::value_type; +using Point = feature::FeatureBuilder::PointSeq::value_type; using BoostPoint = boost::geometry::model::point; using BoostPolygon = boost::geometry::model::polygon; using BoostRect = boost::geometry::model::box; diff --git a/generator/regions/regions.cpp b/generator/regions/regions.cpp index ca3e5884ce..31fa33426a 100644 --- a/generator/regions/regions.cpp +++ b/generator/regions/regions.cpp @@ -34,6 +34,8 @@ #include "defines.hpp" +using namespace feature; + namespace generator { namespace regions @@ -105,7 +107,7 @@ private: { RegionsBuilder::Regions regions; PlacePointsMap placePointsMap; - auto const toDo = [&](FeatureBuilder1 const & fb, uint64_t /* currPos */) { + auto const toDo = [&](FeatureBuilder const & fb, uint64_t /* currPos */) { if (fb.IsArea() && fb.IsGeometryClosed()) { auto const id = fb.GetMostGenericOsmId(); @@ -119,7 +121,7 @@ private: } }; - feature::ForEachFromDatRawFormat(tmpMwmFilename, toDo); + ForEachFromDatRawFormat(tmpMwmFilename, toDo); return std::make_tuple(std::move(regions), std::move(placePointsMap)); } @@ -149,8 +151,8 @@ private: void RepackTmpMwm(std::set const & ids) { - feature::FeaturesCollector collector(m_pathOutRepackedRegionsTmpMwm); - auto const toDo = [this, &collector, &ids](FeatureBuilder1 & fb, uint64_t /* currPos */) { + FeaturesCollector collector(m_pathOutRepackedRegionsTmpMwm); + auto const toDo = [this, &collector, &ids](FeatureBuilder & fb, uint64_t /* currPos */) { if (ids.count(fb.GetMostGenericOsmId()) == 0 || (fb.IsPoint() && !FeaturePlacePointToRegion(m_regionsInfoCollector, fb))) { @@ -161,7 +163,7 @@ private: collector.Collect(fb); }; - feature::ForEachFromDatRawFormat(m_pathInRegionsTmpMwm, toDo); + ForEachFromDatRawFormat(m_pathInRegionsTmpMwm, toDo); LOG(LINFO, ("Repacked regions temporary mwm saved to", m_pathOutRepackedRegionsTmpMwm)); } diff --git a/generator/restaurants_info/restaurants_info.cpp b/generator/restaurants_info/restaurants_info.cpp index 8878dd0199..450d4364e6 100644 --- a/generator/restaurants_info/restaurants_info.cpp +++ b/generator/restaurants_info/restaurants_info.cpp @@ -26,11 +26,13 @@ DEFINE_string(osm, "", "Input .o5m file"); DEFINE_string(out, "", "Output file path"); +using namespace feature; + namespace { -feature::GenerateInfo GetGenerateInfo() +GenerateInfo GetGenerateInfo() { - feature::GenerateInfo info; + GenerateInfo info; info.m_osmFileName = FLAGS_osm; info.SetNodeStorageType("map"); info.SetOsmFileType("o5m"); @@ -42,7 +44,7 @@ feature::GenerateInfo GetGenerateInfo() return info; } -void DumpRestaurants(std::vector const & features, std::ostream & out) +void DumpRestaurants(std::vector const & features, std::ostream & out) { for (auto const & f : features) { @@ -88,7 +90,7 @@ int main(int argc, char * argv[]) generator::GenerateIntermediateData(info); LOG_SHORT(LINFO, ("OSM data:", FLAGS_osm)); - std::vector features; + std::vector features; generator::CacheLoader cacheLoader(info); generator::TranslatorCollection translators; auto emitter = generator::CreateEmitter(generator::EmitterType::Restaurants, features); diff --git a/generator/road_access_generator.cpp b/generator/road_access_generator.cpp index 311ea82408..15028edc9b 100644 --- a/generator/road_access_generator.cpp +++ b/generator/road_access_generator.cpp @@ -28,6 +28,7 @@ #include "boost/optional.hpp" +using namespace feature; using namespace routing; using namespace std; @@ -379,7 +380,7 @@ void RoadAccessWriter::Open(string const & filePath) LOG(LINFO, ("Cannot open file", filePath)); } -void RoadAccessWriter::CollectFeature(FeatureBuilder1 const &, OsmElement const & elem) +void RoadAccessWriter::CollectFeature(FeatureBuilder const &, OsmElement const & elem) { if (!IsOpened()) { diff --git a/generator/road_access_generator.hpp b/generator/road_access_generator.hpp index 4f061ed1ac..5e2ec3a160 100644 --- a/generator/road_access_generator.hpp +++ b/generator/road_access_generator.hpp @@ -58,7 +58,7 @@ public: RoadAccessWriter(std::string const & filePath); // CollectorInterface overrides: - void CollectFeature(FeatureBuilder1 const &, OsmElement const & elem) override; + void CollectFeature(feature::FeatureBuilder const &, OsmElement const & elem) override; void Save() override {} private: diff --git a/generator/sponsored_dataset.hpp b/generator/sponsored_dataset.hpp index 8830b71739..ad35c40896 100644 --- a/generator/sponsored_dataset.hpp +++ b/generator/sponsored_dataset.hpp @@ -7,7 +7,10 @@ #include #include -class FeatureBuilder1; +namespace feature +{ +class FeatureBuilder; +} // namespace feature namespace generator { @@ -25,24 +28,24 @@ public: /// @return true if |fb| satisfies some necessary conditions to match one or serveral /// objects from dataset. - bool NecessaryMatchingConditionHolds(FeatureBuilder1 const & fb) const; - ObjectId FindMatchingObjectId(FeatureBuilder1 const & e) const; + bool NecessaryMatchingConditionHolds(feature::FeatureBuilder const & fb) const; + ObjectId FindMatchingObjectId(feature::FeatureBuilder const & e) const; // Applies changes to a given osm object (for example, remove hotel type) // and passes the result to |fn|. - void PreprocessMatchedOsmObject(ObjectId matchedObjId, FeatureBuilder1 & fb, - std::function const fn) const; + void PreprocessMatchedOsmObject(ObjectId matchedObjId, feature::FeatureBuilder & fb, + std::function const fn) const; // Creates objects and adds them to the map (MWM) via |fn|. - void BuildOsmObjects(std::function const & fn) const; + void BuildOsmObjects(std::function const & fn) const; SponsoredObjectStorage const & GetStorage() const { return m_storage; } private: void BuildObject(Object const & object, - std::function const & fn) const; + std::function const & fn) const; /// @return an id of a matched object or kInvalidObjectId on failure. - ObjectId FindMatchingObjectIdImpl(FeatureBuilder1 const & fb) const; + ObjectId FindMatchingObjectIdImpl(feature::FeatureBuilder const & fb) const; SponsoredObjectStorage m_storage; }; diff --git a/generator/sponsored_dataset_inl.hpp b/generator/sponsored_dataset_inl.hpp index b186f8a4c9..1dd3cb30a8 100644 --- a/generator/sponsored_dataset_inl.hpp +++ b/generator/sponsored_dataset_inl.hpp @@ -50,7 +50,7 @@ SponsoredDataset::SponsoredDataset(std::string const & dataPath } template -void SponsoredDataset::BuildOsmObjects(function const & fn) const +void SponsoredDataset::BuildOsmObjects(function const & fn) const { for (auto const & item : m_storage.GetObjects()) BuildObject(item.second, fn); @@ -58,7 +58,7 @@ void SponsoredDataset::BuildOsmObjects(function typename SponsoredDataset::ObjectId -SponsoredDataset::FindMatchingObjectId(FeatureBuilder1 const & fb) const +SponsoredDataset::FindMatchingObjectId(feature::FeatureBuilder const & fb) const { if (NecessaryMatchingConditionHolds(fb)) return FindMatchingObjectIdImpl(fb); diff --git a/generator/sponsored_scoring.hpp b/generator/sponsored_scoring.hpp index f1eb3e1773..74f99185e1 100644 --- a/generator/sponsored_scoring.hpp +++ b/generator/sponsored_scoring.hpp @@ -2,7 +2,10 @@ #include -class FeatureBuilder1; +namespace feature +{ +class FeatureBuilder; +} // namespace feature namespace generator { @@ -29,6 +32,6 @@ struct MatchStats /// Matches a given sponsored object against a given OSM object. template -MatchStats Match(SponsoredObject const & o, FeatureBuilder1 const & fb); +MatchStats Match(SponsoredObject const & o, feature::FeatureBuilder const & fb); } // namespace booking_scoring } // namespace generator diff --git a/generator/streets/streets_builder.cpp b/generator/streets/streets_builder.cpp index 4a00338790..7f5418cad2 100644 --- a/generator/streets/streets_builder.cpp +++ b/generator/streets/streets_builder.cpp @@ -9,6 +9,8 @@ #include "3party/jansson/myjansson.hpp" +using namespace feature; + namespace generator { namespace streets @@ -19,20 +21,20 @@ StreetsBuilder::StreetsBuilder(regions::RegionInfoGetter const & regionInfoGette void StreetsBuilder::AssembleStreets(std::string const & pathInStreetsTmpMwm) { - auto const transform = [this](FeatureBuilder1 & fb, uint64_t /* currPos */) { + auto const transform = [this](FeatureBuilder & fb, uint64_t /* currPos */) { AddStreet(fb); }; - feature::ForEachFromDatRawFormat(pathInStreetsTmpMwm, transform); + ForEachFromDatRawFormat(pathInStreetsTmpMwm, transform); } void StreetsBuilder::AssembleBindings(std::string const & pathInGeoObjectsTmpMwm) { - auto const transform = [this](FeatureBuilder1 & fb, uint64_t /* currPos */) { + auto const transform = [this](FeatureBuilder & fb, uint64_t /* currPos */) { auto streetName = fb.GetParams().GetStreet(); if (!streetName.empty()) AddStreetBinding(std::move(streetName), fb); }; - feature::ForEachFromDatRawFormat(pathInGeoObjectsTmpMwm, transform); + ForEachFromDatRawFormat(pathInGeoObjectsTmpMwm, transform); } void StreetsBuilder::SaveStreetsKv(std::ostream & streamStreetsKv) @@ -60,7 +62,7 @@ void StreetsBuilder::SaveRegionStreetsKv(std::ostream & streamStreetsKv, uint64_ } } -void StreetsBuilder::AddStreet(FeatureBuilder1 & fb) +void StreetsBuilder::AddStreet(FeatureBuilder & fb) { auto const region = FindStreetRegionOwner(fb); if (!region) @@ -69,7 +71,7 @@ void StreetsBuilder::AddStreet(FeatureBuilder1 & fb) InsertStreet(*region, fb.GetName(), fb.GetMostGenericOsmId()); } -void StreetsBuilder::AddStreetBinding(std::string && streetName, FeatureBuilder1 & fb) +void StreetsBuilder::AddStreetBinding(std::string && streetName, FeatureBuilder & fb) { auto const region = FindStreetRegionOwner(fb.GetKeyPoint()); if (!region) @@ -78,7 +80,7 @@ void StreetsBuilder::AddStreetBinding(std::string && streetName, FeatureBuilder1 InsertSurrogateStreet(*region, std::move(streetName)); } -boost::optional StreetsBuilder::FindStreetRegionOwner(FeatureBuilder1 & fb) +boost::optional StreetsBuilder::FindStreetRegionOwner(FeatureBuilder & fb) { if (fb.IsPoint()) return FindStreetRegionOwner(fb.GetKeyPoint()); @@ -177,7 +179,7 @@ bool StreetsBuilder::IsStreet(OsmElement const & element) } // static -bool StreetsBuilder::IsStreet(FeatureBuilder1 const & fb) +bool StreetsBuilder::IsStreet(FeatureBuilder const & fb) { if (fb.GetName().empty()) return false; diff --git a/generator/streets/streets_builder.hpp b/generator/streets/streets_builder.hpp index 0d46a531b4..66646fe129 100644 --- a/generator/streets/streets_builder.hpp +++ b/generator/streets/streets_builder.hpp @@ -33,7 +33,7 @@ public: void SaveStreetsKv(std::ostream & streamStreetsKv); static bool IsStreet(OsmElement const & element); - static bool IsStreet(FeatureBuilder1 const & fb); + static bool IsStreet(feature::FeatureBuilder const & fb); private: using RegionStreets = std::unordered_map; @@ -41,9 +41,9 @@ private: void SaveRegionStreetsKv(std::ostream & streamStreetsKv, uint64_t regionId, RegionStreets const & streets); - void AddStreet(FeatureBuilder1 & fb); - void AddStreetBinding(std::string && streetName, FeatureBuilder1 & fb); - boost::optional FindStreetRegionOwner(FeatureBuilder1 & fb); + void AddStreet(feature::FeatureBuilder & fb); + void AddStreetBinding(std::string && streetName, feature::FeatureBuilder & fb); + boost::optional FindStreetRegionOwner(feature::FeatureBuilder & fb); boost::optional FindStreetRegionOwner(m2::PointD const & point); bool InsertStreet(KeyValue const & region, std::string && streetName, base::GeoObjectId id); bool InsertSurrogateStreet(KeyValue const & region, std::string && streetName); diff --git a/generator/streets/streets_filter.cpp b/generator/streets/streets_filter.cpp index 69479e22e9..f8c2e852d5 100644 --- a/generator/streets/streets_filter.cpp +++ b/generator/streets/streets_filter.cpp @@ -3,6 +3,8 @@ #include "generator/streets/streets_builder.hpp" #include "generator/osm_element_helpers.hpp" +using namespace feature; + namespace generator { namespace streets @@ -12,13 +14,13 @@ bool StreetsFilter::IsAccepted(OsmElement const & element) return StreetsBuilder::IsStreet(element); } -bool StreetsFilter::IsAccepted(FeatureBuilder1 const & feature) +bool StreetsFilter::IsAccepted(FeatureBuilder const & feature) { return feature.GetParams().IsValid() && IsStreet(feature); } // static -bool StreetsFilter::IsStreet(FeatureBuilder1 const & fb) +bool StreetsFilter::IsStreet(FeatureBuilder const & fb) { return StreetsBuilder::IsStreet(fb); } diff --git a/generator/streets/streets_filter.hpp b/generator/streets/streets_filter.hpp index 00edafc800..db7736385a 100644 --- a/generator/streets/streets_filter.hpp +++ b/generator/streets/streets_filter.hpp @@ -13,9 +13,9 @@ class StreetsFilter : public FilterInterface public: // FilterInterface overrides: bool IsAccepted(OsmElement const & element) override; - bool IsAccepted(FeatureBuilder1 const & feature) override; + bool IsAccepted(feature::FeatureBuilder const & feature) override; - static bool IsStreet(FeatureBuilder1 const & fb); + static bool IsStreet(feature::FeatureBuilder const & fb); }; } // namespace streets } // namespace generator diff --git a/generator/translator.cpp b/generator/translator.cpp index 1d52c48446..e503c791c9 100644 --- a/generator/translator.cpp +++ b/generator/translator.cpp @@ -7,6 +7,8 @@ #include "base/assert.hpp" +using namespace feature; + namespace generator { Translator::Translator(std::shared_ptr emitter, cache::IntermediateDataReader & cache, @@ -35,7 +37,7 @@ void Translator::Emit(OsmElement & element) m_tagsEnricher(element); m_collectors.Collect(element); m_featureMaker->Add(element); - FeatureBuilder1 feature; + FeatureBuilder feature; while (m_featureMaker->GetNextFeature(feature)) { if (!m_filters.IsAccepted(feature)) diff --git a/generator/translator_coastline.cpp b/generator/translator_coastline.cpp index 869bef3790..14e6e0b3d4 100644 --- a/generator/translator_coastline.cpp +++ b/generator/translator_coastline.cpp @@ -14,6 +14,8 @@ #include "defines.hpp" +using namespace feature; + namespace generator { namespace @@ -21,7 +23,7 @@ namespace class CoastlineFilter : public FilterInterface { public: - bool IsAccepted(FeatureBuilder1 const & feature) + bool IsAccepted(FeatureBuilder const & feature) { auto const & checker = ftypes::IsCoastlineChecker::Instance(); return checker(feature.GetTypes()); diff --git a/generator/translator_region.cpp b/generator/translator_region.cpp index 90a82ef093..6909a0a923 100644 --- a/generator/translator_region.cpp +++ b/generator/translator_region.cpp @@ -12,6 +12,8 @@ #include #include +using namespace feature; + namespace generator { namespace @@ -34,7 +36,7 @@ public: return false; } - bool IsAccepted(FeatureBuilder1 const & feature) override + bool IsAccepted(FeatureBuilder const & feature) override { return feature.GetParams().IsValid() && !feature.IsLine(); } @@ -42,7 +44,7 @@ public: } // namespace TranslatorRegion::TranslatorRegion(std::shared_ptr emitter, cache::IntermediateDataReader & cache, - feature::GenerateInfo const & info) + GenerateInfo const & info) : Translator(emitter, cache, std::make_shared(cache)) { diff --git a/generator/type_helper.cpp b/generator/type_helper.cpp index c7bc1f615f..151b44f531 100644 --- a/generator/type_helper.cpp +++ b/generator/type_helper.cpp @@ -10,7 +10,7 @@ uint32_t GetPlaceType(FeatureParams const & params) return params.FindType(placeType, 1 /* level */); } -uint32_t GetPlaceType(FeatureBuilder1 const & feature) +uint32_t GetPlaceType(feature::FeatureBuilder const & feature) { return GetPlaceType(feature.GetParams()); } diff --git a/generator/type_helper.hpp b/generator/type_helper.hpp index a350f4885e..c9a81aaa86 100644 --- a/generator/type_helper.hpp +++ b/generator/type_helper.hpp @@ -12,5 +12,5 @@ namespace generator { uint32_t GetPlaceType(FeatureParams const & params); -uint32_t GetPlaceType(FeatureBuilder1 const & feature); +uint32_t GetPlaceType(feature::FeatureBuilder const & feature); } // namespace generator diff --git a/generator/wiki_url_dumper.cpp b/generator/wiki_url_dumper.cpp index 0cd6450036..48fdb4833c 100644 --- a/generator/wiki_url_dumper.cpp +++ b/generator/wiki_url_dumper.cpp @@ -14,6 +14,8 @@ #include #include +using namespace feature; + namespace generator { WikiUrlDumper::WikiUrlDumper(std::string const & path, std::vector const & dataFiles) @@ -54,7 +56,7 @@ void WikiUrlDumper::Dump(size_t cpuCount) const void WikiUrlDumper::DumpOne(std::string const & path, std::ostream & stream) { auto const & needWikiUrl = ftypes::WikiChecker::Instance(); - feature::ForEachFromDatRawFormat(path, [&](FeatureBuilder1 const & feature, uint64_t /* pos */) { + feature::ForEachFromDatRawFormat(path, [&](FeatureBuilder const & feature, uint64_t /* pos */) { if (!needWikiUrl(feature.GetTypesHolder())) return; @@ -87,7 +89,7 @@ void WikiDataFilter::FilterOne(std::string const & path, std::map & parts) + void ProcessBoundary(feature::FeatureBuilder const & boundary, std::vector & parts) { auto const & line = boundary.GetGeometry().front(); double constexpr kExtension = 0.01; ProcessState state = ProcessState::Initial; - FeatureBuilder1::PointSeq points; + feature::FeatureBuilder::PointSeq points; for (size_t i = 0; i < line.size(); ++i) { @@ -223,7 +223,7 @@ class WorldMapGenerator } /// This function is called after merging linear features. - void operator()(FeatureBuilder1 const & fb) override + void operator()(feature::FeatureBuilder const & fb) override { // do additional check for suitable size of feature if (NeedPushToWorld(fb) && @@ -231,19 +231,19 @@ class WorldMapGenerator PushSure(fb); } - void CalcStatistics(FeatureBuilder1 const & fb) + void CalcStatistics(feature::FeatureBuilder const & fb) { for (uint32_t type : fb.GetTypes()) ++m_mapTypes[type]; } - bool NeedPushToWorld(FeatureBuilder1 const & fb) const + bool NeedPushToWorld(feature::FeatureBuilder const & fb) const { // GetMinFeatureDrawScale also checks suitable size for AREA features return (scales::GetUpperWorldScale() >= fb.GetMinFeatureDrawScale()); } - void PushSure(FeatureBuilder1 const & fb) { m_output.Collect(fb); } + void PushSure(feature::FeatureBuilder const & fb) { m_output.Collect(fb); } }; EmitterImpl m_worldBucket; @@ -277,7 +277,7 @@ public: LOG(LWARNING, ("popular_places_data option not set. Popular atractions will not be added to World.mwm")); } - void Process(FeatureBuilder1 & fb) + void Process(feature::FeatureBuilder & fb) { auto const isPopularAttraction = IsPopularAttraction(fb); auto const isInternationalAirport = @@ -292,7 +292,7 @@ public: if (!m_boundaryChecker.IsBoundaries(fb)) { // Save original feature iff we need to force push it before PushFeature(fb) modifies fb. - auto originalFeature = forcePushToWorld ? fb : FeatureBuilder1(); + auto originalFeature = forcePushToWorld ? fb : feature::FeatureBuilder(); if (PushFeature(fb) || !forcePushToWorld) return; @@ -307,13 +307,13 @@ public: return; } - std::vector boundaryParts; + std::vector boundaryParts; m_boundaryChecker.ProcessBoundary(fb, boundaryParts); for (auto & f : boundaryParts) PushFeature(f); } - bool PushFeature(FeatureBuilder1 & fb) + bool PushFeature(feature::FeatureBuilder & fb) { switch (fb.GetGeomType()) { @@ -348,7 +348,7 @@ public: void DoMerge() { m_merger.DoMerge(m_worldBucket); } private: - bool IsPopularAttraction(FeatureBuilder1 const & fb) const + bool IsPopularAttraction(feature::FeatureBuilder const & fb) const { if (fb.GetName().empty()) return false; @@ -384,7 +384,7 @@ class SimpleCountryMapGenerator public: SimpleCountryMapGenerator(feature::GenerateInfo const & info) : m_bucket(info) {} - void operator()(FeatureBuilder1 & fb) + void operator()(feature::FeatureBuilder & fb) { m_bucket(fb); } @@ -402,7 +402,7 @@ public: CountryMapGenerator(feature::GenerateInfo const & info) : SimpleCountryMapGenerator(info) {} - void Process(FeatureBuilder1 fb) + void Process(feature::FeatureBuilder fb) { if (feature::PreprocessForCountryMap(fb)) SimpleCountryMapGenerator::operator()(fb); diff --git a/search/search_integration_tests/generate_tests.cpp b/search/search_integration_tests/generate_tests.cpp index 1ad4f31467..53029159d8 100644 --- a/search/search_integration_tests/generate_tests.cpp +++ b/search/search_integration_tests/generate_tests.cpp @@ -21,6 +21,7 @@ #include #include +using namespace feature; using namespace generator::tests_support; using namespace std; @@ -39,10 +40,10 @@ public: ftype::GetNameAndType(&e, params); params.AddName("en", "xxx"); - FeatureBuilder1 fb; + FeatureBuilder fb; fb.SetParams(params); fb.SetCenter(pt); - fb.GetMetadata().Set(feature::Metadata::FMD_TEST_ID, strings::to_string(m_lastId)); + fb.GetMetadata().Set(Metadata::FMD_TEST_ID, strings::to_string(m_lastId)); ++m_lastId; TEST(builder.Add(fb), (fb)); @@ -57,7 +58,7 @@ UNIT_CLASS_TEST(GenerateTest, GenerateDeprecatedTypes) auto file = platform::LocalCountryFile::MakeForTesting("testCountry"); { - TestMwmBuilder builder(file, feature::DataHeader::country); + TestMwmBuilder builder(file, DataHeader::country); // Deprecated types. MakeFeature(builder, {"office", "travel_agent"}, {0, 0}); diff --git a/search/search_integration_tests/processor_test.cpp b/search/search_integration_tests/processor_test.cpp index a2a139f642..349e2eb505 100644 --- a/search/search_integration_tests/processor_test.cpp +++ b/search/search_integration_tests/processor_test.cpp @@ -33,6 +33,7 @@ #include #include +using namespace feature; using namespace generator::tests_support; using namespace search::tests_support; using namespace std; @@ -60,13 +61,13 @@ public: } // TestPOI overrides: - void Serialize(FeatureBuilder1 & fb) const override + void Serialize(FeatureBuilder & fb) const override { TestPOI::Serialize(fb); auto & metadata = fb.GetMetadata(); - metadata.Set(feature::Metadata::FMD_RATING, strings::to_string(m_rating)); - metadata.Set(feature::Metadata::FMD_PRICE_RATE, strings::to_string(m_priceRate)); + metadata.Set(Metadata::FMD_RATING, strings::to_string(m_rating)); + metadata.Set(Metadata::FMD_PRICE_RATE, strings::to_string(m_priceRate)); } private: @@ -83,12 +84,12 @@ public: } // TestPOI overrides: - void Serialize(FeatureBuilder1 & fb) const override + void Serialize(FeatureBuilder & fb) const override { TestCafe::Serialize(fb); auto & metadata = fb.GetMetadata(); - metadata.Set(feature::Metadata::FMD_CUISINE, m_cuisine); + metadata.Set(Metadata::FMD_CUISINE, m_cuisine); } private: @@ -105,12 +106,12 @@ public: } // TestPOI overrides: - void Serialize(FeatureBuilder1 & fb) const override + void Serialize(FeatureBuilder & fb) const override { TestPOI::Serialize(fb); auto & metadata = fb.GetMetadata(); - metadata.Set(feature::Metadata::FMD_AIRPORT_IATA, m_iata); + metadata.Set(Metadata::FMD_AIRPORT_IATA, m_iata); } private: @@ -127,12 +128,12 @@ public: } // TestPOI overrides: - void Serialize(FeatureBuilder1 & fb) const override + void Serialize(FeatureBuilder & fb) const override { TestPOI::Serialize(fb); auto & metadata = fb.GetMetadata(); - metadata.Set(feature::Metadata::FMD_OPERATOR, m_operator); + metadata.Set(Metadata::FMD_OPERATOR, m_operator); } private: @@ -148,12 +149,12 @@ public: } // TestPOI overrides: - void Serialize(FeatureBuilder1 & fb) const override + void Serialize(FeatureBuilder & fb) const override { TestCafe::Serialize(fb); auto & metadata = fb.GetMetadata(); - metadata.Set(feature::Metadata::FMD_BRAND, m_brand); + metadata.Set(Metadata::FMD_BRAND, m_brand); } private: diff --git a/search/search_integration_tests/smoke_test.cpp b/search/search_integration_tests/smoke_test.cpp index 8daf1a4c81..b3ab76c49d 100644 --- a/search/search_integration_tests/smoke_test.cpp +++ b/search/search_integration_tests/smoke_test.cpp @@ -18,6 +18,7 @@ #include +using namespace feature; using namespace generator::tests_support; using namespace search::tests_support; using namespace std; @@ -35,9 +36,9 @@ public: } // TestFeature overrides: - void Serialize(FeatureBuilder1 & fb) const override + void Serialize(FeatureBuilder & fb) const override { - fb.GetMetadata().Set(feature::Metadata::FMD_TEST_ID, strings::to_string(m_id)); + fb.GetMetadata().Set(Metadata::FMD_TEST_ID, strings::to_string(m_id)); fb.SetCenter(m_center); m_names.ForEach([&](int8_t langCode, string const & name) { @@ -102,7 +103,7 @@ UNIT_CLASS_TEST(SmokeTest, Smoke) AlcoShop brandyShop(m2::PointD(0, 1), "Brandy shop", "en"); AlcoShop vodkaShop(m2::PointD(1, 1), "Russian vodka shop", "en"); - auto id = BuildMwm(kCountryName, feature::DataHeader::country, [&](TestMwmBuilder & builder) { + auto id = BuildMwm(kCountryName, DataHeader::country, [&](TestMwmBuilder & builder) { builder.Add(wineShop); builder.Add(tequilaShop); builder.Add(brandyShop); @@ -132,7 +133,7 @@ UNIT_CLASS_TEST(SmokeTest, DeepCategoryTest) SubwayStation redStation(m2::PointD(0, 0), "red", "en"); SubwayStationMoscow blueStation(m2::PointD(1, 1), "blue", "en"); - auto id = BuildMwm(kCountryName, feature::DataHeader::country, [&](TestMwmBuilder & builder) { + auto id = BuildMwm(kCountryName, DataHeader::country, [&](TestMwmBuilder & builder) { builder.Add(redStation); builder.Add(blueStation); }); @@ -225,7 +226,7 @@ UNIT_CLASS_TEST(SmokeTest, CategoriesTest) TestPOI poi(m2::PointD(1.0, 1.0), "poi", "en"); poi.SetTypes({strings::Tokenize(classif().GetFullObjectName(type), "|")}); - auto id = BuildMwm(countryName, feature::DataHeader::country, + auto id = BuildMwm(countryName, DataHeader::country, [&](TestMwmBuilder & builder) { builder.Add(poi); }); SetViewport(m2::RectD(m2::PointD(0.0, 0.0), m2::PointD(2.0, 2.0))); @@ -244,7 +245,7 @@ UNIT_CLASS_TEST(SmokeTest, NotPrefixFreeNames) { char const kCountryName[] = "ATown"; - auto id = BuildMwm(kCountryName, feature::DataHeader::country, [&](TestMwmBuilder & builder) { + auto id = BuildMwm(kCountryName, DataHeader::country, [&](TestMwmBuilder & builder) { builder.Add(TestPOI(m2::PointD(0, 0), "a", "en")); builder.Add(TestPOI(m2::PointD(0, 1), "aa", "en")); builder.Add(TestPOI(m2::PointD(1, 1), "aa", "en")); @@ -293,7 +294,7 @@ UNIT_CLASS_TEST(SmokeTest, PoiWithAddress) cafe.SetStreetName(mainStreet.GetName("en")); cafe.SetHouseNumber("27"); - auto id = BuildMwm(kCountryName, feature::DataHeader::country, [&](TestMwmBuilder & builder) { + auto id = BuildMwm(kCountryName, DataHeader::country, [&](TestMwmBuilder & builder) { builder.Add(mainStreet); builder.Add(cafe); });