From 0abbc7440e5c1daf623bf91c0e9e34d7eeda739a Mon Sep 17 00:00:00 2001 From: Joel Beckmeyer Date: Mon, 10 Apr 2017 16:39:03 -0400 Subject: [PATCH] implement findWire() and clean up code --- readme.md | 1 - src/notGate.cpp | 3 +++ src/pQueue.cpp | 1 + src/radec.cpp | 15 ++++++++++----- src/wire.h | 1 + 5 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 src/pQueue.cpp diff --git a/readme.md b/readme.md index a969abd..fce41c4 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,6 @@ # RADEC # TODO -* implement findWire() function * implement vector file parsing * develop pQueue class * define all classes more completely diff --git a/src/notGate.cpp b/src/notGate.cpp index e69de29..b323b15 100644 --- a/src/notGate.cpp +++ b/src/notGate.cpp @@ -0,0 +1,3 @@ +#include "notGate.h" + +using namespace std; diff --git a/src/pQueue.cpp b/src/pQueue.cpp new file mode 100644 index 0000000..e8699b4 --- /dev/null +++ b/src/pQueue.cpp @@ -0,0 +1 @@ +#include "pQueue.h" diff --git a/src/radec.cpp b/src/radec.cpp index f40fbb7..465e11b 100644 --- a/src/radec.cpp +++ b/src/radec.cpp @@ -8,6 +8,7 @@ using namespace std; int getDelay(string d); +bool parseCircuit(vector &gates, vector &wires, fileName); wire* findWire(int n, vector wires); int main() { @@ -34,7 +35,7 @@ int main() { // 4. Print the results of the simulation } -bool parseCircuit(gates, wires, fileName) { +bool parseCircuit(vector &gates, vector &wires, fileName) { ifstream in; circuit.open(fileName + ".txt"); if(in.fail()) { @@ -61,7 +62,8 @@ bool parseCircuit(gates, wires, fileName) { wires.push_back(tmpWire); }else if(tmpType == "NOT") { tmp2 << in; - tmpGate = new notGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2)); + tmpGate = new notGate(getDelay(tmpString), findWire(tmp1), + findWire(tmp2)); gates.push_back(tmpGate); }else if(tmpType == "AND") { tmp2 << in; @@ -72,8 +74,8 @@ bool parseCircuit(gates, wires, fileName) { }else if(tmpType == "NAND") { tmp2 << in; tmp3 << in; - tmpGate = new nandGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), - findWire(tmp3)); + tmpGate = new nandGate(getDelay(tmpString), findWire(tmp1), + findWire(tmp2), findWire(tmp3)); gates.push_back(tmpGate); }else if(tmpType == "OR") { tmp2 << in; @@ -104,7 +106,10 @@ bool parseCircuit(gates, wires, fileName) { } wire* findWire(int n, vector wires) { - //TODO + for(auto i = wires.begin(); i != wires.end(); ++i) { + if(n == *i) return i; + } + return nullptr; } int getDelay(string d) { diff --git a/src/wire.h b/src/wire.h index 4449d03..0428904 100644 --- a/src/wire.h +++ b/src/wire.h @@ -14,6 +14,7 @@ class wire { int getState() const; void setState(bool newValue, int setTime); + int getNumber() const; void addGate(gate* newGate); private: