diff options
Diffstat (limited to 'Circuit.cpp')
-rw-r--r-- | Circuit.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/Circuit.cpp b/Circuit.cpp index cf6312e..7da9384 100644 --- a/Circuit.cpp +++ b/Circuit.cpp @@ -5,8 +5,7 @@ void Circuit::create(string label, vector<string> nodes) { if (nodes.size() == 1 && NodeFactory::has_type(nodes[0])) return new_node(label, nodes[0]); - for (string node : nodes) - new_net(label, node); + new_net(label, nodes); } void Circuit::new_node(string label, string type) { @@ -20,16 +19,32 @@ void Circuit::new_node(string label, string type) { printf("[%s] (%s)\n", label.c_str(), type.c_str()); } -void Circuit::new_net(string label, string connection) { - // TODO: instance Net - // TODO: connect Net to connection - printf("[%s] -> %s\n", label.c_str(), connection.c_str()); +void Circuit::new_net(string src, vector<string> dests) { + printf("%s\n", src.c_str()); + Net * net = new Net(); + nets.push_back(net); + + for (auto dest : dests) { + Node * node = find_node(dest); + if (node == nullptr) continue; // TODO: exception! + node->addInput(net); + } + + 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 const & n : nodes) - delete n.second; - for (auto const & n : nets) + for (auto & n : nodes) delete n.second; + for (auto & n : nets) + delete n; } |