From 0e751426adf504ab5b951a29b00ce522ed702e3a Mon Sep 17 00:00:00 2001 From: daniel Date: Sun, 23 Apr 2017 20:53:17 -0400 Subject: [PATCH] fix joel's mistake --- src/radec.cpp | 127 +++++--------------------------------------------- 1 file changed, 11 insertions(+), 116 deletions(-) diff --git a/src/radec.cpp b/src/radec.cpp index ba86db2..cbbaa0f 100644 --- a/src/radec.cpp +++ b/src/radec.cpp @@ -1,132 +1,27 @@ -#include -#include -#include -#include "wire.h" -#include "orGate.h" -#include "xorGate.h" -#include "norGate.h" -#include "xnorGate.h" -#include "andGate.h" -#include "nandGate.h" -#include "notGate.h" -#include "event.h" +#include "Simulation.h" using namespace std; -int getDelay(string d); -bool parseCircuit(priority_queue e, vector &gates, - vector &wires, string fileName); -wire* findWire(int n, vector wires); -bool parseVector(priority_queue e, string fileName); - int main() { // 1. Parse circuit file to create in-memory data structure of Gates and Wires // to simulate - vector gates; - vector wires; - priority_queue e; string fileName; - getline(cin, fileName); - bool parseSuccess = parseCircuit(e, gates, wires, fileName); + Simulation e; - if(parseSuccess) { - // 2. Parse the vector file to initialize the simulation Queue with initial - // Wire state (i.e., value) changes - parseSuccess = parseVector(e, fileName); + getline(cin, fileName); + e.parseCircuit(fileName); + + // 2. Parse the vector file to initialize the simulation Queue with initial + // Wire state (i.e., value) changes + e.parseVector(fileName); // 3. Simulate the circuit using Event-driven control // first, remove the top Event e in the Queue // second, determine if e causes a future Wire state change // third, create and queue any future Wire state changes as new Events // fourth, apply e's effects + e.simulate(); // 4. Print the results of the simulation - } -} - -bool parseCircuit(priority_queue e, vector &gates, - vector &wires, string fileName) { - ifstream in; - in.open(fileName + ".txt"); - if(in.fail()) { - cerr << endl << fileName << ".txt could not be opened :("; - exit(1); - } - - string tmpString, tmpType; - int tmp1, tmp2, tmp3; - wire *tmpWire; - gate *tmpGate; - getline(in, tmpString); - - while(!in.eof()) { - in >> tmpType; - - in >> tmpString; - in >> tmp1; - if(tmpType == "INPUT") { - tmpWire = new wire(tmp1, true, tmpString); - wires.push_back(tmpWire); - }else if(tmpType == "OUTPUT") { - tmpWire = new wire(tmp1, false, tmpString); - wires.push_back(tmpWire); - }else if(tmpType == "NOT") { - in >> tmp2; - tmpGate = new notGate(&e, getDelay(tmpString), findWire(tmp1, wires), - findWire(tmp2, wires)); - gates.push_back(tmpGate); - }else if(tmpType == "AND") { - in >> tmp2; - in >> tmp3; - tmpGate = new andGate(&e, getDelay(tmpString), findWire(tmp1, wires), - findWire(tmp2, wires), findWire(tmp3, wires)); - gates.push_back(tmpGate); - }else if(tmpType == "NAND") { - in >> tmp2; - in >> tmp3; - tmpGate = new nandGate(&e, getDelay(tmpString), findWire(tmp1, wires), - findWire(tmp2, wires), findWire(tmp3, wires)); - gates.push_back(tmpGate); - }else if(tmpType == "OR") { - in >> tmp2; - in >> tmp3; - tmpGate = new orGate(&e, getDelay(tmpString), findWire(tmp1, wires), - findWire(tmp2, wires), findWire(tmp3, wires)); - gates.push_back(tmpGate); - }else if(tmpType == "XOR") { - in >> tmp2; - in >> tmp3; - tmpGate = new xorGate(&e, getDelay(tmpString), findWire(tmp1, wires), - findWire(tmp2, wires), findWire(tmp3, wires)); - gates.push_back(tmpGate); - }else if(tmpType == "NOR") { - in >> tmp2; - in >> tmp3; - tmpGate = new norGate(&e, getDelay(tmpString), findWire(tmp1, wires), - findWire(tmp2, wires), findWire(tmp3, wires)); - gates.push_back(tmpGate); - }else if(tmpType == "XNOR") { - in >> tmp2; - in >> tmp3; - tmpGate = new xnorGate(&e, getDelay(tmpString), findWire(tmp1, wires), - findWire(tmp2, wires), findWire(tmp3, wires)); - gates.push_back(tmpGate); - } - } -} - -wire* findWire(int n, vector wires) { - for(auto i = wires.begin(); i != wires.end(); ++i) { - if(n == (**i).getNumber()) return *i; - } - return nullptr; -} - -int getDelay(string d) { - d.resize(d.size() - 2); - return atoi(d.c_str()); -} - -bool parseVector(priority_queue e, string fileName) { - //TODO -} + e.print(); +} \ No newline at end of file