| 20 | : mModule{&mod}, mContext{&mod.context()}, mName{std::move(name)} {} |
| 21 | |
| 22 | std::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 | |
| 66 | void GraphStruct::addType(DataType ty, std::string name, size_t addBefore, bool updateReferences) { |
| 67 | assert(addBefore <= types().size() && ty.valid()); |
nothing calls this directly
no test coverage detected