summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-08-19 11:38:26 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-08-19 11:38:26 +0200
commitd147e18153910d4f21eaece75e06725b1249c8f2 (patch)
tree20cefbfca807774a40270127f7f2da685e97ed7e
parentdbf6d7bcb5502ab7529a0b9b7bfd59c2d2e10944 (diff)
downloadqtlocation-mapboxgl-d147e18153910d4f21eaece75e06725b1249c8f2.tar.gz
update mapbox/variant
-rw-r--r--include/mbgl/style/filter_expression.hpp2
-rw-r--r--include/mbgl/style/function_properties.hpp2
-rw-r--r--include/mbgl/style/property_value.hpp2
-rw-r--r--include/mbgl/style/style_bucket.hpp4
-rw-r--r--include/mbgl/style/style_properties.hpp2
-rw-r--r--include/mbgl/style/value.hpp2
-rw-r--r--include/mbgl/util/recursive_wrapper.hpp2
-rw-r--r--include/mbgl/util/variant.hpp25
-rw-r--r--src/style/style_layer.cpp6
9 files changed, 33 insertions, 14 deletions
diff --git a/include/mbgl/style/filter_expression.hpp b/include/mbgl/style/filter_expression.hpp
index 2a6a2927e7..2a96578792 100644
--- a/include/mbgl/style/filter_expression.hpp
+++ b/include/mbgl/style/filter_expression.hpp
@@ -10,7 +10,7 @@ namespace mbgl {
class FilterExpression {
public:
- typedef util::recursive_wrapper<FilterExpression> Wrapper;
+ typedef mapbox::util::recursive_wrapper<FilterExpression> Wrapper;
enum class Operator : uint8_t {
And,
diff --git a/include/mbgl/style/function_properties.hpp b/include/mbgl/style/function_properties.hpp
index 8cd7ce6e28..56092f9a63 100644
--- a/include/mbgl/style/function_properties.hpp
+++ b/include/mbgl/style/function_properties.hpp
@@ -27,7 +27,7 @@ private:
};
template <typename T>
-using Function = util::variant<
+using Function = mapbox::util::variant<
std::false_type,
ConstantFunction<T>,
StopsFunction<T>
diff --git a/include/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp
index 4d148dc029..1b22b31177 100644
--- a/include/mbgl/style/property_value.hpp
+++ b/include/mbgl/style/property_value.hpp
@@ -7,7 +7,7 @@
namespace mbgl {
-typedef util::variant<
+typedef mapbox::util::variant<
std::string,
TranslateAnchorType,
RotateAnchorType,
diff --git a/include/mbgl/style/style_bucket.hpp b/include/mbgl/style/style_bucket.hpp
index 58d4d705db..67c3142059 100644
--- a/include/mbgl/style/style_bucket.hpp
+++ b/include/mbgl/style/style_bucket.hpp
@@ -89,8 +89,8 @@ public:
float buffer = 0.03125f;
};
-typedef util::variant<StyleBucketFill, StyleBucketLine, StyleBucketSymbol,
- StyleBucketRaster, std::false_type> StyleBucketRender;
+typedef mapbox::util::variant<StyleBucketFill, StyleBucketLine, StyleBucketSymbol,
+ StyleBucketRaster, std::false_type> StyleBucketRender;
class StyleBucket {
diff --git a/include/mbgl/style/style_properties.hpp b/include/mbgl/style/style_properties.hpp
index 742ae63f0f..bbe8812bc7 100644
--- a/include/mbgl/style/style_properties.hpp
+++ b/include/mbgl/style/style_properties.hpp
@@ -95,7 +95,7 @@ struct BackgroundProperties {
Color color = {{ 0, 0, 0, 1 }};
};
-typedef util::variant<
+typedef mapbox::util::variant<
FillProperties,
LineProperties,
SymbolProperties,
diff --git a/include/mbgl/style/value.hpp b/include/mbgl/style/value.hpp
index 5e6260e5a6..b981f1db9c 100644
--- a/include/mbgl/style/value.hpp
+++ b/include/mbgl/style/value.hpp
@@ -9,7 +9,7 @@
namespace mbgl {
-typedef util::variant<bool, int64_t, uint64_t, double, std::string> Value;
+typedef mapbox::util::variant<bool, int64_t, uint64_t, double, std::string> Value;
std::string toString(const Value &value);
diff --git a/include/mbgl/util/recursive_wrapper.hpp b/include/mbgl/util/recursive_wrapper.hpp
index a616805c0f..54b27634a3 100644
--- a/include/mbgl/util/recursive_wrapper.hpp
+++ b/include/mbgl/util/recursive_wrapper.hpp
@@ -3,7 +3,7 @@
#include <utility>
-namespace mbgl { namespace util {
+namespace mapbox { namespace util {
template <typename T>
class recursive_wrapper
diff --git a/include/mbgl/util/variant.hpp b/include/mbgl/util/variant.hpp
index ddc82ee311..1eca5160c7 100644
--- a/include/mbgl/util/variant.hpp
+++ b/include/mbgl/util/variant.hpp
@@ -35,7 +35,7 @@
// translates to 100
#define VARIANT_VERSION (VARIANT_MAJOR_VERSION*100000) + (VARIANT_MINOR_VERSION*100) + (VARIANT_PATCH_VERSION)
-namespace mbgl { namespace util { namespace detail {
+namespace mapbox { namespace util { namespace detail {
static constexpr std::size_t invalid_value = std::size_t(-1);
@@ -487,6 +487,8 @@ private:
} // namespace detail
+struct no_init {};
+
template<typename... Types>
class variant
{
@@ -503,12 +505,16 @@ private:
public:
+
VARIANT_INLINE variant()
: type_index(sizeof...(Types) - 1)
{
new (&data) typename detail::select_type<0, Types...>::type();
}
+ VARIANT_INLINE variant(no_init)
+ : type_index(detail::invalid_value) {}
+
template <typename T, class = typename std::enable_if<
detail::is_valid_type<T, Types...>::value>::type>
VARIANT_INLINE explicit variant(T const& val) noexcept
@@ -715,11 +721,24 @@ auto VARIANT_INLINE static apply_visitor(F f, V & v0, V & v1) -> decltype(V::bin
return V::binary_visit(v0, v1, f);
}
+// getter interface
+template<typename ResultType, typename T>
+ResultType & get(T & var)
+{
+ return var.template get<ResultType>();
+}
+
+template<typename ResultType, typename T>
+ResultType const& get(T const& var)
+{
+ return var.template get<ResultType>();
+}
+
// operator<<
-template <typename charT, typename traits, typename Variant>
+template <typename charT, typename traits, typename... Types>
VARIANT_INLINE std::basic_ostream<charT, traits>&
-operator<< (std::basic_ostream<charT, traits>& out, Variant const& rhs)
+operator<< (std::basic_ostream<charT, traits>& out, variant<Types...> const& rhs)
{
detail::printer<std::basic_ostream<charT, traits>> visitor(out);
apply_visitor(visitor, rhs);
diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp
index d4e6d19db4..4994cf3efa 100644
--- a/src/style/style_layer.cpp
+++ b/src/style/style_layer.cpp
@@ -105,7 +105,7 @@ struct PropertyEvaluator {
}
T operator()(const Function<T> &value) const {
- return util::apply_visitor(FunctionEvaluator<T>(z), value);
+ return mapbox::util::apply_visitor(FunctionEvaluator<T>(z), value);
}
template <typename P, typename std::enable_if<!std::is_convertible<P, T>::value, int>::type = 0>
@@ -146,11 +146,11 @@ void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, c
for (AppliedClassProperty &property : applied.properties) {
if (now >= property.end) {
// We overwrite the current property with the new value.
- target = util::apply_visitor(evaluator, property.value);
+ target = mapbox::util::apply_visitor(evaluator, property.value);
} else if (now >= property.begin) {
// We overwrite the current property partially with the new value.
float progress = float(now - property.begin) / float(property.end - property.begin);
- target = interpolate(target, util::apply_visitor(evaluator, property.value), progress);
+ target = interpolate(target, mapbox::util::apply_visitor(evaluator, property.value), progress);
} else {
// Do not apply this property because its transition hasn't begun yet.
}