From 2b834001cca8c2b0552c106dd404da1b238f043b Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Tue, 24 Sep 2019 17:44:39 +0300 Subject: [core] type aliases and conversion traits for mapbox::base::Value --- include/mbgl/style/conversion_impl.hpp | 54 +++++++++++++++++++++++++++++++++- include/mbgl/util/feature.hpp | 10 +++---- next/CMakeLists.txt | 1 + next/platform/android/android.cmake | 1 + scripts/generate-file-lists.js | 3 +- src/mbgl/util/color.cpp | 8 ++--- vendor/mapbox-base-files.json | 1 + 7 files changed, 67 insertions(+), 11 deletions(-) diff --git a/include/mbgl/style/conversion_impl.hpp b/include/mbgl/style/conversion_impl.hpp index f049ba4ffb..7ac4ec649b 100644 --- a/include/mbgl/style/conversion_impl.hpp +++ b/include/mbgl/style/conversion_impl.hpp @@ -1,11 +1,17 @@ #pragma once +#include #include -#include +#include #include #include +#include +#include + +#include #include +#include namespace mbgl { namespace style { @@ -288,6 +294,52 @@ optional convert(const Convertible& value, Error& error, Args&&...args) { return Converter()(value, error, std::forward(args)...); } +template +struct ValueFactory; + +template +struct ValueArrayFactory { + static Value make(const T& arg) { return mapbox::base::ValueArray(arg.begin(), arg.end()); } +}; + +template <> +struct ValueFactory> : public ValueArrayFactory> {}; + +template <> +struct ValueFactory> : public ValueArrayFactory> {}; + +template <> +struct ValueFactory { + static Value make(const ColorRampPropertyValue& value) { return value.getExpression().serialize(); } +}; + +template <> +struct ValueFactory { + static Value make(const Color& color) { return color.toObject(); } +}; + +template +struct ValueFactory::value>::type> { + static Value make(const T& arg) { return {arg}; } +}; + +template +struct ValueFactory::value>::type> { + static Value make(T arg) { return {int64_t(arg)}; } +}; + +template +Value makeValue(T&& arg) { + return ValueFactory>::make(std::forward(arg)); +} + +template +Value makeValue(const PropertyValue& value) { + return value.match([](const Undefined&) -> Value { return {}; }, + [](const T& t) -> Value { return makeValue(t); }, + [](const PropertyExpression& fn) { return fn.getExpression().serialize(); }); +} + } // namespace conversion } // namespace style } // namespace mbgl diff --git a/include/mbgl/util/feature.hpp b/include/mbgl/util/feature.hpp index 390cc65720..6080976945 100644 --- a/include/mbgl/util/feature.hpp +++ b/include/mbgl/util/feature.hpp @@ -3,16 +3,16 @@ #include #include -#include +#include namespace mbgl { -using Value = mapbox::feature::value; -using NullValue = mapbox::feature::null_value_t; -using PropertyMap = mapbox::feature::property_map; +using Value = mapbox::base::Value; +using NullValue = mapbox::base::NullValue; +using PropertyMap = mapbox::base::ValueObject; using FeatureIdentifier = mapbox::feature::identifier; using Feature = mapbox::feature::feature; -using FeatureState = PropertyMap; +using FeatureState = mapbox::base::ValueObject; using FeatureStates = std::unordered_map; // using LayerFeatureStates = std::unordered_map; // diff --git a/next/CMakeLists.txt b/next/CMakeLists.txt index bc15f04420..dbf6c11918 100644 --- a/next/CMakeLists.txt +++ b/next/CMakeLists.txt @@ -912,6 +912,7 @@ target_link_libraries( Mapbox::Base::geometry.hpp Mapbox::Base::optional Mapbox::Base::typewrapper + Mapbox::Base::value Mapbox::Base::variant Mapbox::Base::weak mbgl-vendor-expected diff --git a/next/platform/android/android.cmake b/next/platform/android/android.cmake index 13818e39a7..1bde72d11d 100644 --- a/next/platform/android/android.cmake +++ b/next/platform/android/android.cmake @@ -268,6 +268,7 @@ target_link_libraries( GLESv2 Mapbox::Base::optional Mapbox::Base::typewrapper + Mapbox::Base::value Mapbox::Base::weak log ) diff --git a/scripts/generate-file-lists.js b/scripts/generate-file-lists.js index d1f5e77585..546ce38235 100755 --- a/scripts/generate-file-lists.js +++ b/scripts/generate-file-lists.js @@ -145,7 +145,8 @@ generateFileList('vendor/mapbox-base-files.json', 'vendor/mapbox-base/mapbox/geojson.hpp', 'vendor/mapbox-base/mapbox/jni.hpp', 'vendor/mapbox-base/mapbox/weak', - 'vendor/mapbox-base/mapbox/typewrapper' ], + 'vendor/mapbox-base/mapbox/typewrapper', + 'vendor/mapbox-base/mapbox/value'], vendorRegex, [ "include/*.hpp", "include/**/*.hpp", "include/**/*.h", "optional.hpp", ":!:include/jni/string_conversion.hpp" ]); generateFileList('vendor/polylabel-files.json', [ 'vendor/polylabel' ], vendorRegex, [ "include/**/*.hpp" ]); generateFileList('vendor/protozero-files.json', [ 'vendor/protozero' ], vendorRegex, [ "include/**/*.hpp" ]); diff --git a/src/mbgl/util/color.cpp b/src/mbgl/util/color.cpp index 4c2814cf14..8a880e8760 100644 --- a/src/mbgl/util/color.cpp +++ b/src/mbgl/util/color.cpp @@ -45,10 +45,10 @@ std::array Color::toArray() const { } mbgl::Value Color::toObject() const { - return std::unordered_map{{"r", double(r)}, - {"g", double(g)}, - {"b", double(b)}, - {"a", double(a)}}; + return mapbox::base::ValueObject{{"r", double(r)}, + {"g", double(g)}, + {"b", double(b)}, + {"a", double(a)}}; } } // namespace mbgl diff --git a/vendor/mapbox-base-files.json b/vendor/mapbox-base-files.json index 7c638d2b80..55091e438d 100644 --- a/vendor/mapbox-base-files.json +++ b/vendor/mapbox-base-files.json @@ -94,6 +94,7 @@ "mapbox/pixelmatch.hpp": "vendor/mapbox-base/mapbox/pixelmatch-cpp/include/mapbox/pixelmatch.hpp", "supercluster.hpp": "vendor/mapbox-base/mapbox/supercluster.hpp/include/supercluster.hpp", "mapbox/type_wrapper.hpp": "vendor/mapbox-base/mapbox/typewrapper/include/mapbox/type_wrapper.hpp", + "mapbox/value.hpp": "vendor/mapbox-base/mapbox/value/include/mapbox/value.hpp", "mapbox/optional.hpp": "vendor/mapbox-base/mapbox/variant/include/mapbox/optional.hpp", "mapbox/recursive_wrapper.hpp": "vendor/mapbox-base/mapbox/variant/include/mapbox/recursive_wrapper.hpp", "mapbox/variant.hpp": "vendor/mapbox-base/mapbox/variant/include/mapbox/variant.hpp", -- cgit v1.2.1