MCPcopy Create free account
hub / github.com/chigraph/chigraph / jsonToGraphModule

Function jsonToGraphModule

libchigraph/src/JsonDeserializer.cpp:12–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10namespace chi {
11
12Result jsonToGraphModule(Context& createInside, const nlohmann::json& input,
13 const boost::filesystem::path& fullName, GraphModule** toFill) {
14 Result res;
15
16 auto resCtx = res.addScopedContext({{"Loading Module Name", fullName.string()},
17 {"Workspace Path", createInside.workspacePath().string()}});
18
19 // create the module
20 auto createdModule = createInside.newGraphModule(fullName);
21 if (toFill != nullptr) { *toFill = createdModule; }
22
23 // load if it has C enabled
24 {
25 auto iter = input.find("has_c_support");
26 if (iter == input.end()) {
27 res.addEntry("EUKN", "No has_c_support section in module JSON, assuming none", {});
28 return res;
29 }
30 if (!iter->is_boolean()) {
31 res.addEntry("EUKN", "has_c_support section in module JSON isn't a bool",
32 {{"Actual Data", *iter}});
33 return res;
34 }
35
36 createdModule->setCEnabled(*iter);
37 }
38
39 // load dependencies
40 {
41 auto iter = input.find("dependencies");
42 if (iter == input.end()) {
43 res.addEntry("E38", "No dependencies element in module", {});
44 return res;
45 }
46 if (!iter->is_array()) {
47 res.addEntry("E39", "dependencies element isn't an array", {});
48 return res;
49 }
50
51 for (const auto& dep : *iter) {
52 if (!dep.is_string()) {
53 res.addEntry("E40", "dependency isn't a string", {{"Actual Data", dep}});
54 continue;
55 }
56
57 std::string depName = dep;
58 res += createdModule->addDependency(depName);
59
60 if (!res) { return res; }
61 }
62 }
63
64 // load types
65 {
66 auto iter = input.find("types");
67 if (iter == input.end() || !iter->is_object()) {
68 res.addEntry("EUKN", "No types object in module", {{}});
69 return res;

Callers 2

mainFunction · 0.85
addModuleFromJsonMethod · 0.85

Calls 15

jsonToGraphStructFunction · 0.85
jsonToGraphFunctionFunction · 0.85
addScopedContextMethod · 0.80
workspacePathMethod · 0.80
newGraphModuleMethod · 0.80
endMethod · 0.80
addEntryMethod · 0.80
is_booleanMethod · 0.80
setCEnabledMethod · 0.80
is_arrayMethod · 0.80
is_stringMethod · 0.80

Tested by

no test coverage detected