diff options
author | Marcus Fritzsch <marcus_fritzsch@mentor.com> | 2017-07-06 11:32:50 +0200 |
---|---|---|
committer | Marcus Fritzsch <marcus_fritzsch@mentor.com> | 2017-08-08 17:24:00 +0200 |
commit | 9dfa6b9427115e7402ce25e40e4d78b20d559c93 (patch) | |
tree | a790ce4ce7b15930c1550c5b08bc51930dd75dbc /src/json_helper.cpp | |
parent | ba5360ac03286364abd9fde6b500e2c0fabe56b1 (diff) |
Move all nlohmann::json to json_helper.cpp
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
Diffstat (limited to 'src/json_helper.cpp')
-rw-r--r-- | src/json_helper.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/json_helper.cpp b/src/json_helper.cpp new file mode 100644 index 0000000..823c030 --- /dev/null +++ b/src/json_helper.cpp @@ -0,0 +1,72 @@ +#include "json_helper.hpp" + +#include <json.h> + +#include <json.hpp> + +using json = nlohmann::json; + +template <typename T> +json_object *to_json_(T const *s) { + auto j = json::object({ + {"id", s->id}, + {"size", {{"width", s->size.w}, {"height", s->size.h}}}, + {"dst", + {{"width", s->dst_rect.w}, + {"height", s->dst_rect.h}, + {"x", s->dst_rect.x}, + {"y", s->dst_rect.y}}}, + {"src", + {{"width", s->src_rect.w}, + {"height", s->src_rect.h}, + {"x", s->src_rect.x}, + {"y", s->src_rect.y}}}, + {"visibility", s->visibility}, + {"opacity", s->opacity}, + {"orientation", s->orientation}, + }); + return json_tokener_parse(j.dump().c_str()); +} + +json_object *to_json(genivi::surface const *s) { return to_json_(s); } + +json_object *to_json(genivi::layer const *l) { return to_json_(l); } + +json_object *to_json(genivi::screen const *s) { + auto o = json_object_new_object(); + json_object_object_add(o, "id", json_object_new_int(s->id)); + return o; +} + +template <typename T> +json_object *to_json_(T const &s) { + auto a = json_object_new_array(); + + if (!s.empty()) { + for (auto const &i : s) { + json_object_array_add(a, to_json(i.second.get())); + } + } + + return a; +} + +json_object *to_json(genivi::controller::surface_map_type const &s) { + return to_json_(s); +} + +json_object *to_json(genivi::controller::layer_map_type const &l) { + return to_json_(l); +} + +json_object *to_json(genivi::controller::screen_map_type const &s) { + return to_json_(s); +} + +json_object *to_json(std::vector<uint32_t> const &v) { + auto a = json_object_new_array(); + for (const auto i : v) { + json_object_array_add(a, json_object_new_int(i)); + } + return a; +} |