From c9c4b6caa2a14b7b5a338a6981a616506da7e78f Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 12 Jun 2024 12:30:48 +0200 Subject: connect the nodes (no segfault edition) --- Circuit.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Circuit.cpp') diff --git a/Circuit.cpp b/Circuit.cpp index 393060f..7da9384 100644 --- a/Circuit.cpp +++ b/Circuit.cpp @@ -25,16 +25,22 @@ void Circuit::new_net(string src, vector dests) { nets.push_back(net); for (auto dest : dests) { - Node * node = nodes.find(dest)->second; + Node * node = find_node(dest); if (node == nullptr) continue; // TODO: exception! node->addInput(net); } - Node * node = nodes.find(src)->second; + Node * node = find_node(src); if (node == nullptr) return; // TODO: exception! node->setOutput(net); } +Node * Circuit::find_node(string label) { + auto map_index = this->nodes.find(label); + if (map_index == nodes.end()) return nullptr; + return map_index->second; +} + Circuit::~Circuit() { for (auto & n : nodes) delete n.second; -- cgit v1.2.3