From 089c4e413fbe80711ebd874520d3b8fdcb997112 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 22 Jun 2016 12:31:49 -0700 Subject: [PATCH] [core] Split up and clean up conversion.hpp --- benchmark/parse/filter.cpp | 3 +- include/mbgl/style/conversion.hpp | 389 ++---------------- include/mbgl/style/conversion/constant.hpp | 174 ++++++++ include/mbgl/style/conversion/filter.hpp | 150 +++++++ include/mbgl/style/conversion/function.hpp | 69 ++++ .../mbgl/style/conversion/property_value.hpp | 34 ++ src/mbgl/style/conversion.cpp | 25 -- src/mbgl/style/parser.cpp | 9 +- src/mbgl/style/property_parsing.hpp | 10 +- test/style/filter.cpp | 3 +- 10 files changed, 483 insertions(+), 383 deletions(-) create mode 100644 include/mbgl/style/conversion/constant.hpp create mode 100644 include/mbgl/style/conversion/filter.hpp create mode 100644 include/mbgl/style/conversion/function.hpp create mode 100644 include/mbgl/style/conversion/property_value.hpp delete mode 100644 src/mbgl/style/conversion.cpp diff --git a/benchmark/parse/filter.cpp b/benchmark/parse/filter.cpp index 4269f8e16..24314e858 100644 --- a/benchmark/parse/filter.cpp +++ b/benchmark/parse/filter.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -17,7 +18,7 @@ typedef std::multimap Properties; style::Filter parse(const char* expression) { rapidjson::GenericDocument, rapidjson::CrtAllocator> doc; doc.Parse<0>(expression); - return style::conversion::convertFilter(doc).get(); + return *style::conversion::convert(doc); } static void Parse_Filter(benchmark::State& state) { diff --git a/include/mbgl/style/conversion.hpp b/include/mbgl/style/conversion.hpp index 18326c8dd..eff7e293a 100644 --- a/include/mbgl/style/conversion.hpp +++ b/include/mbgl/style/conversion.hpp @@ -1,39 +1,32 @@ #pragma once -#include -#include -#include - #include -#include -#include -#include - -#include -#include -#include namespace mbgl { namespace style { namespace conversion { /* - This namespace defines a generic conversion from a templated type `V` representing a JSON object conforming - to a style property from the Mapbox Style Specification, to `PropertyValue`: + The `conversion` namespace defines conversions from a templated type `V` representing a JSON + object conforming to the schema defined by the Mapbox Style Specification, to the various C++ + types that form the C++ model of that domain: + + * `std::unique_ptr` + * `std::unique_ptr` + * `Filter` + * `PropertyValue` + + A single template function serves as the public interface: template - Result> convertPropertyValue(const V& value); + Result convert(const V& value); - This is used concretely for conversions from RapidJSON types in mbgl core, and from v8 types in - the node bindings. + Where `T` is one of the above types. If the conversion fails, the `Error` variant of `Result` is + returned, which includes diagnostic text suitable for presentation to a library user. Otherwise, + the `T` variant of `Result` is returned. - It also defines a convertion from `V` to `Filter`, representing a JSON object conforming to a Style - Specification filter object: - - template - Result convertFilter(const V& value); - - The requirements are that the following are legal expressions for a value `v` of type `const V&`: + The implementation of `convert` requires that the following are legal expressions for a value `v` + of type `const V&`: * `isArray(v)` -- returns a boolean indicating whether `v` represents a JSON array * `arrayLength(v)` -- called only if `isArray(v)`; returns a size_t length @@ -51,341 +44,43 @@ namespace conversion { absence indicating `v` is not a boolean, number, or string. Numbers should be converted to unsigned integer, signed integer, or floating point, in descending preference. - If for any reason the conversion fails, the result of `convertPropertyValue` will be the `Error` variant, - which includes explanatory text. + The mbgl core implements these requirements for RapidJSON types, and the node bindings implement + them for v8 types. */ struct Error { const char * message; }; -template -using Result = variant; +template +class Result : private variant { +public: + using variant::variant; -template -struct ConstantConverter {}; + explicit operator bool() const { + return this->template is(); + } -template -struct ConstantConverter { - Result operator()(const V& value) const { - optional converted = toBool(value); - if (!converted) { - return Error { "value must be a boolean" }; - } - return *converted; + T& operator*() { + assert(this->template is()); + return this->template get(); + } + + const T& operator*() const { + assert(this->template is()); + return this->template get(); + } + + const Error& error() const { + assert(this->template is()); + return this->template get(); } }; -template -struct ConstantConverter { - Result operator()(const V& value) const { - optional converted = toNumber(value); - if (!converted) { - return Error { "value must be a number" }; - } - return *converted; - } -}; - -template -struct ConstantConverter { - Result operator()(const V& value) const { - optional converted = toString(value); - if (!converted) { - return Error { "value must be a string" }; - } - return *converted; - } -}; - -template -struct ConstantConverter::value>> { - Result operator()(const V& value) const { - optional string = toString(value); - if (!string) { - return Error { "value must be a string" }; - } - - const auto result = Enum::toEnum(*string); - if (!result) { - return Error { "value must be a valid enumeration value" }; - } - - return *result; - } -}; - -template -struct ConstantConverter { - Result operator()(const V& value) const { - optional string = toString(value); - if (!string) { - return Error { "value must be a string" }; - } - - optional color = Color::parse(*string); - if (!color) { - return Error { "value must be a valid color" }; - } - - return *color; - } -}; - -template -struct ConstantConverter> { - Result> operator()(const V& value) const { - if (!isArray(value) || arrayLength(value) != 2) { - return Error { "value must be an array of two numbers" }; - } - - optional first = toNumber(arrayMember(value, 0)); - optional second = toNumber(arrayMember(value, 1)); - if (!first || !second) { - return Error { "value must be an array of two numbers" }; - } - - return std::array {{ *first, *second }}; - } -}; - -template -struct ConstantConverter> { - Result> operator()(const V& value) const { - if (!isArray(value) || arrayLength(value) != 4) { - return Error { "value must be an array of four numbers" }; - } - - optional first = toNumber(arrayMember(value, 0)); - optional second = toNumber(arrayMember(value, 1)); - optional third = toNumber(arrayMember(value, 2)); - optional fourth = toNumber(arrayMember(value, 3)); - if (!first || !second) { - return Error { "value must be an array of four numbers" }; - } - - return std::array {{ *first, *second, *third, *fourth }}; - } -}; - -template -struct ConstantConverter> { - Result> operator()(const V& value) const { - if (!isArray(value)) { - return Error { "value must be an array" }; - } - - std::vector result; - result.reserve(arrayLength(value)); - - for (std::size_t i = 0; i < arrayLength(value); ++i) { - optional number = toNumber(arrayMember(value, i)); - if (!number) { - return Error { "value must be an array of numbers" }; - } - result.push_back(*number); - } - - return result; - } -}; - -template -struct ConstantConverter> { - Result> operator()(const V& value) const { - if (!isArray(value)) { - return Error { "value must be an array" }; - } - - std::vector result; - result.reserve(arrayLength(value)); - - for (std::size_t i = 0; i < arrayLength(value); ++i) { - optional string = toString(arrayMember(value, i)); - if (!string) { - return Error { "value must be an array of strings" }; - } - result.push_back(*string); - } - - return result; - } -}; +template +struct Converter; template -Result> convertPropertyValue(const V& value) { - if (!isObject(value)) { - Result constant = ConstantConverter()(value); - if (constant.template is()) { - return constant.template get(); - } - return constant.template get(); - } - - auto stopsValue = objectMember(value, "stops"); - if (!stopsValue) { - return Error { "function value must specify stops" }; - } - - if (!isArray(*stopsValue)) { - return Error { "function stops must be an array" }; - } - - std::vector> stops; - for (std::size_t i = 0; i < arrayLength(*stopsValue); ++i) { - const auto& stopValue = arrayMember(*stopsValue, i); - - if (!isArray(stopValue)) { - return Error { "function stop must be an array" }; - } - - if (arrayLength(stopValue) != 2) { - return Error { "function stop must have two elements" }; - } - - optional z = toNumber(arrayMember(stopValue, 0)); - if (!z) { - return Error { "function stop zoom level must be a number" }; - } - - Result v = ConstantConverter()(arrayMember(stopValue, 1)); - if (v.template is()) { - return v.template get(); - } - - stops.emplace_back(*z, v.template get()); - } - - auto baseValue = objectMember(value, "base"); - if (!baseValue) { - return Function(stops, 1.0f); - } - - optional base = toNumber(*baseValue); - if (!base) { - return Error { "function base must be a number"}; - } - - return Function(stops, *base); -} - -Result normalizeFilterValue(const std::string& key, const optional&); - -template -Result convertFilter(const V& value); - -template -Result parseUnaryFilter(const V& value) { - if (arrayLength(value) < 2) { - return Error { "filter expression must have 2 elements" }; - } - - optional key = toString(arrayMember(value, 1)); - if (!key) { - return Error { "filter expression key must be a string" }; - } - - return FilterType { *key }; -} - -template -Result parseBinaryFilter(const V& value) { - if (arrayLength(value) < 3) { - return Error { "filter expression must have 3 elements" }; - } - - optional key = toString(arrayMember(value, 1)); - if (!key) { - return Error { "filter expression key must be a string" }; - } - - Result filterValue = normalizeFilterValue(*key, toValue(arrayMember(value, 2))); - if (filterValue.is()) { - return filterValue.get(); - } - - return FilterType { *key, filterValue.get() }; -} - -template -Result parseSetFilter(const V& value) { - if (arrayLength(value) < 2) { - return Error { "filter expression must at least 2 elements" }; - } - - optional key = toString(arrayMember(value, 1)); - if (!key) { - return Error { "filter expression key must be a string" }; - } - - std::vector values; - for (std::size_t i = 2; i < arrayLength(value); ++i) { - Result filterValue = normalizeFilterValue(*key, toValue(arrayMember(value, i))); - if (filterValue.is()) { - return filterValue.get(); - } - values.push_back(filterValue.get()); - } - - return FilterType { *key, std::move(values) }; -} - -template -Result parseCompoundFilter(const V& value) { - std::vector filters; - for (std::size_t i = 1; i < arrayLength(value); ++i) { - Result element = convertFilter(arrayMember(value, i)); - if (element.is()) { - return element; - } - filters.push_back(element.get()); - } - - return FilterType { std::move(filters) }; -} - -template -Result convertFilter(const V& value) { - if (!isArray(value)) { - return Error { "filter expression must be an array" }; - } - - if (arrayLength(value) < 1) { - return Error { "filter expression must have at least 1 element" }; - } - - optional op = toString(arrayMember(value, 0)); - if (!op) { - return Error { "filter operator must be a string" }; - } - - if (*op == "==") { - return parseBinaryFilter(value); - } else if (*op == "!=") { - return parseBinaryFilter(value); - } else if (*op == ">") { - return parseBinaryFilter(value); - } else if (*op == ">=") { - return parseBinaryFilter(value); - } else if (*op == "<") { - return parseBinaryFilter(value); - } else if (*op == "<=") { - return parseBinaryFilter(value); - } else if (*op == "in") { - return parseSetFilter(value); - } else if (*op == "!in") { - return parseSetFilter(value); - } else if (*op == "all") { - return parseCompoundFilter(value); - } else if (*op == "any") { - return parseCompoundFilter(value); - } else if (*op == "none") { - return parseCompoundFilter(value); - } else if (*op == "has") { - return parseUnaryFilter(value); - } else if (*op == "!has") { - return parseUnaryFilter(value); - } - - return Error { "filter operator must be one of \"==\", \"!=\", \">\", \">=\", \"<\", \"<=\", \"in\", \"!in\", \"all\", \"any\", \"none\", \"has\", or \"!has\"" }; +Result convert(const V& value) { + return Converter()(value); } } // namespace conversion diff --git a/include/mbgl/style/conversion/constant.hpp b/include/mbgl/style/conversion/constant.hpp new file mode 100644 index 000000000..05bf968f4 --- /dev/null +++ b/include/mbgl/style/conversion/constant.hpp @@ -0,0 +1,174 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include +#include + +namespace mbgl { +namespace style { +namespace conversion { + +template <> +struct Converter { + template + Result operator()(const V& value) const { + optional converted = toBool(value); + if (!converted) { + return Error { "value must be a boolean" }; + } + return *converted; + } +}; + +template <> +struct Converter { + template + Result operator()(const V& value) const { + optional converted = toNumber(value); + if (!converted) { + return Error { "value must be a number" }; + } + return *converted; + } +}; + +template <> +struct Converter { + template + Result operator()(const V& value) const { + optional converted = toString(value); + if (!converted) { + return Error { "value must be a string" }; + } + return *converted; + } +}; + +template +struct Converter::value>> { + template + Result operator()(const V& value) const { + optional string = toString(value); + if (!string) { + return Error { "value must be a string" }; + } + + const auto result = Enum::toEnum(*string); + if (!result) { + return Error { "value must be a valid enumeration value" }; + } + + return *result; + } +}; + +template <> +struct Converter { + template + Result operator()(const V& value) const { + optional string = toString(value); + if (!string) { + return Error { "value must be a string" }; + } + + optional color = Color::parse(*string); + if (!color) { + return Error { "value must be a valid color" }; + } + + return *color; + } +}; + +template <> +struct Converter> { + template + Result> operator()(const V& value) const { + if (!isArray(value) || arrayLength(value) != 2) { + return Error { "value must be an array of two numbers" }; + } + + optional first = toNumber(arrayMember(value, 0)); + optional second = toNumber(arrayMember(value, 1)); + if (!first || !second) { + return Error { "value must be an array of two numbers" }; + } + + return std::array {{ *first, *second }}; + } +}; + +template <> +struct Converter> { + template + Result> operator()(const V& value) const { + if (!isArray(value) || arrayLength(value) != 4) { + return Error { "value must be an array of four numbers" }; + } + + optional first = toNumber(arrayMember(value, 0)); + optional second = toNumber(arrayMember(value, 1)); + optional third = toNumber(arrayMember(value, 2)); + optional fourth = toNumber(arrayMember(value, 3)); + if (!first || !second) { + return Error { "value must be an array of four numbers" }; + } + + return std::array {{ *first, *second, *third, *fourth }}; + } +}; + +template <> +struct Converter> { + template + Result> operator()(const V& value) const { + if (!isArray(value)) { + return Error { "value must be an array" }; + } + + std::vector result; + result.reserve(arrayLength(value)); + + for (std::size_t i = 0; i < arrayLength(value); ++i) { + optional number = toNumber(arrayMember(value, i)); + if (!number) { + return Error { "value must be an array of numbers" }; + } + result.push_back(*number); + } + + return result; + } +}; + +template <> +struct Converter> { + template + Result> operator()(const V& value) const { + if (!isArray(value)) { + return Error { "value must be an array" }; + } + + std::vector result; + result.reserve(arrayLength(value)); + + for (std::size_t i = 0; i < arrayLength(value); ++i) { + optional string = toString(arrayMember(value, i)); + if (!string) { + return Error { "value must be an array of strings" }; + } + result.push_back(*string); + } + + return result; + } +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/conversion/filter.hpp b/include/mbgl/style/conversion/filter.hpp new file mode 100644 index 000000000..3ab91e5bb --- /dev/null +++ b/include/mbgl/style/conversion/filter.hpp @@ -0,0 +1,150 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace style { +namespace conversion { + +template <> +struct Converter { +public: + template + Result operator()(const V& value) const { + if (!isArray(value)) { + return Error { "filter expression must be an array" }; + } + + if (arrayLength(value) < 1) { + return Error { "filter expression must have at least 1 element" }; + } + + optional op = toString(arrayMember(value, 0)); + if (!op) { + return Error { "filter operator must be a string" }; + } + + if (*op == "==") { + return convertBinaryFilter(value); + } else if (*op == "!=") { + return convertBinaryFilter(value); + } else if (*op == ">") { + return convertBinaryFilter(value); + } else if (*op == ">=") { + return convertBinaryFilter(value); + } else if (*op == "<") { + return convertBinaryFilter(value); + } else if (*op == "<=") { + return convertBinaryFilter(value); + } else if (*op == "in") { + return convertSetFilter(value); + } else if (*op == "!in") { + return convertSetFilter(value); + } else if (*op == "all") { + return convertCompoundFilter(value); + } else if (*op == "any") { + return convertCompoundFilter(value); + } else if (*op == "none") { + return convertCompoundFilter(value); + } else if (*op == "has") { + return convertUnaryFilter(value); + } else if (*op == "!has") { + return convertUnaryFilter(value); + } + + return Error { "filter operator must be one of \"==\", \"!=\", \">\", \">=\", \"<\", \"<=\", \"in\", \"!in\", \"all\", \"any\", \"none\", \"has\", or \"!has\"" }; + } + +private: + Result normalizeValue(const std::string& key, const optional& value) const { + if (!value) { + return Error { "filter expression value must be a boolean, number, or string" }; + } else if (key != "$type") { + return *value; + } else if (*value == std::string("Point")) { + return Value(uint64_t(FeatureType::Point)); + } else if (*value == std::string("LineString")) { + return Value(uint64_t(FeatureType::LineString)); + } else if (*value == std::string("Polygon")) { + return Value(uint64_t(FeatureType::Polygon)); + } else { + return Error { "value for $type filter must be Point, LineString, or Polygon" }; + } + } + + template + Result convertUnaryFilter(const V& value) const { + if (arrayLength(value) < 2) { + return Error { "filter expression must have 2 elements" }; + } + + optional key = toString(arrayMember(value, 1)); + if (!key) { + return Error { "filter expression key must be a string" }; + } + + return FilterType { *key }; + } + + template + Result convertBinaryFilter(const V& value) const { + if (arrayLength(value) < 3) { + return Error { "filter expression must have 3 elements" }; + } + + optional key = toString(arrayMember(value, 1)); + if (!key) { + return Error { "filter expression key must be a string" }; + } + + Result filterValue = normalizeValue(*key, toValue(arrayMember(value, 2))); + if (!filterValue) { + return filterValue.error(); + } + + return FilterType { *key, *filterValue }; + } + + template + Result convertSetFilter(const V& value) const { + if (arrayLength(value) < 2) { + return Error { "filter expression must at least 2 elements" }; + } + + optional key = toString(arrayMember(value, 1)); + if (!key) { + return Error { "filter expression key must be a string" }; + } + + std::vector values; + for (std::size_t i = 2; i < arrayLength(value); ++i) { + Result filterValue = normalizeValue(*key, toValue(arrayMember(value, i))); + if (!filterValue) { + return filterValue.error(); + } + values.push_back(*filterValue); + } + + return FilterType { *key, std::move(values) }; + } + + template + Result convertCompoundFilter(const V& value) const { + std::vector filters; + for (std::size_t i = 1; i < arrayLength(value); ++i) { + Result element = operator()(arrayMember(value, i)); + if (!element) { + return element.error(); + } + filters.push_back(*element); + } + + return FilterType { std::move(filters) }; + } +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp new file mode 100644 index 000000000..f14b5089b --- /dev/null +++ b/include/mbgl/style/conversion/function.hpp @@ -0,0 +1,69 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace style { +namespace conversion { + +template +struct Converter> { + template + Result> operator()(const V& value) const { + if (!isObject(value)) { + return Error { "function must be an object" }; + } + + auto stopsValue = objectMember(value, "stops"); + if (!stopsValue) { + return Error { "function value must specify stops" }; + } + + if (!isArray(*stopsValue)) { + return Error { "function stops must be an array" }; + } + + std::vector> stops; + for (std::size_t i = 0; i < arrayLength(*stopsValue); ++i) { + const auto& stopValue = arrayMember(*stopsValue, i); + + if (!isArray(stopValue)) { + return Error { "function stop must be an array" }; + } + + if (arrayLength(stopValue) != 2) { + return Error { "function stop must have two elements" }; + } + + optional z = toNumber(arrayMember(stopValue, 0)); + if (!z) { + return Error { "function stop zoom level must be a number" }; + } + + Result v = convert(arrayMember(stopValue, 1)); + if (!v) { + return v.error(); + } + + stops.emplace_back(*z, *v); + } + + auto baseValue = objectMember(value, "base"); + if (!baseValue) { + return Function(stops, 1.0f); + } + + optional base = toNumber(*baseValue); + if (!base) { + return Error { "function base must be a number"}; + } + + return Function(stops, *base); + } +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/conversion/property_value.hpp b/include/mbgl/style/conversion/property_value.hpp new file mode 100644 index 000000000..840643abb --- /dev/null +++ b/include/mbgl/style/conversion/property_value.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include +#include + +namespace mbgl { +namespace style { +namespace conversion { + +template +struct Converter> { + template + Result> operator()(const V& value) const { + if (isObject(value)) { + Result> function = convert>(value); + if (!function) { + return function.error(); + } + return *function; + } else { + Result constant = convert(value); + if (!constant) { + return constant.error(); + } + return *constant; + } + } +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/conversion.cpp b/src/mbgl/style/conversion.cpp deleted file mode 100644 index e863e285c..000000000 --- a/src/mbgl/style/conversion.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include - -namespace mbgl { -namespace style { -namespace conversion { - -Result normalizeFilterValue(const std::string& key, const optional& value) { - if (!value) { - return Error { "filter expression value must be a boolean, number, or string" }; - } else if (key != "$type") { - return *value; - } else if (*value == std::string("Point")) { - return Value(uint64_t(FeatureType::Point)); - } else if (*value == std::string("LineString")) { - return Value(uint64_t(FeatureType::LineString)); - } else if (*value == std::string("Polygon")) { - return Value(uint64_t(FeatureType::Polygon)); - } else { - return Error { "value for $type filter must be Point, LineString, or Polygon" }; - } -} - -} // namespace conversion -} // namespace style -} // namespace mbgl diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp index eddda5d3f..bbe2fd786 100644 --- a/src/mbgl/style/parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -277,11 +278,11 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique } if (value.HasMember("filter")) { - conversion::Result filter = conversion::convertFilter(value["filter"]); - if (filter.is()) { - impl->filter = filter.get(); + conversion::Result filter = conversion::convert(value["filter"]); + if (filter) { + impl->filter = *filter; } else { - Log::Warning(Event::ParseStyle, filter.get().message); + Log::Warning(Event::ParseStyle, filter.error().message); } } diff --git a/src/mbgl/style/property_parsing.hpp b/src/mbgl/style/property_parsing.hpp index 0c750ca29..8c2bd2c0f 100644 --- a/src/mbgl/style/property_parsing.hpp +++ b/src/mbgl/style/property_parsing.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include @@ -12,12 +12,12 @@ namespace style { template PropertyValue parseProperty(const char* name, const JSValue& value) { - conversion::Result> result = conversion::convertPropertyValue(value); - if (result.template is()) { - Log::Warning(Event::ParseStyle, "%s: %s", name, result.template get().message); + conversion::Result> result = conversion::convert>(value); + if (!result) { + Log::Warning(Event::ParseStyle, "%s: %s", name, result.error().message); return {}; } - return result.template get>(); + return *result; } optional parseTransitionOptions(const char * name, const JSValue&); diff --git a/test/style/filter.cpp b/test/style/filter.cpp index fd763896a..2d26a8eb6 100644 --- a/test/style/filter.cpp +++ b/test/style/filter.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -17,7 +18,7 @@ typedef std::multimap Properties; Filter parse(const char * expression) { rapidjson::GenericDocument, rapidjson::CrtAllocator> doc; doc.Parse<0>(expression); - return conversion::convertFilter(doc).get(); + return *conversion::convert(doc); } bool evaluate(const Filter& filter, const Properties& properties, FeatureType type = FeatureType::Unknown) {