summaryrefslogtreecommitdiff
path: root/include/mbgl
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl')
-rw-r--r--include/mbgl/style/conversion.hpp5
-rw-r--r--include/mbgl/style/conversion_impl.hpp29
-rw-r--r--include/mbgl/style/expression/formatted.hpp16
-rw-r--r--include/mbgl/util/traits.hpp10
4 files changed, 39 insertions, 21 deletions
diff --git a/include/mbgl/style/conversion.hpp b/include/mbgl/style/conversion.hpp
index 2c83d1561b..29af9fac91 100644
--- a/include/mbgl/style/conversion.hpp
+++ b/include/mbgl/style/conversion.hpp
@@ -17,9 +17,12 @@ class ConversionTraits;
class Convertible;
-template <class T, class Enable = void>
+template <typename T, typename Enable = void>
struct Converter;
+template <typename T, typename Enable = void>
+struct ValueFactory;
+
} // namespace conversion
} // namespace style
} // namespace mbgl
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));
}
diff --git a/include/mbgl/style/expression/formatted.hpp b/include/mbgl/style/expression/formatted.hpp
index f4f08e9197..bb3d609c91 100644
--- a/include/mbgl/style/expression/formatted.hpp
+++ b/include/mbgl/style/expression/formatted.hpp
@@ -48,7 +48,8 @@ public:
bool operator==(const Formatted& ) const;
std::string toString() const;
-
+ mbgl::Value toObject() const;
+
bool empty() const {
return sections.empty() || sections.at(0).text.empty();
}
@@ -59,13 +60,18 @@ public:
} // namespace expression
namespace conversion {
-
+
template <>
-struct Converter<mbgl::style::expression::Formatted> {
+struct Converter<expression::Formatted> {
public:
- optional<mbgl::style::expression::Formatted> operator()(const Convertible& value, Error& error) const;
+ optional<expression::Formatted> operator()(const Convertible& value, Error& error) const;
};
-
+
+template <>
+struct ValueFactory<expression::Formatted> {
+ static Value make(const expression::Formatted& formatted) { return formatted.toObject(); }
+};
+
} // namespace conversion
} // namespace style
diff --git a/include/mbgl/util/traits.hpp b/include/mbgl/util/traits.hpp
index 5b9401aad7..e37144e60e 100644
--- a/include/mbgl/util/traits.hpp
+++ b/include/mbgl/util/traits.hpp
@@ -1,7 +1,9 @@
#pragma once
+#include <array>
#include <cstdint>
#include <type_traits>
+#include <vector>
namespace mbgl {
@@ -25,4 +27,12 @@ typename std::enable_if<is_utf16char_like<InChar>::value && is_utf16char_like_po
return reinterpret_cast<OutPointer>(in);
}
+template <typename T>
+struct is_linear_container : std::false_type {};
+
+template <typename T, std::size_t N>
+struct is_linear_container<std::array<T, N>> : std::true_type {};
+template <typename... Ts>
+struct is_linear_container<std::vector<Ts...>> : std::true_type {};
+
} // namespace mbgl