blob: de0ac915020559b6d31637ab4cfe82ab857bb790 (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#pragma once
#include "value.hpp"
#include <mbgl/util/logging.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/util/optional.hpp>
#include <jni/jni.hpp>
namespace mbgl {
namespace style {
namespace conversion {
inline bool isUndefined(const mbgl::android::Value& value) {
return value.isNull();
}
inline bool isArray(const mbgl::android::Value& value) {
return value.isArray();
}
inline bool isObject(const mbgl::android::Value& value) {
return value.isObject();
}
inline std::size_t arrayLength(const mbgl::android::Value& value) {
return value.getLength();;
}
inline mbgl::android::Value arrayMember(const mbgl::android::Value& value, std::size_t i) {
return value.get(i);
}
inline optional<mbgl::android::Value> objectMember(const mbgl::android::Value& value, const char* key) {
mbgl::android::Value member = value.get(key);
if (!member.isNull()) {
return member;
} else {
return {};
}
}
template <class Fn>
optional<Error> eachMember(const mbgl::android::Value&, Fn&&) {
//TODO
mbgl::Log::Warning(mbgl::Event::Android, "eachMember not implemented");
return {};
}
inline optional<bool> toBool(const mbgl::android::Value& value) {
if (value.isBool()) {
return value.toBool();
} else {
return {};
}
}
inline optional<float> toNumber(const mbgl::android::Value& value) {
if (value.isNumber()) {
return value.toNumber();
} else {
return {};
}
}
inline optional<std::string> toString(const mbgl::android::Value& value) {
if (value.isString()) {
return value.toString();
} else {
return {};
}
}
inline optional<Value> toValue(const mbgl::android::Value& value) {
if (value.isNull()) {
return {};
} else if (value.isBool()) {
return { value.toBool() };
} else if (value.isString()) {
return { value.toString() };
} else if (value.isNumber()) {
//Need to cast to a double here as the float is otherwise considered a bool...
return { (double) value.toNumber() };
} else {
return {};
}
}
} // namespace conversion
} // namespace style
} // namespace mbgl
|