summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilhelm Berg <wb@BergWerk-GIS.at>2018-08-23 18:13:23 +0200
committerWilhelm Berg <wb@BergWerk-GIS.at>2018-08-23 18:13:23 +0200
commit3300fc1eeca8e778c6af01fe0f641e5978ad4c77 (patch)
tree9b81f847d7b883cf0e731942cd48736e140385b2
parent7a0a1a76a776c8cc4785d5f6ba2cacf56730bb4c (diff)
downloadqtlocation-mapboxgl-3300fc1eeca8e778c6af01fe0f641e5978ad4c77.tar.gz
down to 289 compile errors
-rw-r--r--include/mbgl/style/expression/value.hpp127
1 files changed, 106 insertions, 21 deletions
diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp
index b1126118a9..6170ac46ec 100644
--- a/include/mbgl/style/expression/value.hpp
+++ b/include/mbgl/style/expression/value.hpp
@@ -18,29 +18,102 @@ namespace expression {
struct Value;
-using ValueBase = variant<
- NullValue,
- bool,
- double,
- std::string,
- Color,
- Collator,
- mapbox::util::recursive_wrapper<std::vector<Value>>,
- mapbox::util::recursive_wrapper<std::unordered_map<std::string, Value>>>;
+using ValueBase = variant<NullValue,
+ bool,
+ double,
+ std::string,
+ Color,
+ Collator,
+ mapbox::util::recursive_wrapper<std::vector<Value>>,
+ mapbox::util::recursive_wrapper<std::unordered_map<std::string, Value>>>;
struct Value : ValueBase {
using ValueBase::ValueBase;
-
+
+ template <typename T>
+ bool is(T*) const {
+ return ValueBase::is<T>();
+ }
+
+ template <>
+ bool is(float*) const {
+ return ValueBase::is<double>();
+ }
+
+ template <typename T>
+ bool is() const {
+ return ValueBase::is<T>();
+ }
+ template <typename T>
+ T& get(T*) {
+ return ValueBase::get<T>();
+ }
+ template <typename T>
+ T const& get(T*) const {
+ return ValueBase::get<T>();
+ }
+ template <>
+ float const& get(float*) const {
+ return ValueBase::get<double>();
+ }
+
+ template <typename T>
+ T& get() {
+ return ValueBase::get<T>();
+ }
+ template <typename T>
+ T const& get() const {
+ return ValueBase::get<T>();
+ }
+
+ Value(NullValue&& args) : ValueBase(std::move(args)) {
+ }
+ Value(bool&& args) : ValueBase(std::forward<bool>(args)) {
+ }
+ Value(double&& args) : ValueBase(std::forward<double>(args)) {
+ }
+ Value(std::string&& args) : ValueBase(std::move(args)) {
+ }
+ Value(Color&& args) : ValueBase(std::forward<Color>(args)) {
+ }
+ Value(std::vector<Value>&& args)
+ : ValueBase(mapbox::util::recursive_wrapper<std::vector<Value>>(args)) {
+ }
+ typedef mapbox::util::recursive_wrapper<std::unordered_map<std::string, Value>> rec_map;
+ Value(std::unordered_map<std::string, Value>&& args) : ValueBase(rec_map(args)) {
+ }
+
+ Value(const NullValue& args) : ValueBase(args) {
+ }
+ Value(const bool& args) : ValueBase(args) {
+ }
+ Value(const double& args) : ValueBase(args) {
+ }
+ Value(const std::string& args) : ValueBase(args) {
+ }
+ Value(const Color& args) : ValueBase(args) {
+ }
+ Value(const std::vector<Value>& args)
+ : ValueBase(mapbox::util::recursive_wrapper<std::vector<Value>>(args)) {
+ }
+ Value(const std::unordered_map<std::string, Value>& args) : ValueBase(rec_map(args)) {
+ }
+
+ Value(const Value&) = default;
+
// Javascript's Number.MAX_SAFE_INTEGER
- static uint64_t maxSafeInteger() { return 9007199254740991ULL; }
-
- static bool isSafeInteger(uint64_t x) { return x <= maxSafeInteger(); };
+ static uint64_t maxSafeInteger() {
+ return 9007199254740991ULL;
+ }
+
+ static bool isSafeInteger(uint64_t x) {
+ return x <= maxSafeInteger();
+ };
static bool isSafeInteger(int64_t x) {
return static_cast<uint64_t>(x > 0 ? x : -x) <= maxSafeInteger();
}
static bool isSafeInteger(double x) {
return static_cast<uint64_t>(x > 0 ? x : -x) <= maxSafeInteger();
}
-
};
constexpr NullValue Null = NullValue();
@@ -73,9 +146,15 @@ struct ValueConverter {
template <>
struct ValueConverter<Value> {
- static type::Type expressionType() { return type::Value; }
- static Value toExpressionValue(const Value& value) { return value; }
- static optional<Value> fromExpressionValue(const Value& value) { return value; }
+ static type::Type expressionType() {
+ return type::Value;
+ }
+ static Value toExpressionValue(const Value& value) {
+ return value;
+ }
+ static optional<Value> fromExpressionValue(const Value& value) {
+ return value;
+ }
};
template <>
@@ -86,7 +165,9 @@ struct ValueConverter<mbgl::Value> {
template <>
struct ValueConverter<float> {
- static type::Type expressionType() { return type::Number; }
+ static type::Type expressionType() {
+ return type::Number;
+ }
static Value toExpressionValue(const float value);
static optional<float> fromExpressionValue(const Value& value);
};
@@ -111,14 +192,18 @@ struct ValueConverter<std::vector<T>> {
template <>
struct ValueConverter<Position> {
- static type::Type expressionType() { return type::Array(type::Number, 3); }
+ static type::Type expressionType() {
+ return type::Array(type::Number, 3);
+ }
static Value toExpressionValue(const mbgl::style::Position& value);
static optional<Position> fromExpressionValue(const Value& v);
};
template <typename T>
-struct ValueConverter<T, std::enable_if_t< std::is_enum<T>::value >> {
- static type::Type expressionType() { return type::String; }
+struct ValueConverter<T, std::enable_if_t<std::is_enum<T>::value>> {
+ static type::Type expressionType() {
+ return type::String;
+ }
static Value toExpressionValue(const T& value);
static optional<T> fromExpressionValue(const Value& value);
};