From 3d53ab30f83ffa9799257df2e9332506f1f89c57 Mon Sep 17 00:00:00 2001 From: cmoineau <cyril.moineau@cea.fr> Date: Thu, 25 Apr 2024 09:59:48 +0000 Subject: [PATCH] [Fix] Node name is now updated in GraphViews. --- include/aidge/graph/GraphView.hpp | 8 +++++++- include/aidge/graph/Node.hpp | 8 ++++---- src/graph/Node.cpp | 5 ++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/aidge/graph/GraphView.hpp b/include/aidge/graph/GraphView.hpp index 59c538ce6..6a0460941 100644 --- a/include/aidge/graph/GraphView.hpp +++ b/include/aidge/graph/GraphView.hpp @@ -160,7 +160,7 @@ public: /** * @brief List outside input connections of the GraphView. The vector - * size is garanteed to match the number of outside inputs of the GraphView. If there is + * size is guaranteed to match the number of outside inputs of the GraphView. If there is * no external connection to a given input, a pair of nullptr and gk_IODefaultIndex is returned. * @return std::vector<std::pair<NodePtr, IOIndex_t>> */ @@ -376,6 +376,12 @@ public: addChild(toOtherNode, mNodeRegistry.at(fromOutNodeName), fromTensor, toTensor); } + inline void updateNodeName(const std::string& oldName, const std::string& newName){ + AIDGE_ASSERT(mNodeRegistry.find(oldName) != mNodeRegistry.end(), "No node named {} in graph {}, the graph may be corrupted !", oldName, name()); + mNodeRegistry[newName] = mNodeRegistry[oldName]; + mNodeRegistry.erase(oldName); + } + /** * @brief Include a GraphView content in the current GraphView and link * the two sets by linking one Node from each GraphView. diff --git a/include/aidge/graph/Node.hpp b/include/aidge/graph/Node.hpp index 908f56295..2a0a4a3b7 100644 --- a/include/aidge/graph/Node.hpp +++ b/include/aidge/graph/Node.hpp @@ -235,8 +235,8 @@ public: /////////////////////////////////////////////////////// /** - * @brief Vector of pointers to each GraphView containing the object - * @return std::vector<GraphView> + * @brief Set of pointers to each GraphView containing this Node + * @return std::set<GraphView> */ inline std::set<std::shared_ptr<GraphView>> views() const noexcept { std::set<std::shared_ptr<GraphView>> res; @@ -460,10 +460,10 @@ private: // OPERATOR FUNCTIONNAL but commented out to avoid iostream inclusion // /** // * @brief operator<< overload to ease print & debug of nodes - // * @param[inout] ostream to print to + // * @param[inout] ostream to print to // * @param[in] n node to print // */ - // friend std::ostream& operator << (std::ostream& os, Node& n); + // friend std::ostream& operator << (std::ostream& os, Node& n); }; } // namespace Aidge diff --git a/src/graph/Node.cpp b/src/graph/Node.cpp index 149691f79..b08bb4c20 100644 --- a/src/graph/Node.cpp +++ b/src/graph/Node.cpp @@ -57,7 +57,10 @@ Aidge::Connector Aidge::Node::operator()(const std::vector<Connector>& ctors) { // INNER /////////////////////////////////////////////////////// -void Aidge::Node::setName(const std::string& name) { mName = name; } +void Aidge::Node::setName(const std::string& name) { + for (auto graphView : views()) graphView->updateNodeName(mName, name); + mName = name; +} /////////////////////////////////////////////////////// // OPERATORS -- GitLab