X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fjson_helper.hpp;h=7d6e77ead5aa993cf584f52c4332a49620b6f149;hb=d16426164142cdddeaf16cb18a6ac5f191c8e0e4;hp=7d5d26febc4eab96195f6f3e25bad84e80adee5b;hpb=0c673801b78c98fe116b4d14bf37fb18f8b749dc;p=staging%2Fwindowmanager.git diff --git a/src/json_helper.hpp b/src/json_helper.hpp index 7d5d26f..7d6e77e 100644 --- a/src/json_helper.hpp +++ b/src/json_helper.hpp @@ -1,7 +1,9 @@ #ifndef TMCAGLWM_JSON_HELPER_HPP #define TMCAGLWM_JSON_HELPER_HPP +#include "result.hpp" #include "wayland.hpp" +#include struct json_object; @@ -9,4 +11,14 @@ json_object *to_json(genivi::screen const *s); json_object *to_json(genivi::controller::props_map const &s); json_object *to_json(std::vector const &v); +// We ned to manually unwrap numbers +template +wm::result get(nlohmann::json const &j) { + // DB(j); + T r; + std::istringstream s(j.get()); + s >> r; + return !s.eof() || s.fail() ? wm::Err("Could not read int") : wm::Ok(r); +} + #endif // TMCAGLWM_JSON_HELPER_HPP