summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/style/expression/compound_expression.hpp15
-rw-r--r--include/mbgl/style/expression/literal.hpp3
-rw-r--r--include/mbgl/style/filter.hpp276
-rw-r--r--include/mbgl/style/filter_evaluator.hpp55
4 files changed, 34 insertions, 315 deletions
diff --git a/include/mbgl/style/expression/compound_expression.hpp b/include/mbgl/style/expression/compound_expression.hpp
index 6baaae862f..431afb4d13 100644
--- a/include/mbgl/style/expression/compound_expression.hpp
+++ b/include/mbgl/style/expression/compound_expression.hpp
@@ -36,7 +36,7 @@ template <typename T>
struct Varargs : std::vector<T> { using std::vector<T>::vector; };
namespace detail {
-// Base class for the Signature<Fn> structs that are used to determine the
+// Base class for the Signature<Fn> structs that are used to determine
// each CompoundExpression definition's type::Type data from the type of its
// "evaluate" function.
struct SignatureBase {
@@ -137,10 +137,21 @@ ParseResult parseCompoundExpression(const std::string name, const mbgl::style::c
ParseResult createCompoundExpression(const CompoundExpressionRegistry::Definition& definition,
std::vector<std::unique_ptr<Expression>> args,
ParsingContext& ctx);
-
+
ParseResult createCompoundExpression(const std::string& name,
std::vector<std::unique_ptr<Expression>> args,
ParsingContext& ctx);
+// Convenience method for use expressions that have 0, 1, or 2 args.
+ParseResult createCompoundExpression(const std::string& name, ParsingContext& ctx);
+
+ParseResult createCompoundExpression(const std::string& name,
+ std::unique_ptr<Expression> arg1,
+ ParsingContext& ctx);
+
+ParseResult createCompoundExpression(const std::string& name,
+ std::unique_ptr<Expression> arg1,
+ std::unique_ptr<Expression> arg2,
+ ParsingContext& ctx);
} // namespace expression
} // namespace style
diff --git a/include/mbgl/style/expression/literal.hpp b/include/mbgl/style/expression/literal.hpp
index a00c468efc..d3b3a20cce 100644
--- a/include/mbgl/style/expression/literal.hpp
+++ b/include/mbgl/style/expression/literal.hpp
@@ -51,6 +51,9 @@ private:
Value value;
};
+std::unique_ptr<Literal> createLiteral(const char* value);
+std::unique_ptr<Literal> createLiteral(Value value);
+
} // namespace expression
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/filter.hpp b/include/mbgl/style/filter.hpp
index ccf8dce188..ce4015bb69 100644
--- a/include/mbgl/style/filter.hpp
+++ b/include/mbgl/style/filter.hpp
@@ -11,271 +11,31 @@
namespace mbgl {
namespace style {
-
-class Filter;
-
-class NullFilter {
-public:
- friend bool operator==(const NullFilter&, const NullFilter&) {
- return true;
- }
-};
-
-class EqualsFilter {
-public:
- std::string key;
- Value value;
-
- friend bool operator==(const EqualsFilter& lhs, const EqualsFilter& rhs) {
- return std::tie(lhs.key, lhs.value) == std::tie(rhs.key, rhs.value);
- }
-};
-
-class NotEqualsFilter {
-public:
- std::string key;
- Value value;
-
- friend bool operator==(const NotEqualsFilter& lhs, const NotEqualsFilter& rhs) {
- return std::tie(lhs.key, lhs.value) == std::tie(rhs.key, rhs.value);
- }
-};
-
-class LessThanFilter {
-public:
- std::string key;
- Value value;
-
- friend bool operator==(const LessThanFilter& lhs, const LessThanFilter& rhs) {
- return std::tie(lhs.key, lhs.value) == std::tie(rhs.key, rhs.value);
- }
-};
-
-class LessThanEqualsFilter {
-public:
- std::string key;
- Value value;
-
- friend bool operator==(const LessThanEqualsFilter& lhs, const LessThanEqualsFilter& rhs) {
- return std::tie(lhs.key, lhs.value) == std::tie(rhs.key, rhs.value);
- }
-};
-
-class GreaterThanFilter {
-public:
- std::string key;
- Value value;
-
- friend bool operator==(const GreaterThanFilter& lhs, const GreaterThanFilter& rhs) {
- return std::tie(lhs.key, lhs.value) == std::tie(rhs.key, rhs.value);
- }
-};
-
-class GreaterThanEqualsFilter {
-public:
- std::string key;
- Value value;
-
- friend bool operator==(const GreaterThanEqualsFilter& lhs, const GreaterThanEqualsFilter& rhs) {
- return std::tie(lhs.key, lhs.value) == std::tie(rhs.key, rhs.value);
- }
-};
-
-class InFilter {
-public:
- std::string key;
- std::vector<Value> values;
-
- friend bool operator==(const InFilter& lhs, const InFilter& rhs) {
- return std::tie(lhs.key, lhs.values) == std::tie(rhs.key, rhs.values);
- }
-};
-
-class NotInFilter {
-public:
- std::string key;
- std::vector<Value> values;
-
- friend bool operator==(const NotInFilter& lhs, const NotInFilter& rhs) {
- return std::tie(lhs.key, lhs.values) == std::tie(rhs.key, rhs.values);
- }
-};
-
-class AnyFilter {
-public:
- std::vector<Filter> filters;
-
- friend bool operator==(const AnyFilter& lhs, const AnyFilter& rhs) {
- return lhs.filters == rhs.filters;
- }
-};
-
-class AllFilter {
-public:
- std::vector<Filter> filters;
-
- friend bool operator==(const AllFilter& lhs, const AllFilter& rhs) {
- return lhs.filters == rhs.filters;
- }
-};
-
-class NoneFilter {
-public:
- std::vector<Filter> filters;
-
- friend bool operator==(const NoneFilter& lhs, const NoneFilter& rhs) {
- return lhs.filters == rhs.filters;
- }
-};
-
-class HasFilter {
-public:
- std::string key;
-
- friend bool operator==(const HasFilter& lhs, const HasFilter& rhs) {
- return lhs.key == rhs.key;
- }
-};
-
-class NotHasFilter {
-public:
- std::string key;
-
- friend bool operator==(const NotHasFilter& lhs, const NotHasFilter& rhs) {
- return lhs.key == rhs.key;
- }
-};
-
-
-class TypeEqualsFilter {
-public:
- FeatureType value;
-
- friend bool operator==(const TypeEqualsFilter& lhs, const TypeEqualsFilter& rhs) {
- return lhs.value == rhs.value;
- }
-};
-
-class TypeNotEqualsFilter {
-public:
- FeatureType value;
-
- friend bool operator==(const TypeNotEqualsFilter& lhs, const TypeNotEqualsFilter& rhs) {
- return lhs.value == rhs.value;
- }
-};
-
-class TypeInFilter {
-public:
- std::vector<FeatureType> values;
-
- friend bool operator==(const TypeInFilter& lhs, const TypeInFilter& rhs) {
- return lhs.values == rhs.values;
- }
-};
-
-class TypeNotInFilter {
-public:
- std::vector<FeatureType> values;
-
- friend bool operator==(const TypeNotInFilter& lhs, const TypeNotInFilter& rhs) {
- return lhs.values == rhs.values;
- }
-};
-
-
-class IdentifierEqualsFilter {
-public:
- FeatureIdentifier value;
-
- friend bool operator==(const IdentifierEqualsFilter& lhs, const IdentifierEqualsFilter& rhs) {
- return lhs.value == rhs.value;
- }
-};
-
-class IdentifierNotEqualsFilter {
-public:
- FeatureIdentifier value;
-
- friend bool operator==(const IdentifierNotEqualsFilter& lhs, const IdentifierNotEqualsFilter& rhs) {
- return lhs.value == rhs.value;
- }
-};
-
-class IdentifierInFilter {
-public:
- std::vector<FeatureIdentifier> values;
-
- friend bool operator==(const IdentifierInFilter& lhs, const IdentifierInFilter& rhs) {
- return lhs.values == rhs.values;
- }
-};
-
-class IdentifierNotInFilter {
-public:
- std::vector<FeatureIdentifier> values;
-
- friend bool operator==(const IdentifierNotInFilter& lhs, const IdentifierNotInFilter& rhs) {
- return lhs.values == rhs.values;
- }
-};
-
-class HasIdentifierFilter {
+
+class Filter {
public:
- friend bool operator==(const HasIdentifierFilter&, const HasIdentifierFilter&) {
- return true;
+ optional<std::shared_ptr<const expression::Expression>> expression;
+
+ Filter() : expression() {}
+
+ Filter(expression::ParseResult _expression) : expression(std::move(*_expression)) {
+ assert(!expression || *expression != nullptr);
}
-};
+
+ bool operator()(const expression::EvaluationContext& context) const;
-class NotHasIdentifierFilter {
-public:
- friend bool operator==(const NotHasIdentifierFilter&, const NotHasIdentifierFilter&) {
- return true;
+ friend bool operator==(const Filter& lhs, const Filter& rhs) {
+ if (!lhs.expression || !rhs.expression) {
+ return lhs.expression == rhs.expression;
+ } else {
+ return *(lhs.expression) == *(rhs.expression);
+ }
}
-};
-class ExpressionFilter {
-public:
- std::shared_ptr<const expression::Expression> expression;
-
- friend bool operator==(const ExpressionFilter& lhs, const ExpressionFilter& rhs) {
- return *(lhs.expression) == *(rhs.expression);
+ friend bool operator!=(const Filter& lhs, const Filter& rhs) {
+ return !(lhs == rhs);
}
};
-
-using FilterBase = variant<
- class NullFilter,
- class EqualsFilter,
- class NotEqualsFilter,
- class LessThanFilter,
- class LessThanEqualsFilter,
- class GreaterThanFilter,
- class GreaterThanEqualsFilter,
- class InFilter,
- class NotInFilter,
- class AnyFilter,
- class AllFilter,
- class NoneFilter,
- class HasFilter,
- class NotHasFilter,
- class TypeEqualsFilter,
- class TypeNotEqualsFilter,
- class TypeInFilter,
- class TypeNotInFilter,
- class IdentifierEqualsFilter,
- class IdentifierNotEqualsFilter,
- class IdentifierInFilter,
- class IdentifierNotInFilter,
- class HasIdentifierFilter,
- class NotHasIdentifierFilter,
- class ExpressionFilter>;
-
-class Filter : public FilterBase {
-public:
- using FilterBase::FilterBase;
- bool operator()(const expression::EvaluationContext& context) const;
-};
-
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/filter_evaluator.hpp b/include/mbgl/style/filter_evaluator.hpp
deleted file mode 100644
index a4a4098b3f..0000000000
--- a/include/mbgl/style/filter_evaluator.hpp
+++ /dev/null
@@ -1,55 +0,0 @@
-#pragma once
-
-#include <mbgl/style/filter.hpp>
-#include <mbgl/util/geometry.hpp>
-
-#include <type_traits>
-
-namespace mbgl {
-namespace style {
-
-/*
- A visitor that evaluates a `Filter` for a given feature.
-
- Use via `Filter::operator()`. For example:
-
- if (filter(feature)) {
- // matches the filter
- } else {
- // does not match
- }
-*/
-class FilterEvaluator {
-public:
- const expression::EvaluationContext context;
-
- bool operator()(const NullFilter&) const;
- bool operator()(const EqualsFilter& filter) const;
- bool operator()(const NotEqualsFilter& filter) const;
- bool operator()(const LessThanFilter& filter) const;
- bool operator()(const LessThanEqualsFilter& filter) const;
- bool operator()(const GreaterThanFilter& filter) const;
- bool operator()(const GreaterThanEqualsFilter& filter) const;
- bool operator()(const InFilter& filter) const;
- bool operator()(const NotInFilter& filter) const;
- bool operator()(const AnyFilter& filter) const;
- bool operator()(const AllFilter& filter) const;
- bool operator()(const NoneFilter& filter) const;
- bool operator()(const HasFilter& filter) const;
- bool operator()(const NotHasFilter& filter) const;
- bool operator()(const TypeEqualsFilter& filter) const;
- bool operator()(const TypeNotEqualsFilter& filter) const;
- bool operator()(const TypeInFilter& filter) const;
- bool operator()(const TypeNotInFilter& filter) const;
- bool operator()(const IdentifierEqualsFilter& filter) const;
- bool operator()(const IdentifierNotEqualsFilter& filter) const;
- bool operator()(const IdentifierInFilter& filter) const;
- bool operator()(const IdentifierNotInFilter& filter) const;
- bool operator()(const HasIdentifierFilter&) const;
- bool operator()(const NotHasIdentifierFilter&) const;
- bool operator()(const ExpressionFilter&) const;
-
-};
-
-} // namespace style
-} // namespace mbgl