diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-12 12:30:48 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-12 12:30:48 +0200 |
commit | c9c4b6caa2a14b7b5a338a6981a616506da7e78f (patch) | |
tree | 1b6c30d6561a342578bf7b197d94cda755ba4aa2 /Circuit.cpp | |
parent | 2b941bc1b28e0a60da50baa0875d7cb05c0632c1 (diff) |
connect the nodes (no segfault edition)
Diffstat (limited to 'Circuit.cpp')
-rw-r--r-- | Circuit.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
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<string> 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; |