diff --git a/include/aidge/graph/GraphView.hpp b/include/aidge/graph/GraphView.hpp index c0aaea9025389ace11705635491cb7ffb50aa5c9..4973de0a3925ff4e9f04dfa9eab5d90c7b178db4 100644 --- a/include/aidge/graph/GraphView.hpp +++ b/include/aidge/graph/GraphView.hpp @@ -96,7 +96,7 @@ public: bool inView(const NodePtr& nodePtr) const; - inline NodePtr getRootNode() const noexcept { + inline NodePtr rootNode() const noexcept { return mRootNode; } diff --git a/src/graph/GraphView.cpp b/src/graph/GraphView.cpp index 5abd1d71a077eb3b7ad3fdfb3e4b23715d3a2288..95d0f0b08fb93db06a20d8e0bb09c9a8e153de58 100644 --- a/src/graph/GraphView.cpp +++ b/src/graph/GraphView.cpp @@ -9,11 +9,17 @@ * ********************************************************************************/ -#include <algorithm> +#include <algorithm> // std::find, std::set_difference, std::set_intersection #include <cassert> -#include <iterator> -#include <utility> -#include <numeric> +#include <cstddef> // std::size_t +#include <cstdio> // std::fopen, std::fprintf, std::fclose +#include <iterator> // std::inserter, std::distance, std::next +#include <map> +#include <memory> // std::shared_ptr, std::static_pointer_cast, std::make_shared +#include <set> +#include <string> // std::to_string +#include <utility> // std::pair, std::make_pair +#include <vector> #include "aidge/utils/Types.h" #include "aidge/graph/GraphView.hpp" @@ -71,16 +77,12 @@ void Aidge::GraphView::save(std::string path, bool verbose, bool showProducers) // Start by creating every node for (const std::shared_ptr<Node> &node_ptr : mNodes) { const std::string currentType = node_ptr->type(); - if (typeCounter.find(currentType) == typeCounter.end()) - typeCounter[currentType] = 0; ++typeCounter[currentType]; - std::string givenName = - (node_ptr->name().empty()) - ? "<em>" + currentType + "#" + std::to_string(typeCounter[currentType]) + "</em>" - : "\"" + node_ptr->name() + "\\n<sub><em>( " + currentType + "#" + std::to_string(typeCounter[currentType]) + " )</em></sub>\""; - namePtrTable[node_ptr] = - (currentType + "_" + std::to_string(typeCounter[currentType])); + const std::string givenName = (node_ptr->name().empty()) ? + "<em>" + currentType + "#" + std::to_string(typeCounter[currentType]) + "</em>" : + "\"" + node_ptr->name() + "\\n<sub><em>( " + currentType + "#" + std::to_string(typeCounter[currentType]) + " )</em></sub>\""; + namePtrTable[node_ptr] = (currentType + "_" + std::to_string(typeCounter[currentType])); if (node_ptr == mRootNode) { std::fprintf(fp, "%s(%s):::rootCls\n", namePtrTable[node_ptr].c_str(), @@ -100,13 +102,13 @@ void Aidge::GraphView::save(std::string path, bool verbose, bool showProducers) continue; } IOIndex_t outputIdx = 0; - for (auto childs : node_ptr->getOrderedChildren()) { - for (auto child : childs) { + for (const auto& childs : node_ptr->getOrderedChildren()) { + for (const auto& child : childs) { if (child != nullptr) { IOIndex_t inputIdx = 0; for (auto parent : child->inputs()) { if (parent.first == node_ptr && parent.second == outputIdx) { - if (mNodes.find(child) != mNodes.end()) { + if (mNodes.find(child) != mNodes.cend()) { std::fprintf(fp, "%s-->|%u→%u|%s\n", namePtrTable[node_ptr].c_str(), outputIdx, inputIdx, namePtrTable[child].c_str()); } @@ -540,7 +542,7 @@ bool Aidge::GraphView::add(std::pair<NodePtr, std::set<NodePtr>> nodes, bool inc bool Aidge::GraphView::add(std::shared_ptr<GraphView> graph) { // set the rootNode to the other graphView rootNode if no rootNode yet - mRootNode = mRootNode ? mRootNode : graph->getRootNode(); + mRootNode = mRootNode ? mRootNode : graph->rootNode(); return add(graph->getNodes(), false); } @@ -741,10 +743,10 @@ bool Aidge::GraphView::replace(const std::set<Aidge::NodePtr>& oldNodes, const s auto newG = std::make_shared<GraphView>("newG"); newG->add(newNodes, false); - const auto oldOI = oldG->getOrderedInputs(); - const auto oldOO = oldG->getOrderedOutputs(); - const auto newOI = newG->getOrderedInputs(); - const auto newOO = newG->getOrderedOutputs(); + const auto& oldOI = oldG->getOrderedInputs(); + const auto& oldOO = oldG->getOrderedOutputs(); + const auto& newOI = newG->getOrderedInputs(); + const auto& newOO = newG->getOrderedOutputs(); std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>> inputParents = std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>>(oldOI.size()); std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>> outputChildren = std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>>(oldOO.size());