2 // Created by m on 7/27/17.
6 #include "json_helper.hpp"
11 surface_id_to_layer::surface_id_to_layer(nlohmann::json const &j) {
13 if (j["type"] == "range") {
14 this->id_min = get<int>(j["first_surface_id"]);
15 this->id_max = get<int>(j["last_surface_id"]);
17 this->id_min = this->id_max = get<int>(j["surface_id"]);
19 this->name = j["name"].get<std::string>();
20 this->layer_id = get<int>(j["layer_id"]);
23 struct result<struct surface_id_to_layer_map> to_surface_id_to_layer_map(
24 nlohmann::json const &j) {
27 surface_id_to_layer_map stl{};
29 std::cbegin(j), std::cend(j),
30 std::inserter(stl.mapping, stl.mapping.end()),
31 [](nlohmann::json const &j) { return surface_id_to_layer(j); });
32 for (auto i : stl.mapping) {
34 return Err<struct surface_id_to_layer_map>(
35 "Found mapping w/o name");
37 if (i.layer_id == -1 || i.id_min == -1 || i.id_max == -1) {
38 return Err<struct surface_id_to_layer_map>(
39 "Found invalid/unset IDs in mapping");
43 } catch (std::exception &e) {
44 return Err<struct surface_id_to_layer_map>(e.what());