blob: 718c3eb0e081f45a5fa1ecfe9af26c51cc9b3be4 (
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
95
96
97
98
99
100
101
102
103
|
#ifndef MBGL_MAP_MAP_DATA
#define MBGL_MAP_MAP_DATA
#include <mbgl/util/chrono.hpp>
#include <string>
#include <mutex>
#include <atomic>
#include <vector>
namespace mbgl {
struct StyleInfo {
std::string url;
std::string base;
std::string json;
};
class MapData {
using Lock = std::lock_guard<std::mutex>;
public:
inline MapData() {
setAnimationTime(TimePoint::min());
setDefaultTransitionDuration(Duration::zero());
}
inline StyleInfo getStyleInfo() const {
Lock lock(mtx);
return styleInfo;
}
inline void setStyleInfo(StyleInfo&& info) {
Lock lock(mtx);
styleInfo = info;
}
inline std::string getAccessToken() const {
Lock lock(mtx);
return accessToken;
}
inline void setAccessToken(const std::string &token) {
Lock lock(mtx);
accessToken = token;
}
// Adds the class if it's not yet set. Returns true when it added the class, and false when it
// was already present.
bool addClass(const std::string& klass);
// Removes the class if it's present. Returns true when it remvoed the class, and false when it
// was not present.
bool removeClass(const std::string& klass);
// Returns true when class is present in the list of currently set classes.
bool hasClass(const std::string& klass) const;
// Changes the list of currently set classes to the new list.
void setClasses(const std::vector<std::string>& klasses);
// Returns a list of all currently set classes.
std::vector<std::string> getClasses() const;
inline bool getDebug() const {
return debug;
}
inline bool toggleDebug() {
return debug ^= 1u;
}
inline void setDebug(bool value) {
debug = value;
}
inline TimePoint getAnimationTime() const {
// We're casting the TimePoint to and from a Duration because libstdc++
// has a bug that doesn't allow TimePoints to be atomic.
return TimePoint(animationTime);
}
inline void setAnimationTime(TimePoint timePoint) {
animationTime = timePoint.time_since_epoch();
};
inline Duration getDefaultTransitionDuration() const {
return defaultTransitionDuration;
}
inline void setDefaultTransitionDuration(Duration duration) {
defaultTransitionDuration = duration;
};
private:
mutable std::mutex mtx;
StyleInfo styleInfo;
std::string accessToken;
std::vector<std::string> classes;
std::atomic<uint8_t> debug { false };
std::atomic<Duration> animationTime;
std::atomic<Duration> defaultTransitionDuration;
};
}
#endif
|