make parseCircuit() push gates onto input wire gates vector

This commit is contained in:
Joel Beckmeyer 2017-04-24 22:18:06 -04:00
parent 681b4c91ad
commit fe794c6725
1 changed files with 22 additions and 0 deletions

View File

@ -32,49 +32,71 @@ bool Simulation::parseCircuit(string fileName)
in >> tmp2; in >> tmp2;
tmpGate = new NotGate(getDelay(tmpString), findWire(tmp1), tmpGate = new NotGate(getDelay(tmpString), findWire(tmp1),
findWire(tmp2)); findWire(tmp2));
// push gate onto Simulation gates vector
gates.push_back(tmpGate); gates.push_back(tmpGate);
// also push gate onto input wire's gate vector
findWire(tmp1)->addGate(tmpGate);
} }
else if (tmpType == "AND") { else if (tmpType == "AND") {
in >> tmp2; in >> tmp2;
in >> tmp3; in >> tmp3;
tmpGate = new AndGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), tmpGate = new AndGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
findWire(tmp3)); findWire(tmp3));
gates.push_back(tmpGate); gates.push_back(tmpGate);
findWire(tmp1)->addGate(tmpGate);
findWire(tmp2)->addGate(tmpGate);
} }
else if (tmpType == "NAND") { else if (tmpType == "NAND") {
in >> tmp2; in >> tmp2;
in >> tmp3; in >> tmp3;
tmpGate = new NandGate(getDelay(tmpString), findWire(tmp1), tmpGate = new NandGate(getDelay(tmpString), findWire(tmp1),
findWire(tmp2), findWire(tmp3)); findWire(tmp2), findWire(tmp3));
gates.push_back(tmpGate); gates.push_back(tmpGate);
findWire(tmp1)->addGate(tmpGate);
findWire(tmp2)->addGate(tmpGate);
} }
else if (tmpType == "OR") { else if (tmpType == "OR") {
in >> tmp2; in >> tmp2;
in >> tmp3; in >> tmp3;
tmpGate = new OrGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), tmpGate = new OrGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
findWire(tmp3)); findWire(tmp3));
gates.push_back(tmpGate); gates.push_back(tmpGate);
findWire(tmp1)->addGate(tmpGate);
findWire(tmp2)->addGate(tmpGate);
} }
else if (tmpType == "XOR") { else if (tmpType == "XOR") {
in >> tmp2; in >> tmp2;
in >> tmp3; in >> tmp3;
tmpGate = new XorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), tmpGate = new XorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
findWire(tmp3)); findWire(tmp3));
gates.push_back(tmpGate); gates.push_back(tmpGate);
findWire(tmp1)->addGate(tmpGate);
findWire(tmp2)->addGate(tmpGate);
} }
else if (tmpType == "NOR") { else if (tmpType == "NOR") {
in >> tmp2; in >> tmp2;
in >> tmp3; in >> tmp3;
tmpGate = new NorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), tmpGate = new NorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
findWire(tmp3)); findWire(tmp3));
gates.push_back(tmpGate); gates.push_back(tmpGate);
findWire(tmp1)->addGate(tmpGate);
findWire(tmp2)->addGate(tmpGate);
} }
else if (tmpType == "XNOR") { else if (tmpType == "XNOR") {
in >> tmp2; in >> tmp2;
in >> tmp3; in >> tmp3;
tmpGate = new XnorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), tmpGate = new XnorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
findWire(tmp3)); findWire(tmp3));
gates.push_back(tmpGate); gates.push_back(tmpGate);
findWire(tmp1)->addGate(tmpGate);
findWire(tmp2)->addGate(tmpGate);
} }
} }
return true; return true;