From 49cc7243ded5b5f74ca935bcfc8677d36d1d75b8 Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Tue, 30 Jul 2024 16:23:38 +0000 Subject: [PATCH] Add GraphView::setNodesName member function to set nodes' name in a spcific GraphView --- include/aidge/graph/GraphView.hpp | 6 ++++++ src/graph/GraphView.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/aidge/graph/GraphView.hpp b/include/aidge/graph/GraphView.hpp index 73dc7950d..17bd3b1e9 100644 --- a/include/aidge/graph/GraphView.hpp +++ b/include/aidge/graph/GraphView.hpp @@ -96,6 +96,12 @@ public: */ inline void setName(const std::string &name) { mName = name; } + /** + * @brief Set the name of every Node based on the current GraphView name in + * following form: "name_type#type-id" + */ + void setNodesName()const; + /** * @brief Save the GraphView as a Mermaid graph in a .md file at the * specified location. diff --git a/src/graph/GraphView.cpp b/src/graph/GraphView.cpp index 4ec333445..8a0c3b275 100644 --- a/src/graph/GraphView.cpp +++ b/src/graph/GraphView.cpp @@ -225,6 +225,18 @@ void Aidge::GraphView::save(const std::string& path, bool verbose, bool showProd fmt::print(fp.get(), "\n"); } +void Aidge::GraphView::setNodesName() const { + std::map<std::string, std::int32_t> typeIds; + for (const auto& nodePtr: getNodes()) { + const std::string& t = nodePtr->getOperator()->type(); + if (typeIds.find(t) == typeIds.cend()) { + typeIds.emplace(t, 0); + } + const std::string nodeName = name() + std::string("_") + t + std::string("#") + std::to_string(typeIds[t]++); + nodePtr->setName(nodeName); + } +} + void Aidge::GraphView::logOutputs(const std::string& dirName) const { if (!Aidge::createDirectories(dirName)){ AIDGE_THROW_OR_ABORT(std::runtime_error, "Failed to create directory: {}.", dirName); -- GitLab