summaryrefslogtreecommitdiff
path: root/include/mbgl/style/conversion_impl.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/style/conversion_impl.hpp')
-rw-r--r--include/mbgl/style/conversion_impl.hpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/include/mbgl/style/conversion_impl.hpp b/include/mbgl/style/conversion_impl.hpp
index ebeeee1c79..7abe7bf923 100644
--- a/include/mbgl/style/conversion_impl.hpp
+++ b/include/mbgl/style/conversion_impl.hpp
@@ -8,6 +8,7 @@
#include <mbgl/util/feature.hpp>
#include <mbgl/util/geojson.hpp>
#include <mbgl/util/optional.hpp>
+#include <mbgl/util/traits.hpp>
#include <mapbox/value.hpp>
@@ -297,20 +298,6 @@ 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(); }
@@ -334,7 +321,7 @@ struct ValueFactory<Color> {
};
template <typename T>
-struct ValueFactory<T, typename std::enable_if<!std::is_enum<T>::value>::type> {
+struct ValueFactory<T, typename std::enable_if<(!std::is_enum<T>::value && !is_linear_container<T>::value)>::type> {
static Value make(const T& arg) { return {arg}; }
};
@@ -344,6 +331,18 @@ struct ValueFactory<T, typename std::enable_if<std::is_enum<T>::value>::type> {
};
template <typename T>
+struct ValueFactory<T, typename std::enable_if<is_linear_container<T>::value>::type> {
+ static Value make(const T& arg) {
+ mapbox::base::ValueArray result;
+ result.reserve(arg.size());
+ for (const auto& item : arg) {
+ result.emplace_back(ValueFactory<std::decay_t<decltype(item)>>::make(item));
+ }
+ return result;
+ }
+};
+
+template <typename T>
Value makeValue(T&& arg) {
return ValueFactory<std::decay_t<T>>::make(std::forward<T>(arg));
}