Merge pull request #433 from mapbox/update-variant
Update variant implementation
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using Function = util::variant<
|
||||
using Function = mapbox::util::variant<
|
||||
std::false_type,
|
||||
ConstantFunction<T>,
|
||||
StopsFunction<T>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
typedef util::variant<
|
||||
typedef mapbox::util::variant<
|
||||
std::string,
|
||||
TranslateAnchorType,
|
||||
RotateAnchorType,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -95,7 +95,7 @@ struct BackgroundProperties {
|
||||
Color color = {{ 0, 0, 0, 1 }};
|
||||
};
|
||||
|
||||
typedef util::variant<
|
||||
typedef mapbox::util::variant<
|
||||
FillProperties,
|
||||
LineProperties,
|
||||
SymbolProperties,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace mbgl { namespace util {
|
||||
namespace mapbox { namespace util {
|
||||
|
||||
template <typename T>
|
||||
class recursive_wrapper
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user