[core] type aliases and conversion traits for mapbox::base::Value
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/style/color_ramp_property_value.hpp>
|
||||
#include <mbgl/style/conversion.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
#include <mbgl/style/property_value.hpp>
|
||||
#include <mbgl/util/feature.hpp>
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
|
||||
#include <mapbox/value.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
@@ -288,6 +294,52 @@ optional<T> convert(const Convertible& value, Error& error, Args&&...args) {
|
||||
return Converter<T>()(value, error, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct ValueFactory;
|
||||
|
||||
template <typename T>
|
||||
struct ValueArrayFactory {
|
||||
static Value make(const T& arg) { return mapbox::base::ValueArray(arg.begin(), arg.end()); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ValueFactory<std::array<float, 2>> : public ValueArrayFactory<std::array<float, 2>> {};
|
||||
|
||||
template <>
|
||||
struct ValueFactory<std::vector<float>> : public ValueArrayFactory<std::vector<float>> {};
|
||||
|
||||
template <>
|
||||
struct ValueFactory<ColorRampPropertyValue> {
|
||||
static Value make(const ColorRampPropertyValue& value) { return value.getExpression().serialize(); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ValueFactory<Color> {
|
||||
static Value make(const Color& color) { return color.toObject(); }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct ValueFactory<T, typename std::enable_if<!std::is_enum<T>::value>::type> {
|
||||
static Value make(const T& arg) { return {arg}; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct ValueFactory<T, typename std::enable_if<std::is_enum<T>::value>::type> {
|
||||
static Value make(T arg) { return {int64_t(arg)}; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Value makeValue(T&& arg) {
|
||||
return ValueFactory<std::decay_t<T>>::make(std::forward<T>(arg));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Value makeValue(const PropertyValue<T>& value) {
|
||||
return value.match([](const Undefined&) -> Value { return {}; },
|
||||
[](const T& t) -> Value { return makeValue(t); },
|
||||
[](const PropertyExpression<T>& fn) { return fn.getExpression().serialize(); });
|
||||
}
|
||||
|
||||
} // namespace conversion
|
||||
} // namespace style
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
#include <mbgl/util/optional.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
|
||||
#include <mapbox/feature.hpp>
|
||||
#include <mapbox/value.hpp>
|
||||
|
||||
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<double>;
|
||||
using FeatureState = PropertyMap;
|
||||
using FeatureState = mapbox::base::ValueObject;
|
||||
using FeatureStates = std::unordered_map<std::string, FeatureState>; // <featureID, FeatureState>
|
||||
using LayerFeatureStates = std::unordered_map<std::string, FeatureStates>; // <sourceLayer, FeatureStates>
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -268,6 +268,7 @@ target_link_libraries(
|
||||
GLESv2
|
||||
Mapbox::Base::optional
|
||||
Mapbox::Base::typewrapper
|
||||
Mapbox::Base::value
|
||||
Mapbox::Base::weak
|
||||
log
|
||||
)
|
||||
|
||||
@@ -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" ]);
|
||||
|
||||
@@ -45,10 +45,10 @@ std::array<double, 4> Color::toArray() const {
|
||||
}
|
||||
|
||||
mbgl::Value Color::toObject() const {
|
||||
return std::unordered_map<std::string, mbgl::Value>{{"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
|
||||
|
||||
1
vendor/mapbox-base-files.json
vendored
1
vendor/mapbox-base-files.json
vendored
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user