[core] Prepare Filter and FilterEvaluator for extraction (#5366)
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include <mbgl/style/filter.hpp>
|
||||
#include <mbgl/style/filter_evaluator.hpp>
|
||||
#include <mbgl/style/parser.hpp>
|
||||
#include <mbgl/tile/geometry_tile_data.hpp>
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
|
||||
@@ -14,33 +13,6 @@ using namespace mbgl::style;
|
||||
|
||||
typedef std::multimap<std::string, mbgl::Value> Properties;
|
||||
|
||||
class StubFeature : public GeometryTileFeature {
|
||||
public:
|
||||
inline StubFeature(Properties properties_, FeatureType type_)
|
||||
: properties(std::move(properties_))
|
||||
, type(type_)
|
||||
{}
|
||||
|
||||
optional<Value> getValue(const std::string &key) const override {
|
||||
auto it = properties.find(key);
|
||||
if (it == properties.end())
|
||||
return optional<Value>();
|
||||
return it->second;
|
||||
}
|
||||
|
||||
FeatureType getType() const override {
|
||||
return type;
|
||||
}
|
||||
|
||||
GeometryCollection getGeometries() const override {
|
||||
return GeometryCollection();
|
||||
}
|
||||
|
||||
private:
|
||||
const Properties properties;
|
||||
FeatureType type;
|
||||
};
|
||||
|
||||
Filter parse(const char * expression) {
|
||||
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc;
|
||||
doc.Parse<0>(expression);
|
||||
@@ -48,9 +20,12 @@ Filter parse(const char * expression) {
|
||||
}
|
||||
|
||||
bool evaluate(const Filter& filter, const Properties& properties, FeatureType type = FeatureType::Unknown) {
|
||||
StubFeature feature(properties, type);
|
||||
FilterEvaluator evaluator(feature);
|
||||
return Filter::visit(filter, evaluator);
|
||||
return filter(type, [&] (const std::string& key) -> optional<Value> {
|
||||
auto it = properties.find(key);
|
||||
if (it == properties.end())
|
||||
return {};
|
||||
return it->second;
|
||||
});
|
||||
}
|
||||
|
||||
TEST(Filter, EqualsString) {
|
||||
|
||||
Reference in New Issue
Block a user