blob: 56092f9a637437861a1ed17c6b1c66559787834a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#ifndef MBGL_STYLE_FUNCTION_PROPERTIES
#define MBGL_STYLE_FUNCTION_PROPERTIES
#include <mbgl/util/variant.hpp>
#include <vector>
namespace mbgl {
template <typename T>
struct ConstantFunction {
inline ConstantFunction(const T &value) : value(value) {}
inline T evaluate(float) const { return value; }
private:
const T value;
};
template <typename T>
struct StopsFunction {
inline StopsFunction(const std::vector<std::pair<float, T>> &values, float base) : values(values), base(base) {}
T evaluate(float z) const;
private:
const std::vector<std::pair<float, T>> values;
const float base;
};
template <typename T>
using Function = mapbox::util::variant<
std::false_type,
ConstantFunction<T>,
StopsFunction<T>
>;
template <typename T>
struct FunctionEvaluator {
typedef T result_type;
inline FunctionEvaluator(float z) : z(z) {}
inline result_type operator()(const std::false_type &) {
return result_type();
}
template <template <typename> class Fn>
inline result_type operator()(const Fn<T>& fn) {
return fn.evaluate(z);
}
private:
float z;
};
}
#endif
|