#include "Circuit.h" #include "NodeFactory.h" void Circuit::create(string label, vector nodes) { if (nodes.size() == 1 && NodeFactory::has_type(nodes[0])) return new_node(label, nodes[0]); new_net(label, nodes); } void Circuit::new_node(string label, string type) { if (nodes.find(label) != nodes.end()) return; // TODO: exception! Node * node = NodeFactory::create(type); if (node == nullptr) return; // TODO: exception? nodes[label] = node; printf("[%s] (%s)\n", label.c_str(), type.c_str()); } void Circuit::new_net(string src, vector dests) { printf("%s\n", src.c_str()); Net * net = new Net(); nets.push_back(net); for (auto dest : dests) { Node * node = nodes.find(dest)->second; if (node == nullptr) continue; // TODO: exception! node->addInput(net); } Node * node = nodes.find(src)->second; if (node == nullptr) return; // TODO: exception! node->setOutput(net); } Circuit::~Circuit() { for (auto & n : nodes) delete n.second; for (auto & n : nets) delete n; }