make wire instantiation great again

This commit is contained in:
Joel Beckmeyer 2017-04-24 19:36:08 -04:00
parent 217e1aab71
commit d692c5ff3a

View File

@ -22,13 +22,9 @@ bool Simulation::parseCircuit(string fileName)
in >> tmpString; in >> tmpString;
in >> tmp1; in >> tmp1;
if (tmpType == "INPUT") { if (tmpType == "INPUT" || tmpType == "OUTPUT") {
tmpWire = new Wire(tmp1, true, tmpString); tmpWire = findWire(tmp1);
wires.push_back(tmpWire); tmpWire->convertToIO(tmpString);
}
else if (tmpType == "OUTPUT") {
tmpWire = new Wire(tmp1, false, tmpString);
wires.push_back(tmpWire);
} }
else if (tmpType == "NOT") { else if (tmpType == "NOT") {
in >> tmp2; in >> tmp2;
@ -126,7 +122,11 @@ Wire * Simulation::findWire(int n)
for (auto i = wires.begin(); i != wires.end(); ++i) { for (auto i = wires.begin(); i != wires.end(); ++i) {
if (n == (**i).getNumber()) return *i; if (n == (**i).getNumber()) return *i;
} }
return nullptr;
// if wire does not exist, create it, instantiating as an intermediary wire
Wire * tmpWire = new Wire(n, false);
wires.push_back(tmpWire);
return tmpWire;
} }
int Simulation::getDelay(string d) int Simulation::getDelay(string d)