aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Json.cpp5
-rw-r--r--lib/Json.h7
-rw-r--r--lib/RemoteControl.cpp3
3 files changed, 10 insertions, 5 deletions
diff --git a/lib/Json.cpp b/lib/Json.cpp
index da5b078..121c2de 100644
--- a/lib/Json.cpp
+++ b/lib/Json.cpp
@@ -86,8 +86,9 @@ namespace json {
else if (std::holds_alternative<std::nullopt_t>(value)) {
ss << "null";
}
- else if (std::holds_alternative<json::map_t>(value)) {
- ss << map_to_json(std::get<json::map_t>(value));
+ else if (std::holds_alternative<std::shared_ptr<json::map_t> >(value)) {
+ const map_t& v = *std::get<std::shared_ptr<json::map_t> >(value);
+ ss << map_to_json(v);
}
else {
throw std::logic_error("variant alternative not handled");
diff --git a/lib/Json.h b/lib/Json.h
index ee67f35..706394f 100644
--- a/lib/Json.h
+++ b/lib/Json.h
@@ -41,11 +41,12 @@
namespace json {
- using map_t = std::unordered_map<std::string, struct value_t>;
+ // STL containers are not required to support incomplete types,
+ // hence the shared_ptr
struct value_t {
std::variant<
- map_t,
+ std::shared_ptr<std::unordered_map<std::string, value_t>>,
std::string,
double,
size_t,
@@ -54,5 +55,7 @@ namespace json {
std::nullopt_t> v;
};
+ using map_t = std::unordered_map<std::string, value_t>;
+
std::string map_to_json(const map_t& values);
}
diff --git a/lib/RemoteControl.cpp b/lib/RemoteControl.cpp
index fbe0662..dca3373 100644
--- a/lib/RemoteControl.cpp
+++ b/lib/RemoteControl.cpp
@@ -109,7 +109,8 @@ std::list< std::vector<std::string> > RemoteControllers::get_param_list_values(c
std::string RemoteControllers::get_showjson() {
json::map_t root;
for (auto &controllable : rcs.controllables) {
- root[controllable->get_rc_name()].v = controllable->get_all_values();
+ root[controllable->get_rc_name()].v =
+ std::make_shared<json::map_t>(controllable->get_all_values());
}
return json::map_to_json(root);