summaryrefslogtreecommitdiff
path: root/src/mbgl/map/map_data.cpp
blob: 993edb38e8086ed48912cc2761123534994bb137 (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
#include "map_data.hpp"

#include <algorithm>

namespace mbgl {

// Adds the class if it's not yet set. Returns true when it added the class, and false when it
// was already present.
bool MapData::addClass(const std::string& klass) {
    Lock lock(mtx);
    if (std::find(classes.begin(), classes.end(), klass) != classes.end()) return false;
    classes.push_back(klass);
    return true;
}

// Removes the class if it's present. Returns true when it remvoed the class, and false when it
// was not present.
bool MapData::removeClass(const std::string& klass) {
    Lock lock(mtx);
    const auto it = std::find(classes.begin(), classes.end(), klass);
    if (it != classes.end()) {
        classes.erase(it);
        return true;
    }
    return false;
}

// Returns true when class is present in the list of currently set classes.
bool MapData::hasClass(const std::string& klass) const {
    Lock lock(mtx);
    return std::find(classes.begin(), classes.end(), klass) != classes.end();
}

void MapData::setClasses(const std::vector<std::string>& klasses) {
    Lock lock(mtx);
    classes = klasses;
}

std::vector<std::string> MapData::getClasses() const {
    Lock lock(mtx);
    return classes;
}

}