forked from organicmaps/organicmaps
[generator] Filters can be cloned.
This commit is contained in:
parent
08b1210b5e
commit
fe907b9b8c
13 changed files with 62 additions and 4 deletions
|
@ -9,6 +9,14 @@ using namespace feature;
|
|||
|
||||
namespace generator
|
||||
{
|
||||
std::shared_ptr<FilterInterface> FilterCollection::Clone() const
|
||||
{
|
||||
auto p = std::make_shared<FilterCollection>();
|
||||
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) {
|
||||
|
|
|
@ -18,6 +18,8 @@ class FilterCollection : public CollectionBase<std::shared_ptr<FilterInterface>>
|
|||
{
|
||||
public:
|
||||
// FilterInterface overrides:
|
||||
std::shared_ptr<FilterInterface> Clone() const override;
|
||||
|
||||
bool IsAccepted(OsmElement const & element) override;
|
||||
bool IsAccepted(feature::FeatureBuilder const & feature) override;
|
||||
};
|
||||
|
|
|
@ -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<char>(stream)), std::istreambuf_iterator<char>());
|
||||
if (!ParseString(str))
|
||||
LOG(LERROR, ("Cannot parse file", filename));
|
||||
LOG(LERROR, ("Cannot parse file", m_filename));
|
||||
}
|
||||
|
||||
std::shared_ptr<FilterInterface> FilterElements::Clone() const
|
||||
{
|
||||
return std::make_shared<FilterElements>(m_filename);
|
||||
}
|
||||
|
||||
bool FilterElements::IsAccepted(OsmElement const & element)
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
@ -75,6 +76,8 @@ public:
|
|||
explicit FilterElements(const std::string & filename);
|
||||
|
||||
// FilterInterface overrides:
|
||||
std::shared_ptr<FilterInterface> 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;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
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<FilterInterface> Clone() const = 0;
|
||||
|
||||
virtual bool IsAccepted(OsmElement const &) { return true; }
|
||||
virtual bool IsAccepted(feature::FeatureBuilder const &) { return true; }
|
||||
};
|
||||
|
|
|
@ -15,6 +15,11 @@ using namespace feature;
|
|||
|
||||
namespace generator
|
||||
{
|
||||
std::shared_ptr<FilterInterface> FilterPlanet::Clone() const
|
||||
{
|
||||
return std::make_shared<FilterPlanet>();
|
||||
}
|
||||
|
||||
bool FilterPlanet::IsAccepted(OsmElement const & element)
|
||||
{
|
||||
if (element.IsRelation())
|
||||
|
|
|
@ -7,6 +7,9 @@ namespace generator
|
|||
class FilterPlanet : public FilterInterface
|
||||
{
|
||||
public:
|
||||
// FilterInterface overrides:
|
||||
std::shared_ptr<FilterInterface> Clone() const override;
|
||||
|
||||
bool IsAccepted(OsmElement const & element) override;
|
||||
bool IsAccepted(feature::FeatureBuilder const & feature) override;
|
||||
};
|
||||
|
|
|
@ -10,6 +10,11 @@ namespace generator
|
|||
{
|
||||
namespace geo_objects
|
||||
{
|
||||
std::shared_ptr<FilterInterface> GeoObjectsFilter::Clone() const
|
||||
{
|
||||
return std::make_shared<GeoObjectsFilter>();
|
||||
}
|
||||
|
||||
bool GeoObjectsFilter::IsAccepted(OsmElement const & element)
|
||||
{
|
||||
return osm_element::IsBuilding(element) || osm_element::HasHouse(element) || osm_element::IsPoi(element);
|
||||
|
|
|
@ -12,6 +12,8 @@ class GeoObjectsFilter : public FilterInterface
|
|||
{
|
||||
public:
|
||||
// FilterInterface overrides:
|
||||
std::shared_ptr<FilterInterface> Clone() const override;
|
||||
|
||||
bool IsAccepted(OsmElement const & element) override;
|
||||
bool IsAccepted(feature::FeatureBuilder const & feature) override;
|
||||
|
||||
|
|
|
@ -9,6 +9,11 @@ namespace generator
|
|||
{
|
||||
namespace streets
|
||||
{
|
||||
std::shared_ptr<FilterInterface> StreetsFilter::Clone() const
|
||||
{
|
||||
return std::make_shared<StreetsFilter>();
|
||||
}
|
||||
|
||||
bool StreetsFilter::IsAccepted(OsmElement const & element)
|
||||
{
|
||||
return StreetsBuilder::IsStreet(element);
|
||||
|
|
|
@ -12,6 +12,8 @@ class StreetsFilter : public FilterInterface
|
|||
{
|
||||
public:
|
||||
// FilterInterface overrides:
|
||||
std::shared_ptr<FilterInterface> Clone() const override;
|
||||
|
||||
bool IsAccepted(OsmElement const & element) override;
|
||||
bool IsAccepted(feature::FeatureBuilder const & feature) override;
|
||||
|
||||
|
|
|
@ -23,7 +23,13 @@ namespace
|
|||
class CoastlineFilter : public FilterInterface
|
||||
{
|
||||
public:
|
||||
bool IsAccepted(FeatureBuilder const & feature)
|
||||
// FilterInterface overrides:
|
||||
std::shared_ptr<FilterInterface> Clone() const override
|
||||
{
|
||||
return std::make_shared<CoastlineFilter>();
|
||||
}
|
||||
|
||||
bool IsAccepted(FeatureBuilder const & feature) override
|
||||
{
|
||||
auto const & checker = ftypes::IsCoastlineChecker::Instance();
|
||||
return checker(feature.GetTypes());
|
||||
|
|
|
@ -22,6 +22,11 @@ class FilterRegions : public FilterInterface
|
|||
{
|
||||
public:
|
||||
// FilterInterface overrides:
|
||||
std::shared_ptr<FilterInterface> Clone() const override
|
||||
{
|
||||
return std::make_shared<FilterRegions>();
|
||||
}
|
||||
|
||||
bool IsAccepted(OsmElement const & element) override
|
||||
{
|
||||
for (auto const & t : element.Tags())
|
||||
|
|
Loading…
Add table
Reference in a new issue