summaryrefslogtreecommitdiff
path: root/src/mbgl/style/property_parsing.hpp
blob: 182636df5c0d1d5eedab711b13ec966d32692674 (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
#ifndef MBGL_PROPERTY_PARSING
#define MBGL_PROPERTY_PARSING

#include <mbgl/style/class_properties.hpp>

#include <mapbox/optional.hpp>
#include <rapidjson/document.h>

namespace mbgl {

using JSVal = rapidjson::Value;

template <typename T>
using optional = mapbox::util::optional<T>;

namespace detail {

template <typename T>
optional<T> parseProperty(const char* name, const JSVal&);

}

template <typename T>
void parseProperty(const char* name, PropertyKey key, ClassProperties& properties, const JSVal& value) {
    if (!value.HasMember(name))
        return;

    const optional<T> res = detail::parseProperty<T>(name, value[name]);

    if (res) {
        properties.set(key, *res);
    }
}

}

#endif