2 // Created by mfritzsc on 6/27/17.
5 #include "json_helper.hpp"
10 surface_id_to_layer::surface_id_to_layer(nlohmann::json const &j) {
12 if (j["type"] == "range") {
13 this->id_min = get<int>(j["first_surface_id"]);
14 this->id_max = get<int>(j["last_surface_id"]);
16 this->id_min = this->id_max = get<int>(j["surface_id"]);
18 this->name = j["name"].get<std::string>();
19 this->layer_id = get<int>(j["layer_id"]);
22 struct result<struct surface_id_to_layer_map> to_surface_id_to_layer_map(
23 nlohmann::json const &j) {
26 surface_id_to_layer_map stl{};
28 std::cbegin(j), std::cend(j),
29 std::inserter(stl.mapping, stl.mapping.end()),
30 [](nlohmann::json const &j) { return surface_id_to_layer(j); });
31 for (auto i : stl.mapping) {
33 return Err<struct surface_id_to_layer_map>(
34 "Found mapping w/o name");
36 if (i.layer_id == -1 || i.id_min == -1 || i.id_max == -1) {
37 return Err<struct surface_id_to_layer_map>(
38 "Found invalid/unset IDs in mapping");
42 } catch (std::exception &e) {
43 return Err<struct surface_id_to_layer_map>(e.what());