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
|
#include <mbgl/style/applied_class_properties.hpp>
namespace mbgl {
AppliedClassPropertyValue::AppliedClassPropertyValue(ClassID class_id, const TimePoint& begin_, const TimePoint& end_, const PropertyValue &value_)
: name(class_id),
begin(begin_),
end(end_),
value(value_) {}
// Returns the ID of the most recent
ClassID AppliedClassPropertyValues::mostRecent() const {
return propertyValues.empty() ? ClassID::Fallback : propertyValues.back().name;
}
void AppliedClassPropertyValues::add(ClassID class_id, const TimePoint& begin, const TimePoint& end, const PropertyValue &value) {
propertyValues.emplace_back(class_id, begin, end, value);
}
bool AppliedClassPropertyValues::hasTransitions() const {
return propertyValues.size() > 1;
}
// Erase all items in the property list that are before a completed transition.
// Then, if the only remaining property is a Fallback value, remove it too.
void AppliedClassPropertyValues::cleanup(const TimePoint& now) {
// Iterate backwards, but without using the rbegin/rend interface since we need forward
// iterators to use .erase().
for (auto it = propertyValues.end(), begin = propertyValues.begin(); it != begin;) {
// If the property is finished, break iteration and delete all remaining items.
if ((--it)->end <= now) {
// Removes all items that precede the current iterator, but *not* the element currently
// pointed to by the iterator. This preserves the last completed transition as the
// first element in the property list.
propertyValues.erase(begin, it);
// Also erase the pivot element if it's a fallback value. This means we can remove the
// entire applied properties object as well, because we already have the fallback
// value set as the default.
if (it->name == ClassID::Fallback) {
propertyValues.erase(it);
}
break;
}
}
}
bool AppliedClassPropertyValues::empty() const {
return propertyValues.empty();
}
}
|