implement findWire() and clean up code

This commit is contained in:
Joel Beckmeyer 2017-04-10 16:39:03 -04:00
parent 46fc86d36a
commit 0abbc7440e
5 changed files with 15 additions and 6 deletions

View File

@ -1,7 +1,6 @@
# RADEC
# TODO
* implement findWire() function
* implement vector file parsing
* develop pQueue class
* define all classes more completely

View File

@ -0,0 +1,3 @@
#include "notGate.h"
using namespace std;

1
src/pQueue.cpp Normal file
View File

@ -0,0 +1 @@
#include "pQueue.h"

View File

@ -8,6 +8,7 @@
using namespace std;
int getDelay(string d);
bool parseCircuit(vector<gate*> &gates, vector<wire*> &wires, fileName);
wire* findWire(int n, vector<wire*> wires);
int main() {
@ -34,7 +35,7 @@ int main() {
// 4. Print the results of the simulation
}
bool parseCircuit(gates, wires, fileName) {
bool parseCircuit(vector<gate*> &gates, vector<wire*> &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<wire*> wires) {
//TODO
for(auto i = wires.begin(); i != wires.end(); ++i) {
if(n == *i) return i;
}
return nullptr;
}
int getDelay(string d) {

View File

@ -14,6 +14,7 @@ class wire {
int getState() const;
void setState(bool newValue, int setTime);
int getNumber() const;
void addGate(gate* newGate);
private: