diff options
author | Anand Thakker <github@anandthakker.net> | 2017-10-26 22:14:27 -0400 |
---|---|---|
committer | Anand Thakker <github@anandthakker.net> | 2017-10-26 22:25:54 -0400 |
commit | 1c861151264fe1d71b3be3774d147eeb76b84aa9 (patch) | |
tree | c8c63765d05ce01be26d882be66c8e909a52363d | |
parent | b6f070a8a937d6fe488977123bee1c6c6b132615 (diff) | |
download | qtlocation-mapboxgl-1c861151264fe1d71b3be3774d147eeb76b84aa9.tar.gz |
Address misc review comments
42 files changed, 166 insertions, 137 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index cd66fccef3..8d30de0a17 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -382,6 +382,7 @@ set(MBGL_CORE_FILES src/mbgl/style/conversion/filter.cpp src/mbgl/style/conversion/geojson.cpp src/mbgl/style/conversion/geojson_options.cpp + src/mbgl/style/conversion/get_json_type.cpp src/mbgl/style/conversion/json.hpp src/mbgl/style/conversion/layer.cpp src/mbgl/style/conversion/light.cpp diff --git a/include/mbgl/style/conversion/data_driven_property_value.hpp b/include/mbgl/style/conversion/data_driven_property_value.hpp index 55e29c4641..2fc98494ac 100644 --- a/include/mbgl/style/conversion/data_driven_property_value.hpp +++ b/include/mbgl/style/conversion/data_driven_property_value.hpp @@ -1,6 +1,5 @@ #pragma once -#include <unordered_set> #include <mbgl/style/data_driven_property_value.hpp> #include <mbgl/style/conversion.hpp> #include <mbgl/style/conversion/constant.hpp> @@ -10,6 +9,9 @@ #include <mbgl/style/expression/curve.hpp> #include <mbgl/style/expression/is_constant.hpp> +#include <unordered_set> + + namespace mbgl { namespace style { namespace conversion { @@ -32,11 +34,9 @@ struct Converter<DataDrivenPropertyValue<T>> { bool zoomConstant = isZoomConstant(expression->get()); - if (!zoomConstant) { - if (!CameraFunction<T>::Curve::findZoomCurve(expression->get())) { - error = { R"("zoom" expression may only be used as input to a top-level "curve" expression.)" }; - return {}; - } + if (!zoomConstant && !CameraFunction<T>::Curve::findZoomCurve(expression->get())) { + error = { R"("zoom" expression may only be used as input to a top-level "curve" expression.)" }; + return {}; } if (isFeatureConstant(expression->get())) { diff --git a/include/mbgl/style/conversion/expression.hpp b/include/mbgl/style/conversion/expression.hpp index 287fcbbe36..21f28ca8c1 100644 --- a/include/mbgl/style/conversion/expression.hpp +++ b/include/mbgl/style/conversion/expression.hpp @@ -1,10 +1,11 @@ #pragma once -#include <memory> #include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/expression/type.hpp> #include <mbgl/style/conversion.hpp> +#include <memory> + namespace mbgl { namespace style { namespace conversion { @@ -12,7 +13,7 @@ namespace conversion { using namespace mbgl::style::expression; template<> struct Converter<std::unique_ptr<Expression>> { - optional<std::unique_ptr<Expression>> operator()(const mbgl::style::conversion::Convertible& value, Error& error, type::Type expected) const { + optional<std::unique_ptr<Expression>> operator()(const Convertible& value, Error& error, type::Type expected) const { std::vector<ParsingError> errors; ParseResult parsed = ParsingContext(errors, expected).parse(value); if (parsed) { diff --git a/include/mbgl/style/conversion/get_json_type.hpp b/include/mbgl/style/conversion/get_json_type.hpp index ce1c5d711a..f7efebccce 100644 --- a/include/mbgl/style/conversion/get_json_type.hpp +++ b/include/mbgl/style/conversion/get_json_type.hpp @@ -1,37 +1,13 @@ #pragma once +#include <mbgl/style/conversion.hpp> #include <string> namespace mbgl { namespace style { namespace conversion { -template <class V> -std::string getJSONType(const V& value) { - using namespace mbgl::style::conversion; - - if (isUndefined(value)) { - return "null"; - } - if (isArray(value)) { - return "array"; - } - if (isObject(value)) { - return "object"; - } - optional<mbgl::Value> v = toValue(value); - - // Since we've already checked the non-atomic types above, value must then - // be a string, number, or boolean -- thus, assume that the toValue() - // conversion succeeds. - assert(v); - - return v->match( - [&] (const std::string&) { return "string"; }, - [&] (bool) { return "boolean"; }, - [&] (auto) { return "number"; } - ); -} +std::string getJSONType(const Convertible& value); } // namespace conversion } // namespace style diff --git a/include/mbgl/style/expression/array_assertion.hpp b/include/mbgl/style/expression/array_assertion.hpp index 4fbd9530ce..10e4bf58c8 100644 --- a/include/mbgl/style/expression/array_assertion.hpp +++ b/include/mbgl/style/expression/array_assertion.hpp @@ -1,15 +1,12 @@ #pragma once -#include <vector> -#include <memory> -#include <mbgl/util/optional.hpp> -#include <mbgl/util/variant.hpp> -#include <mbgl/style/expression/check_subtype.hpp> #include <mbgl/style/expression/expression.hpp> #include <mbgl/style/expression/type.hpp> #include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/conversion.hpp> +#include <memory> + namespace mbgl { namespace style { namespace expression { diff --git a/include/mbgl/style/expression/assertion.hpp b/include/mbgl/style/expression/assertion.hpp index 01c55ae92c..68caa14998 100644 --- a/include/mbgl/style/expression/assertion.hpp +++ b/include/mbgl/style/expression/assertion.hpp @@ -1,5 +1,9 @@ #pragma once #include <mbgl/style/expression/expression.hpp> +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/expression/parsing_context.hpp> +#include <memory> +#include <vector> namespace mbgl { namespace style { diff --git a/include/mbgl/style/expression/at.hpp b/include/mbgl/style/expression/at.hpp index f29c605973..54f08d13a5 100644 --- a/include/mbgl/style/expression/at.hpp +++ b/include/mbgl/style/expression/at.hpp @@ -2,6 +2,7 @@ #include <mbgl/style/expression/expression.hpp> #include <mbgl/style/conversion.hpp> +#include <memory> namespace mbgl { namespace style { diff --git a/include/mbgl/style/expression/boolean_operator.hpp b/include/mbgl/style/expression/boolean_operator.hpp index 284b5cb04f..3a86aba0c1 100644 --- a/include/mbgl/style/expression/boolean_operator.hpp +++ b/include/mbgl/style/expression/boolean_operator.hpp @@ -1,5 +1,8 @@ #pragma once + #include <mbgl/style/expression/expression.hpp> +#include <mbgl/style/conversion.hpp> +#include <memory> namespace mbgl { namespace style { diff --git a/include/mbgl/style/expression/case.hpp b/include/mbgl/style/expression/case.hpp index e54f8651e8..9304b81816 100644 --- a/include/mbgl/style/expression/case.hpp +++ b/include/mbgl/style/expression/case.hpp @@ -1,9 +1,11 @@ #pragma once -#include <mbgl/style/expression/check_subtype.hpp> #include <mbgl/style/expression/expression.hpp> -#include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/conversion.hpp> +#include <mbgl/style/expression/parsing_context.hpp> + +#include <memory> +#include <vector> namespace mbgl { namespace style { diff --git a/include/mbgl/style/expression/check_subtype.hpp b/include/mbgl/style/expression/check_subtype.hpp index b866b80cd8..90e5169de7 100644 --- a/include/mbgl/style/expression/check_subtype.hpp +++ b/include/mbgl/style/expression/check_subtype.hpp @@ -1,9 +1,8 @@ #pragma once -#include <memory> -#include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/expression/type.hpp> #include <mbgl/util/optional.hpp> +#include <memory> namespace mbgl { namespace style { diff --git a/include/mbgl/style/expression/coalesce.hpp b/include/mbgl/style/expression/coalesce.hpp index e3b5ef8e75..2adec91240 100644 --- a/include/mbgl/style/expression/coalesce.hpp +++ b/include/mbgl/style/expression/coalesce.hpp @@ -1,10 +1,11 @@ #pragma once -#include <map> -#include <mbgl/util/interpolate.hpp> #include <mbgl/style/expression/expression.hpp> -#include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/conversion.hpp> +#include <mbgl/style/expression/parsing_context.hpp> + +#include <memory> +#include <map> namespace mbgl { namespace style { diff --git a/include/mbgl/style/expression/coercion.hpp b/include/mbgl/style/expression/coercion.hpp index 882cf2a0c3..79259f1b35 100644 --- a/include/mbgl/style/expression/coercion.hpp +++ b/include/mbgl/style/expression/coercion.hpp @@ -1,5 +1,8 @@ #pragma once #include <mbgl/style/expression/expression.hpp> +#include <mbgl/style/conversion.hpp> +#include <memory> +#include <vector> namespace mbgl { namespace style { diff --git a/include/mbgl/style/expression/compound_expression.hpp b/include/mbgl/style/expression/compound_expression.hpp index 8852f8f955..c9ec5d6735 100644 --- a/include/mbgl/style/expression/compound_expression.hpp +++ b/include/mbgl/style/expression/compound_expression.hpp @@ -1,17 +1,16 @@ #pragma once -#include <array> -#include <vector> -#include <memory> -#include <mbgl/util/optional.hpp> -#include <mbgl/util/variant.hpp> -#include <mbgl/util/color.hpp> -#include <mbgl/style/expression/check_subtype.hpp> #include <mbgl/style/expression/expression.hpp> +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/expression/type.hpp> #include <mbgl/style/expression/value.hpp> -#include <mbgl/style/expression/parsing_context.hpp> -#include <mbgl/style/conversion.hpp> + +#include <mbgl/util/optional.hpp> +#include <mbgl/util/variant.hpp> + +#include <memory> +#include <vector> namespace mbgl { namespace style { diff --git a/include/mbgl/style/expression/curve.hpp b/include/mbgl/style/expression/curve.hpp index 19a167e3ab..ba2347c0a3 100644 --- a/include/mbgl/style/expression/curve.hpp +++ b/include/mbgl/style/expression/curve.hpp @@ -1,13 +1,18 @@ #pragma once -#include <map> -#include <mbgl/util/interpolate.hpp> -#include <mbgl/util/range.hpp> -#include <mbgl/util/unitbezier.hpp> #include <mbgl/style/expression/expression.hpp> +#include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/expression/compound_expression.hpp> -#include <mbgl/style/expression/coalesce.hpp> #include <mbgl/style/expression/let.hpp> +#include <mbgl/style/expression/coalesce.hpp> +#include <mbgl/style/conversion.hpp> + +#include <mbgl/util/interpolate.hpp> +#include <mbgl/util/range.hpp> +#include <mbgl/util/unitbezier.hpp> + +#include <memory> +#include <map> namespace mbgl { diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index 8da38eaffc..d481baa6a1 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -17,11 +17,13 @@ class GeometryTileFeature; namespace style { namespace expression { -struct EvaluationError { +class EvaluationError { +public: std::string message; }; -struct EvaluationParameters { +class EvaluationParameters { +public: EvaluationParameters(float zoom_) : zoom(zoom_), feature(nullptr) {} EvaluationParameters(GeometryTileFeature const * feature_) : zoom(optional<float>()), feature(feature_) {} EvaluationParameters(float zoom_, GeometryTileFeature const * feature_) : @@ -74,7 +76,8 @@ public: } }; -struct EvaluationResult : public Result<Value> { +class EvaluationResult : public Result<Value> { +public: using Result::Result; EvaluationResult(const std::array<double, 4>& arr) : diff --git a/include/mbgl/style/expression/is_expression.hpp b/include/mbgl/style/expression/is_expression.hpp index 7cb2b03863..8eeb0434e4 100644 --- a/include/mbgl/style/expression/is_expression.hpp +++ b/include/mbgl/style/expression/is_expression.hpp @@ -1,7 +1,8 @@ #pragma once -#include <unordered_set> + #include <mbgl/style/expression/expression.hpp> #include <mbgl/style/expression/compound_expression.hpp> +#include <unordered_set> namespace mbgl { namespace style { diff --git a/include/mbgl/style/expression/let.hpp b/include/mbgl/style/expression/let.hpp index a403e20d40..5256ba5409 100644 --- a/include/mbgl/style/expression/let.hpp +++ b/include/mbgl/style/expression/let.hpp @@ -1,9 +1,12 @@ #pragma once -#include <map> #include <mbgl/style/expression/expression.hpp> +#include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/conversion.hpp> +#include <memory> +#include <map> + namespace mbgl { namespace style { namespace expression { diff --git a/include/mbgl/style/expression/literal.hpp b/include/mbgl/style/expression/literal.hpp index e4c12e17d4..836b61097e 100644 --- a/include/mbgl/style/expression/literal.hpp +++ b/include/mbgl/style/expression/literal.hpp @@ -1,16 +1,10 @@ #pragma once -#include <vector> -#include <memory> -#include <mbgl/util/optional.hpp> -#include <mbgl/util/variant.hpp> -#include <mbgl/util/color.hpp> #include <mbgl/style/expression/expression.hpp> -#include <mbgl/style/expression/type.hpp> -#include <mbgl/style/expression/value.hpp> #include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/conversion.hpp> +#include <memory> namespace mbgl { namespace style { diff --git a/include/mbgl/style/expression/match.hpp b/include/mbgl/style/expression/match.hpp index 4a0d35f96e..5ec1e878b2 100644 --- a/include/mbgl/style/expression/match.hpp +++ b/include/mbgl/style/expression/match.hpp @@ -1,16 +1,15 @@ #pragma once -#include <mbgl/style/expression/check_subtype.hpp> #include <mbgl/style/expression/expression.hpp> #include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/conversion.hpp> +#include <memory> + namespace mbgl { namespace style { namespace expression { -using InputType = variant<int64_t, std::string>; - template <typename T> class Match : public Expression { public: diff --git a/include/mbgl/style/expression/parsing_context.hpp b/include/mbgl/style/expression/parsing_context.hpp index 5cdde71346..56d68c19d2 100644 --- a/include/mbgl/style/expression/parsing_context.hpp +++ b/include/mbgl/style/expression/parsing_context.hpp @@ -1,12 +1,14 @@ #pragma once -#include <map> -#include <string> -#include <vector> #include <mbgl/util/optional.hpp> #include <mbgl/style/expression/type.hpp> #include <mbgl/style/conversion.hpp> +#include <map> +#include <string> +#include <vector> +#include <memory> + namespace mbgl { namespace style { namespace expression { @@ -108,7 +110,7 @@ private: : key(std::move(key_)), errors(errors_), expected(std::move(expected_)), - scope(scope_) + scope(std::move(scope_)) {} }; diff --git a/include/mbgl/style/expression/type.hpp b/include/mbgl/style/expression/type.hpp index 6f011676a1..d801cd3ac9 100644 --- a/include/mbgl/style/expression/type.hpp +++ b/include/mbgl/style/expression/type.hpp @@ -1,10 +1,8 @@ #pragma once -#include <unordered_map> -#include <vector> #include <mbgl/util/optional.hpp> #include <mbgl/util/variant.hpp> - +#include <vector> namespace mbgl { namespace style { diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp index c92d0c4e19..8baa9d2dba 100644 --- a/include/mbgl/style/expression/value.hpp +++ b/include/mbgl/style/expression/value.hpp @@ -1,6 +1,5 @@ #pragma once -#include <array> #include <mbgl/style/expression/type.hpp> #include <mbgl/style/position.hpp> #include <mbgl/style/types.hpp> @@ -9,6 +8,8 @@ #include <mbgl/util/feature.hpp> #include <mbgl/util/variant.hpp> +#include <array> +#include <vector> namespace mbgl { namespace style { diff --git a/include/mbgl/style/function/convert.hpp b/include/mbgl/style/function/convert.hpp index 1934e5fe4f..5ae94e343e 100644 --- a/include/mbgl/style/function/convert.hpp +++ b/include/mbgl/style/function/convert.hpp @@ -1,7 +1,5 @@ #pragma once -#include <mbgl/util/enum.hpp> -#include <mbgl/style/types.hpp> #include <mbgl/style/expression/array_assertion.hpp> #include <mbgl/style/expression/assertion.hpp> #include <mbgl/style/expression/case.hpp> @@ -21,6 +19,9 @@ #include <mbgl/style/function/composite_categorical_stops.hpp> #include <mbgl/style/function/identity_stops.hpp> +#include <mbgl/util/enum.hpp> +#include <mbgl/style/types.hpp> + #include <string> diff --git a/platform/node/src/node_expression.hpp b/platform/node/src/node_expression.hpp index e977b58288..7af5b7ab51 100644 --- a/platform/node/src/node_expression.hpp +++ b/platform/node/src/node_expression.hpp @@ -1,9 +1,9 @@ #pragma once -#include <exception> -#include <memory> #include <mbgl/style/conversion.hpp> #include <mbgl/style/expression/expression.hpp> +#include <exception> +#include <memory> #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" diff --git a/src/mbgl/style/conversion/get_json_type.cpp b/src/mbgl/style/conversion/get_json_type.cpp new file mode 100644 index 0000000000..cd3b4608b1 --- /dev/null +++ b/src/mbgl/style/conversion/get_json_type.cpp @@ -0,0 +1,34 @@ +#include <mbgl/style/conversion/get_json_type.hpp> +#include <mbgl/util/feature.hpp> + +namespace mbgl { +namespace style { +namespace conversion { + +std::string getJSONType(const Convertible& value) { + if (isUndefined(value)) { + return "null"; + } + if (isArray(value)) { + return "array"; + } + if (isObject(value)) { + return "object"; + } + optional<mbgl::Value> v = toValue(value); + + // Since we've already checked the non-atomic types above, value must then + // be a string, number, or boolean -- thus, assume that the toValue() + // conversion succeeds. + assert(v); + + return v->match( + [&] (const std::string&) { return "string"; }, + [&] (bool) { return "boolean"; }, + [&] (auto) { return "number"; } + ); +} + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/conversion/stringify.hpp b/src/mbgl/style/conversion/stringify.hpp index df786e5b91..6ae6fede42 100644 --- a/src/mbgl/style/conversion/stringify.hpp +++ b/src/mbgl/style/conversion/stringify.hpp @@ -76,7 +76,7 @@ void stringify(Writer& writer, const std::array<float, 4>& v) { } template <class Writer> -void stringify(Writer&, const mbgl::Value&); +void stringify(Writer&, const Value&); template <class Writer, class T> void stringify(Writer& writer, const std::vector<T>& v) { diff --git a/src/mbgl/style/expression/array_assertion.cpp b/src/mbgl/style/expression/array_assertion.cpp index 73b3674d32..302d1b0178 100644 --- a/src/mbgl/style/expression/array_assertion.cpp +++ b/src/mbgl/style/expression/array_assertion.cpp @@ -1,4 +1,5 @@ #include <mbgl/style/expression/array_assertion.hpp> +#include <mbgl/style/expression/check_subtype.hpp> namespace mbgl { namespace style { @@ -24,8 +25,8 @@ void ArrayAssertion::eachChild(std::function<void(const Expression*)> visit) con visit(input.get()); } -ParseResult ArrayAssertion::parse(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { - using namespace mbgl::style::conversion; +using namespace mbgl::style::conversion; +ParseResult ArrayAssertion::parse(const Convertible& value, ParsingContext ctx) { static std::unordered_map<std::string, type::Type> itemTypes { {"string", type::String}, diff --git a/src/mbgl/style/expression/assertion.cpp b/src/mbgl/style/expression/assertion.cpp index 7e1ef95e7a..c92533ccd2 100644 --- a/src/mbgl/style/expression/assertion.cpp +++ b/src/mbgl/style/expression/assertion.cpp @@ -5,8 +5,8 @@ namespace mbgl { namespace style { namespace expression { -ParseResult Assertion::parse(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { - using namespace mbgl::style::conversion; +using namespace mbgl::style::conversion; +ParseResult Assertion::parse(const Convertible& value, ParsingContext ctx) { static std::unordered_map<std::string, type::Type> types { {"string", type::String}, {"number", type::Number}, diff --git a/src/mbgl/style/expression/at.cpp b/src/mbgl/style/expression/at.cpp index 43d8d82bef..eb354374d3 100644 --- a/src/mbgl/style/expression/at.cpp +++ b/src/mbgl/style/expression/at.cpp @@ -37,8 +37,8 @@ void At::eachChild(std::function<void(const Expression*)> visit) const { visit(input.get()); } -ParseResult At::parse(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { - using namespace mbgl::style::conversion; +using namespace mbgl::style::conversion; +ParseResult At::parse(const Convertible& value, ParsingContext ctx) { assert(isArray(value)); std::size_t length = arrayLength(value); diff --git a/src/mbgl/style/expression/boolean_operator.cpp b/src/mbgl/style/expression/boolean_operator.cpp index 6c184ef173..d4d6aa1e7d 100644 --- a/src/mbgl/style/expression/boolean_operator.cpp +++ b/src/mbgl/style/expression/boolean_operator.cpp @@ -34,9 +34,11 @@ void All::eachChild(std::function<void(const Expression*)> visit) const { } } +using namespace mbgl::style::conversion; + template <class T> -ParseResult parseBooleanOp(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { - using namespace mbgl::style::conversion; +ParseResult parseBooleanOp(const Convertible& value, ParsingContext ctx) { + assert(isArray(value)); auto length = arrayLength(value); @@ -55,11 +57,11 @@ ParseResult parseBooleanOp(const mbgl::style::conversion::Convertible& value, Pa return ParseResult(std::make_unique<T>(std::move(parsedInputs))); } -ParseResult Any::parse(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { +ParseResult Any::parse(const Convertible& value, ParsingContext ctx) { return parseBooleanOp<Any>(value, ctx); } -ParseResult All::parse(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { +ParseResult All::parse(const Convertible& value, ParsingContext ctx) { return parseBooleanOp<All>(value, ctx); } diff --git a/src/mbgl/style/expression/case.cpp b/src/mbgl/style/expression/case.cpp index 4438af8511..e6b402a9f6 100644 --- a/src/mbgl/style/expression/case.cpp +++ b/src/mbgl/style/expression/case.cpp @@ -26,9 +26,8 @@ void Case::eachChild(std::function<void(const Expression*)> visit) const { visit(otherwise.get()); } -ParseResult Case::parse(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { - using namespace mbgl::style::conversion; - +using namespace mbgl::style::conversion; +ParseResult Case::parse(const Convertible& value, ParsingContext ctx) { assert(isArray(value)); auto length = arrayLength(value); if (length < 4) { diff --git a/src/mbgl/style/expression/coalesce.cpp b/src/mbgl/style/expression/coalesce.cpp index 479aae1a1a..452fc9a2ce 100644 --- a/src/mbgl/style/expression/coalesce.cpp +++ b/src/mbgl/style/expression/coalesce.cpp @@ -5,12 +5,12 @@ namespace style { namespace expression { EvaluationResult Coalesce::evaluate(const EvaluationParameters& params) const { - for (auto it = args.begin(); it != args.end(); it++) { - const EvaluationResult result = (*it)->evaluate(params); - if (!result || *result != Null || std::next(it) == args.end()) return result; + EvaluationResult result = Null; + for (const auto& arg : args) { + result = arg->evaluate(params); + if (!result || *result != Null) break; } - - return Null; + return result; } void Coalesce::eachChild(std::function<void(const Expression*)> visit) const { @@ -19,8 +19,8 @@ void Coalesce::eachChild(std::function<void(const Expression*)> visit) const { } } -ParseResult Coalesce::parse(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { - using namespace mbgl::style::conversion; +using namespace mbgl::style::conversion; +ParseResult Coalesce::parse(const Convertible& value, ParsingContext ctx) { assert(isArray(value)); auto length = arrayLength(value); if (length < 2) { diff --git a/src/mbgl/style/expression/coercion.cpp b/src/mbgl/style/expression/coercion.cpp index b4ac98def4..3e289b7c96 100644 --- a/src/mbgl/style/expression/coercion.cpp +++ b/src/mbgl/style/expression/coercion.cpp @@ -80,8 +80,8 @@ Coercion::Coercion(type::Type type_, std::vector<std::unique_ptr<Expression>> in } } -ParseResult Coercion::parse(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { - using namespace mbgl::style::conversion; +using namespace mbgl::style::conversion; +ParseResult Coercion::parse(const Convertible& value, ParsingContext ctx) { static std::unordered_map<std::string, type::Type> types { {"to-number", type::Number}, {"to-color", type::Color} diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp index 2a9e973023..637196cef6 100644 --- a/src/mbgl/style/expression/compound_expression.cpp +++ b/src/mbgl/style/expression/compound_expression.cpp @@ -436,9 +436,8 @@ std::unordered_map<std::string, CompoundExpressionRegistry::Definition> initiali std::unordered_map<std::string, Definition> CompoundExpressionRegistry::definitions = initializeDefinitions(); - -ParseResult parseCompoundExpression(const std::string name, const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { - using namespace mbgl::style::conversion; +using namespace mbgl::style::conversion; +ParseResult parseCompoundExpression(const std::string name, const Convertible& value, ParsingContext ctx) { assert(isArray(value) && arrayLength(value) > 0); auto it = CompoundExpressionRegistry::definitions.find(name); diff --git a/src/mbgl/style/expression/curve.cpp b/src/mbgl/style/expression/curve.cpp index c03250a50f..d34ac1cadd 100644 --- a/src/mbgl/style/expression/curve.cpp +++ b/src/mbgl/style/expression/curve.cpp @@ -9,8 +9,9 @@ using Interpolator = variant<StepInterpolator, ExponentialInterpolator, CubicBezierInterpolator>; -ParseResult parseCurve(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { - using namespace mbgl::style::conversion; +using namespace mbgl::style::conversion; + +ParseResult parseCurve(const Convertible& value, ParsingContext ctx) { assert(isArray(value)); auto length = arrayLength(value); @@ -21,7 +22,7 @@ ParseResult parseCurve(const mbgl::style::conversion::Convertible& value, Parsin ctx.error("Expected an interpolation type expression."); return ParseResult(); } - const mbgl::style::conversion::Convertible& interp = arrayMember(value, 1); + const Convertible& interp = arrayMember(value, 1); if (!isArray(interp) || arrayLength(interp) == 0) { ctx.error("Expected an interpolation type expression."); return ParseResult(); diff --git a/src/mbgl/style/expression/is_expression.cpp b/src/mbgl/style/expression/is_expression.cpp index c7f6599d94..0ed3ac594e 100644 --- a/src/mbgl/style/expression/is_expression.cpp +++ b/src/mbgl/style/expression/is_expression.cpp @@ -5,9 +5,9 @@ namespace mbgl { namespace style { namespace expression { -bool isExpression(const conversion::Convertible& value) { - using namespace mbgl::style::conversion; - +using namespace mbgl::style::conversion; + +bool isExpression(const Convertible& value) { static std::unordered_set<std::string> specialForms = { "all", "any", diff --git a/src/mbgl/style/expression/let.cpp b/src/mbgl/style/expression/let.cpp index 27b99c9640..d5c4403052 100644 --- a/src/mbgl/style/expression/let.cpp +++ b/src/mbgl/style/expression/let.cpp @@ -16,8 +16,9 @@ void Let::eachChild(std::function<void(const Expression*)> visit) const { visit(result.get()); } -ParseResult Let::parse(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { - using namespace mbgl::style::conversion; +using namespace mbgl::style::conversion; + +ParseResult Let::parse(const Convertible& value, ParsingContext ctx) { assert(isArray(value)); std::size_t length = arrayLength(value); @@ -66,8 +67,7 @@ EvaluationResult Var::evaluate(const EvaluationParameters& params) const { void Var::eachChild(std::function<void(const Expression*)>) const {} -ParseResult Var::parse(const mbgl::style::conversion::Convertible& value_, ParsingContext ctx) { - using namespace mbgl::style::conversion; +ParseResult Var::parse(const Convertible& value_, ParsingContext ctx) { assert(isArray(value_)); if (arrayLength(value_) != 2 || !toString(arrayMember(value_, 1))) { diff --git a/src/mbgl/style/expression/literal.cpp b/src/mbgl/style/expression/literal.cpp index 402e56de96..900ebe2afb 100644 --- a/src/mbgl/style/expression/literal.cpp +++ b/src/mbgl/style/expression/literal.cpp @@ -14,8 +14,8 @@ optional<Value> checkNumber(T n) { } } -optional<Value> parseValue(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { - using namespace mbgl::style::conversion; +using namespace mbgl::style::conversion; +optional<Value> parseValue(const Convertible& value, ParsingContext ctx) { if (isUndefined(value)) return {Null}; if (isObject(value)) { std::unordered_map<std::string, Value> result; @@ -61,7 +61,7 @@ optional<Value> parseValue(const mbgl::style::conversion::Convertible& value, Pa ); } -ParseResult Literal::parse(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { +ParseResult Literal::parse(const Convertible& value, ParsingContext ctx) { const optional<Value> parsedValue = parseValue(value, ctx); if (!parsedValue) { diff --git a/src/mbgl/style/expression/match.cpp b/src/mbgl/style/expression/match.cpp index b058e09bf0..414221b957 100644 --- a/src/mbgl/style/expression/match.cpp +++ b/src/mbgl/style/expression/match.cpp @@ -49,8 +49,10 @@ template<> EvaluationResult Match<int64_t>::evaluate(const EvaluationParameters& template class Match<int64_t>; template class Match<std::string>; +using InputType = variant<int64_t, std::string>; -optional<InputType> parseInputValue(const mbgl::style::conversion::Convertible& input, ParsingContext ctx, optional<type::Type>& inputType) { +using namespace mbgl::style::conversion; +optional<InputType> parseInputValue(const Convertible& input, ParsingContext ctx, optional<type::Type>& inputType) { using namespace mbgl::style::conversion; optional<InputType> result; optional<type::Type> type; @@ -144,9 +146,7 @@ static ParseResult create(type::Type outputType, )); } -ParseResult parseMatch(const mbgl::style::conversion::Convertible& value, ParsingContext ctx) { - using namespace mbgl::style::conversion; - +ParseResult parseMatch(const Convertible& value, ParsingContext ctx) { assert(isArray(value)); auto length = arrayLength(value); if (length < 5) { diff --git a/src/mbgl/style/expression/parsing_context.cpp b/src/mbgl/style/expression/parsing_context.cpp index 9b8a352c7b..f874aed81d 100644 --- a/src/mbgl/style/expression/parsing_context.cpp +++ b/src/mbgl/style/expression/parsing_context.cpp @@ -49,10 +49,9 @@ bool isConstant(const Expression* expression) { isGlobalPropertyConstant(expression, std::array<std::string, 2>{{"zoom", "heatmap-density"}}); } -ParseResult ParsingContext::parse(const mbgl::style::conversion::Convertible& value) +using namespace mbgl::style::conversion; +ParseResult ParsingContext::parse(const Convertible& value) { - using namespace mbgl::style::conversion; - ParseResult parsed; if (isArray(value)) { diff --git a/src/mbgl/style/expression/util.cpp b/src/mbgl/style/expression/util.cpp index 637922dfbd..f198fb3e1b 100644 --- a/src/mbgl/style/expression/util.cpp +++ b/src/mbgl/style/expression/util.cpp @@ -1,5 +1,5 @@ -#include "util.hpp" +#include <mbgl/style/expression/util.hpp> #include <mbgl/style/expression/value.hpp> namespace mbgl { diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp index 4b0e828b31..0b2940a0e0 100644 --- a/test/style/conversion/stringify.test.cpp +++ b/test/style/conversion/stringify.test.cpp @@ -69,9 +69,9 @@ TEST(Stringify, Map) { } TEST(Stringify, Value) { - ASSERT_EQ(stringify(mbgl::Value(true)), "true"); - ASSERT_EQ(stringify(mbgl::Value(uint64_t(0))), "0"); - ASSERT_EQ(stringify(mbgl::Value(1.2)), "1.2"); + ASSERT_EQ(stringify(Value(true)), "true"); + ASSERT_EQ(stringify(Value(uint64_t(0))), "0"); + ASSERT_EQ(stringify(Value(1.2)), "1.2"); } TEST(Stringify, Filter) { |