summaryrefslogtreecommitdiff
path: root/src/style/applied_class_properties.cpp
blob: ca9c09436c031ab2cbfb49843aa74fe604803733 (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
#include <mbgl/style/applied_class_properties.hpp>

namespace mbgl {

AppliedClassProperty::AppliedClassProperty(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value)
    : name(class_id),
    begin(begin),
    end(end),
    value(value) {}

// Returns thie ID of the most recent
ClassID AppliedClassProperties::mostRecent() const {
    return properties.size() ? properties.back().name : ClassID::Fallback;
}

void AppliedClassProperties::add(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value) {
    properties.emplace_back(class_id, begin, end, value);
}

bool AppliedClassProperties::hasTransitions() const {
    return properties.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 AppliedClassProperties::cleanup(timestamp now) {
    // Iterate backwards, but without using the rbegin/rend interface since we need forward
    // iterators to use .erase().
    for (auto it = properties.end(), begin = properties.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.
            properties.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) {
                properties.erase(it);
            }
            break;
        }
    }
}

bool AppliedClassProperties::empty() const {
    return properties.empty();
}

}