| 227 | } |
| 228 | |
| 229 | Result disconnectData(NodeInstance& lhs, size_t lhsConnID, NodeInstance& rhs) { |
| 230 | assert(&lhs.function() == &rhs.function()); |
| 231 | |
| 232 | lhs.module().updateLastEditTime(); |
| 233 | |
| 234 | Result res = {}; |
| 235 | |
| 236 | if (lhsConnID >= lhs.outputDataConnections.size()) { |
| 237 | auto dataOutputs = nlohmann::json::array(); |
| 238 | for (auto& output : lhs.type().dataOutputs()) { |
| 239 | dataOutputs.push_back({{output.name, output.type.qualifiedName()}}); |
| 240 | } |
| 241 | |
| 242 | res.addEntry("E22", "Output data connection in node doesn't exist", |
| 243 | {{"Requested ID", lhsConnID}, |
| 244 | {"Node Type", lhs.type().qualifiedName()}, |
| 245 | {"Node JSON", rhs.type().toJSON()}, |
| 246 | {"Node Output Data Connections", dataOutputs}}); |
| 247 | |
| 248 | return res; |
| 249 | } |
| 250 | |
| 251 | // find the connection |
| 252 | auto iter = std::find_if(lhs.outputDataConnections[lhsConnID].begin(), |
| 253 | lhs.outputDataConnections[lhsConnID].end(), |
| 254 | [&](auto& pair) { return pair.first == &rhs; }); |
| 255 | |
| 256 | if (iter == lhs.outputDataConnections[lhsConnID].end()) { |
| 257 | res.addEntry("EUKN", "Cannot disconnect from connection that doesn't exist", |
| 258 | {{"Left node ID", lhs.stringId()}, |
| 259 | {"Right node ID", rhs.stringId()}, |
| 260 | {"Left dock ID", lhsConnID}}); |
| 261 | |
| 262 | return res; |
| 263 | } |
| 264 | |
| 265 | if (rhs.inputDataConnections.size() <= iter->second) { |
| 266 | auto dataInputs = nlohmann::json::array(); |
| 267 | for (auto& output : rhs.type().dataInputs()) { |
| 268 | dataInputs.push_back({{output.name, output.type.qualifiedName()}}); |
| 269 | } |
| 270 | |
| 271 | res.addEntry("E23", "Input Data connection doesn't exist in node", |
| 272 | {{"Requested ID", iter->second}, |
| 273 | {"Node Type", rhs.type().qualifiedName()}, |
| 274 | {"Node JSON", rhs.type().toJSON()}, |
| 275 | {"Node Input Data Connections", dataInputs}}); |
| 276 | |
| 277 | return res; |
| 278 | } |
| 279 | |
| 280 | if (rhs.inputDataConnections[iter->second] != std::make_pair(&lhs, lhsConnID)) { |
| 281 | res.addEntry("EUKN", "Cannot disconnect from connection that doesn't exist", |
| 282 | {{"Left node ID", lhs.stringId()}, {"Right node ID", rhs.stringId()}}); |
| 283 | |
| 284 | return res; |
| 285 | } |
| 286 |
no test coverage detected