static void extract(picojson::value* super, picojson::value& v, std::vector<action>& action_storage) { if (v.is<picojson::object>()) { if(v.contains("action") && super != nullptr) { action a; a.link = &v; std::string type = v.get("action").get<std::string>(); if(type == "loop") { a.t = loop; a.begin = v.get("begin").get<double>(); a.step = v.get("step").get<double>(); a.end = v.get("end").get<double>(); action_storage.push_back(a); } else if(type == "each") { a.t = each; for(const auto& d : v.get("values").get<picojson::array>()) a.values.push_back(d); action_storage.push_back(a); } else if(type == "pipe") { a.t = pipe; a.data_id = v.get("data_id").get<std::string>(); a.sink = v.get("sink").get<std::string>(); if(v.contains("log_id")) { a.log_id = v.get("log_id").get<std::string>(); action_storage.push_back(a); } } } else { for(picojson::object::value_type& i : v.get<picojson::object>()) { action_extractor::extract(&v, i.second, action_storage); } } } else if(v.is<picojson::array>()) { for(picojson::value& i : v.get<picojson::array>()) { action_extractor::extract(&v, i, action_storage); } } }
bool JsonActionResolver::getObject(picojson::value v, std::string key, picojson::value &value) { if (!v.contains(key)) { std::cout << "Object does not contain any " << key << std::endl; return false; } picojson::value result = v.get(key); if (!result.is<picojson::object>()) { std::cout << key << " is not an object" << std::endl; return false; } value = result; return true; }
bool JsonActionResolver::getInt(picojson::value v, std::string key, int &value) { if (!v.contains(key)) { std::cout << "Object does not contain any " << key << std::endl; return false; } picojson::value result = v.get(key); if (!result.is<double>()) { std::cout << key << " is not an int" << std::endl; return false; } value = result.get<double>(); return true; }