blob: d1766f9755c76eed12f8a4ec1f43feb4d686b345 (
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
|
#pragma once
#include <mbgl/util/variant.hpp>
#include <jni/jni.hpp>
#include <string>
namespace mbgl {
namespace android {
namespace conversion {
struct Error { std::string message; };
template <class T>
class Result : private variant<T, Error> {
public:
using variant<T, Error>::variant;
explicit operator bool() const {
return this->template is<T>();
}
T& operator*() {
assert(this->template is<T>());
return this->template get<T>();
}
const T& operator*() const {
assert(this->template is<T>());
return this->template get<T>();
}
const Error& error() const {
assert(this->template is<Error>());
return this->template get<Error>();
}
};
template <class T, class V, class Enable = void>
struct Converter;
template <class T, typename V, class...Args>
Result<T> convert(jni::JNIEnv& env, const V& value, Args&&...args) {
return Converter<T, V>()(env, value, std::forward<Args>(args)...);
}
} // namespace conversion
} // namespace android
} // namespace mbgl
|