json_helper: clang-format
[staging/windowmanager.git] / src / json_helper.hpp
1 #ifndef TMCAGLWM_JSON_HELPER_HPP
2 #define TMCAGLWM_JSON_HELPER_HPP
3
4 #include "result.hpp"
5 #include "wayland.hpp"
6 #include <json.hpp>
7
8 struct json_object;
9
10 json_object *to_json(genivi::screen const *s);
11 json_object *to_json(genivi::controller::props_map const &s);
12 json_object *to_json(std::vector<uint32_t> const &v);
13
14 // We ned to manually unwrap numbers
15 template <typename T>
16 wm::result<T> get(nlohmann::json const &j) {
17    // DB(j);
18    T r;
19    std::istringstream s(j.get<std::string>());
20    s >> r;
21    return !s.eof() || s.fail() ? wm::Err<T>("Could not read int") : wm::Ok(r);
22 }
23
24 #endif  // TMCAGLWM_JSON_HELPER_HPP