| 54 | NodeInstance::~NodeInstance() = default; |
| 55 | |
| 56 | void 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()) { |
no test coverage detected