diff --git a/generator/filter_collection.cpp b/generator/filter_collection.cpp index 511025647a..1d67f6ec3a 100644 --- a/generator/filter_collection.cpp +++ b/generator/filter_collection.cpp @@ -9,6 +9,14 @@ using namespace feature; namespace generator { +std::shared_ptr FilterCollection::Clone() const +{ + auto p = std::make_shared(); + for (auto const & c : m_collection) + p->Append(c->Clone()); + return p; +} + bool FilterCollection::IsAccepted(OsmElement const & element) { return std::all_of(std::begin(m_collection), std::end(m_collection), [&] (auto & filter) { diff --git a/generator/filter_collection.hpp b/generator/filter_collection.hpp index f4690ce20d..4af61beaa2 100644 --- a/generator/filter_collection.hpp +++ b/generator/filter_collection.hpp @@ -18,6 +18,8 @@ class FilterCollection : public CollectionBase> { public: // FilterInterface overrides: + std::shared_ptr Clone() const override; + bool IsAccepted(OsmElement const & element) override; bool IsAccepted(feature::FeatureBuilder const & feature) override; }; diff --git a/generator/filter_elements.cpp b/generator/filter_elements.cpp index 6f8a92cf20..de7affe135 100644 --- a/generator/filter_elements.cpp +++ b/generator/filter_elements.cpp @@ -153,11 +153,17 @@ bool FilterElements::ParseTags(json_t * json, FilterData & fdata) } FilterElements::FilterElements(std::string const & filename) + : m_filename(filename) { - std::ifstream stream(filename); + std::ifstream stream(m_filename); std::string str((std::istreambuf_iterator(stream)), std::istreambuf_iterator()); if (!ParseString(str)) - LOG(LERROR, ("Cannot parse file", filename)); + LOG(LERROR, ("Cannot parse file", m_filename)); +} + +std::shared_ptr FilterElements::Clone() const +{ + return std::make_shared(m_filename); } bool FilterElements::IsAccepted(OsmElement const & element) diff --git a/generator/filter_elements.hpp b/generator/filter_elements.hpp index 3ab8b4e675..4f4af296f0 100644 --- a/generator/filter_elements.hpp +++ b/generator/filter_elements.hpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +76,8 @@ public: explicit FilterElements(const std::string & filename); // FilterInterface overrides: + std::shared_ptr Clone() const override; + bool IsAccepted(OsmElement const & element) override; bool NeedSkip(OsmElement const & element) const; @@ -87,6 +90,8 @@ private: bool NeedSkip(OsmElement const & element, FilterData const & fdata) const; bool ParseString(std::string const & str); + std::string m_filename; + FilterData m_nodes; FilterData m_ways; FilterData m_relations; diff --git a/generator/filter_interface.hpp b/generator/filter_interface.hpp index e786938503..a5a4b2e1f5 100644 --- a/generator/filter_interface.hpp +++ b/generator/filter_interface.hpp @@ -1,5 +1,7 @@ #pragma once +#include + struct OsmElement; namespace feature { @@ -8,12 +10,14 @@ class FeatureBuilder; namespace generator { -// Implementing this interface allows an object to filter OsmElement and FeatureBuilder1 elements. +// Implementing this interface allows an object to filter OsmElement and FeatureBuilder elements. class FilterInterface { public: virtual ~FilterInterface() = default; + virtual std::shared_ptr Clone() const = 0; + virtual bool IsAccepted(OsmElement const &) { return true; } virtual bool IsAccepted(feature::FeatureBuilder const &) { return true; } }; diff --git a/generator/filter_planet.cpp b/generator/filter_planet.cpp index 3e92123613..237ac19652 100644 --- a/generator/filter_planet.cpp +++ b/generator/filter_planet.cpp @@ -15,6 +15,11 @@ using namespace feature; namespace generator { +std::shared_ptr FilterPlanet::Clone() const +{ + return std::make_shared(); +} + bool FilterPlanet::IsAccepted(OsmElement const & element) { if (element.IsRelation()) diff --git a/generator/filter_planet.hpp b/generator/filter_planet.hpp index c35c86dcae..7089ed13f1 100644 --- a/generator/filter_planet.hpp +++ b/generator/filter_planet.hpp @@ -7,6 +7,9 @@ namespace generator class FilterPlanet : public FilterInterface { public: + // FilterInterface overrides: + std::shared_ptr Clone() const override; + bool IsAccepted(OsmElement const & element) override; bool IsAccepted(feature::FeatureBuilder const & feature) override; }; diff --git a/generator/geo_objects/geo_objects_filter.cpp b/generator/geo_objects/geo_objects_filter.cpp index 0d1ba4d494..5d6a242f31 100644 --- a/generator/geo_objects/geo_objects_filter.cpp +++ b/generator/geo_objects/geo_objects_filter.cpp @@ -10,6 +10,11 @@ namespace generator { namespace geo_objects { +std::shared_ptr GeoObjectsFilter::Clone() const +{ + return std::make_shared(); +} + bool GeoObjectsFilter::IsAccepted(OsmElement const & element) { return osm_element::IsBuilding(element) || osm_element::HasHouse(element) || osm_element::IsPoi(element); diff --git a/generator/geo_objects/geo_objects_filter.hpp b/generator/geo_objects/geo_objects_filter.hpp index fccdbdd2fa..7c6f83bd75 100644 --- a/generator/geo_objects/geo_objects_filter.hpp +++ b/generator/geo_objects/geo_objects_filter.hpp @@ -12,6 +12,8 @@ class GeoObjectsFilter : public FilterInterface { public: // FilterInterface overrides: + std::shared_ptr Clone() const override; + bool IsAccepted(OsmElement const & element) override; bool IsAccepted(feature::FeatureBuilder const & feature) override; diff --git a/generator/streets/streets_filter.cpp b/generator/streets/streets_filter.cpp index f8c2e852d5..ce06516194 100644 --- a/generator/streets/streets_filter.cpp +++ b/generator/streets/streets_filter.cpp @@ -9,6 +9,11 @@ namespace generator { namespace streets { +std::shared_ptr StreetsFilter::Clone() const +{ + return std::make_shared(); +} + bool StreetsFilter::IsAccepted(OsmElement const & element) { return StreetsBuilder::IsStreet(element); diff --git a/generator/streets/streets_filter.hpp b/generator/streets/streets_filter.hpp index db7736385a..182993c324 100644 --- a/generator/streets/streets_filter.hpp +++ b/generator/streets/streets_filter.hpp @@ -12,6 +12,8 @@ class StreetsFilter : public FilterInterface { public: // FilterInterface overrides: + std::shared_ptr Clone() const override; + bool IsAccepted(OsmElement const & element) override; bool IsAccepted(feature::FeatureBuilder const & feature) override; diff --git a/generator/translator_coastline.cpp b/generator/translator_coastline.cpp index 14e6e0b3d4..b70f41d14a 100644 --- a/generator/translator_coastline.cpp +++ b/generator/translator_coastline.cpp @@ -23,7 +23,13 @@ namespace class CoastlineFilter : public FilterInterface { public: - bool IsAccepted(FeatureBuilder const & feature) + // FilterInterface overrides: + std::shared_ptr Clone() const override + { + return std::make_shared(); + } + + bool IsAccepted(FeatureBuilder const & feature) override { auto const & checker = ftypes::IsCoastlineChecker::Instance(); return checker(feature.GetTypes()); diff --git a/generator/translator_region.cpp b/generator/translator_region.cpp index 6909a0a923..b0c33584a0 100644 --- a/generator/translator_region.cpp +++ b/generator/translator_region.cpp @@ -22,6 +22,11 @@ class FilterRegions : public FilterInterface { public: // FilterInterface overrides: + std::shared_ptr Clone() const override + { + return std::make_shared(); + } + bool IsAccepted(OsmElement const & element) override { for (auto const & t : element.Tags())