| 446 | } |
| 447 | |
| 448 | Result jsonToGraphStruct(GraphModule& mod, boost::string_view name, const nlohmann::json& input, |
| 449 | GraphStruct** toFill) { |
| 450 | Result res; |
| 451 | |
| 452 | if (!input.is_array()) { |
| 453 | res.addEntry("EUKN", "Graph Struct json has to be an array", {{"Given JSON", input}}); |
| 454 | return res; |
| 455 | } |
| 456 | |
| 457 | auto createdStruct = mod.getOrCreateStruct(name.to_string()); |
| 458 | if (toFill != nullptr) { *toFill = createdStruct; } |
| 459 | |
| 460 | for (const auto& str : input) { |
| 461 | if (!str.is_object()) { |
| 462 | res.addEntry("EUKN", "Graph Struct entry must be an object", {{"Given JSON", str}}); |
| 463 | continue; |
| 464 | } |
| 465 | |
| 466 | if (str.size() != 1) { |
| 467 | res.addEntry("EUKN", "Graph Struct entry must have size of 1", {{"Size", str.size()}}); |
| 468 | continue; |
| 469 | } |
| 470 | |
| 471 | std::string docstring, qualifiedType; |
| 472 | std::tie(docstring, qualifiedType) = parseObjectPair(str); |
| 473 | |
| 474 | // parse the type |
| 475 | std::string typeModuleName, typeName; |
| 476 | std::tie(typeModuleName, typeName) = parseColonPair(qualifiedType); |
| 477 | |
| 478 | DataType ty; |
| 479 | res += mod.context().typeFromModule(typeModuleName, typeName, &ty); |
| 480 | |
| 481 | if (!res) { continue; } |
| 482 | |
| 483 | createdStruct->addType(ty, docstring, createdStruct->types().size()); |
| 484 | } |
| 485 | |
| 486 | return res; |
| 487 | } |
| 488 | |
| 489 | std::pair<std::string, std::string> parseObjectPair(const nlohmann::json& object) { |
| 490 | if (!object.is_object()) { return {}; } |
no test coverage detected