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

Method setName

libchigraph/src/GraphStruct.cpp:22–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20 : mModule{&mod}, mContext{&mod.context()}, mName{std::move(name)} {}
21
22std::vector<NodeInstance*> GraphStruct::setName(std::string newName, bool updateReferences) {
23 assert(!newName.empty() && "Cannot pass an empty name to GraphStruct::setName");
24
25 module().updateLastEditTime();
26
27 auto oldName = name();
28 mName = std::move(newName);
29
30 // find references to update
31 if (updateReferences) {
32 auto makeInstances =
33 context().findInstancesOfType(module().fullNamePath(), "_make_" + oldName);
34
35 for (auto makeInst : makeInstances) {
36 std::unique_ptr<NodeType> type;
37 auto res = module().nodeTypeFromName("_make_" + name(), {}, &type);
38
39 if (!res) { return {}; }
40
41 makeInst->setType(std::move(type));
42 }
43
44 auto breakInstances =
45 context().findInstancesOfType(module().fullNamePath(), "_break_" + oldName);
46
47 for (auto breakInst : breakInstances) {
48 std::unique_ptr<NodeType> type;
49 auto res = module().nodeTypeFromName("_break_" + name(), {}, &type);
50
51 if (!res) { return {}; }
52
53 breakInst->setType(std::move(type));
54 }
55
56 // append breakInstances to makeInstances so wer can return the updated nodes
57 makeInstances.reserve(breakInstances.size() + makeInstances.size());
58 std::copy(breakInstances.begin(), breakInstances.end(), std::back_inserter(makeInstances));
59
60 return makeInstances;
61 }
62
63 return {};
64}
65
66void GraphStruct::addType(DataType ty, std::string name, size_t addBefore, bool updateReferences) {
67 assert(addBefore <= types().size() && ty.valid());

Callers

nothing calls this directly

Calls 7

updateLastEditTimeMethod · 0.80
findInstancesOfTypeMethod · 0.80
fullNamePathMethod · 0.80
setTypeMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
nodeTypeFromNameMethod · 0.45

Tested by

no test coverage detected