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

Method setType

libchigraph/src/NodeInstance.cpp:56–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54NodeInstance::~NodeInstance() = default;
55
56void NodeInstance::setType(std::unique_ptr<NodeType> newType) {
57 module().updateLastEditTime();
58
59 // delete exec connections that are out of range
60 // start at one past the end
61 for (size_t id = newType->execInputs().size(); id < inputExecConnections.size(); ++id) {
62 while (!inputExecConnections[id].empty()) {
63 assert(inputExecConnections[id][0].first); // should never fail...
64 auto res = disconnectExec(*inputExecConnections[id][0].first,
65 inputExecConnections[id][0].second);
66
67 assert(res.mSuccess);
68 }
69 }
70 inputExecConnections.resize(newType->execInputs().size());
71
72 for (size_t id = newType->execOutputs().size(); id < outputExecConnections.size(); ++id) {
73 auto& conn = outputExecConnections[id];
74 if (conn.first != nullptr) { disconnectExec(*this, id); }
75 }
76 outputExecConnections.resize(newType->execOutputs().size(), std::make_pair(nullptr, ~0ull));
77
78 auto id = 0ull;
79 for (const auto& conn : inputDataConnections) {
80 // if there is no connection, then skip
81 if (conn.first == nullptr) {
82 ++id;
83 continue;
84 }
85
86 // if we get here, then we have to deal with the connection.
87
88 // see if we can keep it
89 if (newType->dataInputs().size() > id &&
90 type().dataInputs()[id].type == newType->dataInputs()[id].type) {
91 ++id;
92 continue;
93 }
94
95 // disconnect if there's a connection and we can't keep it
96 auto res = disconnectData(*conn.first, conn.second, *this);
97
98 assert(res.mSuccess);
99
100 ++id;
101 }
102 inputDataConnections.resize(newType->dataInputs().size(), std::make_pair(nullptr, ~0ull));
103
104 id = 0ull;
105 for (const auto& connSlot : outputDataConnections) {
106 // keep the connections if they're still good
107 if (newType->dataOutputs().size() > id &&
108 type().dataOutputs()[id].type == newType->dataOutputs()[id].type) {
109 ++id;
110 continue;
111 }
112
113 while (!connSlot.empty()) {

Callers 7

updateEntriesMethod · 0.80
updateExitsMethod · 0.80
renameLocalVariableMethod · 0.80
retypeLocalVariableMethod · 0.80
setNameMethod · 0.80
setNameMethod · 0.80
updateNodeReferencesMethod · 0.80

Calls 3

disconnectExecFunction · 0.85
disconnectDataFunction · 0.85
updateLastEditTimeMethod · 0.80

Tested by

no test coverage detected