| 437 | } |
| 438 | |
| 439 | Result Context::addModuleFromJson(const fs::path& fullName, const nlohmann::json& json, |
| 440 | GraphModule** toFill) { |
| 441 | Result res; |
| 442 | |
| 443 | auto scopedCtx = res.addScopedContext({{"Requested Module Name", fullName.string()}}); |
| 444 | |
| 445 | // make sure it's not already added |
| 446 | { |
| 447 | auto mod = moduleByFullName(fullName); |
| 448 | if (mod != nullptr) { |
| 449 | if (toFill != nullptr) { |
| 450 | auto casted = dynamic_cast<GraphModule*>(mod); |
| 451 | if (casted != nullptr) { *toFill = casted; } |
| 452 | } |
| 453 | return {}; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | // Create the module |
| 458 | GraphModule* jMod = nullptr; |
| 459 | res += jsonToGraphModule(*this, json, fullName, &jMod); |
| 460 | if (toFill != nullptr) { *toFill = jMod; } |
| 461 | |
| 462 | // if we failed, remove the module |
| 463 | if (!res) { unloadModule(jMod->fullName()); } |
| 464 | |
| 465 | return res; |
| 466 | } |
| 467 | |
| 468 | bool Context::addModule(std::unique_ptr<ChiModule> modToAdd) noexcept { |
| 469 | assert(modToAdd != nullptr); |
no test coverage detected