From 850d4e0fbdbc06077cd5ba914a7031f2d97249ae Mon Sep 17 00:00:00 2001 From: Joel Beckmeyer Date: Fri, 14 Apr 2017 19:10:32 -0400 Subject: [PATCH] fix a bunch of compile-time errors --- src/andGate.h | 2 +- src/event.cpp | 8 ++--- src/event.h | 2 +- src/gate.h | 6 ++-- src/norGate.h | 1 + src/notGate.h | 1 + src/orGate.h | 1 + src/radec.cpp | 90 +++++++++++++++++++++++++++++--------------------- src/xnorGate.h | 1 + src/xorGate.h | 1 + 10 files changed, 67 insertions(+), 46 deletions(-) diff --git a/src/andGate.h b/src/andGate.h index 9b1234f..795f28b 100644 --- a/src/andGate.h +++ b/src/andGate.h @@ -8,7 +8,7 @@ class andGate : public gate { public: andGate(priority_queue *eQueue, int d, wire* wire1, wire* wire2, wire* wire3); - int evaluate(int evTime); + void evaluate(int evTime); }; #endif // !AND diff --git a/src/event.cpp b/src/event.cpp index 805aab7..4c840b5 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -7,10 +7,10 @@ event::event(int num, int value, int setTime, wire * output){ out = output; } -bool event::operator<(const event &e1) { - if(evTime == e1.evTime) { - return evNum > e1.evNum; +bool operator<(const event &e1, const event &e2) { + if(e1.evTime == e2.evTime) { + return e1.evNum > e2.evNum; } - return evTime > e1.evTime; + return e1.evTime > e2.evTime; } diff --git a/src/event.h b/src/event.h index a8df798..48592d1 100644 --- a/src/event.h +++ b/src/event.h @@ -7,7 +7,7 @@ using namespace std; class event { public: event(int num, int value, int setTime, wire * output); - bool operator<(const event &e1); + friend bool operator<(const event &e1, const event &e2); private: int evNum, evValue, evTime; wire *out; diff --git a/src/gate.h b/src/gate.h index e48e16f..3a42d45 100644 --- a/src/gate.h +++ b/src/gate.h @@ -1,17 +1,19 @@ #ifndef GATE #define GATE + +#include "event.h" + class wire; class gate { public: gate(); - virtual void evaluate() = 0; + virtual void evaluate(int) = 0; protected: wire *in1, *in2, *out; priority_queue *e; int delay; - priority_queue *e; }; #endif // !GATE diff --git a/src/norGate.h b/src/norGate.h index a904cab..2a8fa5d 100644 --- a/src/norGate.h +++ b/src/norGate.h @@ -5,6 +5,7 @@ #include "wire.h" class norGate : public gate { + public: norGate(priority_queue *eQueue, int d, wire* wire1, wire* wire2, wire* wire3); void evaluate(int evTime); diff --git a/src/notGate.h b/src/notGate.h index 53dfc8d..0760c1e 100644 --- a/src/notGate.h +++ b/src/notGate.h @@ -5,6 +5,7 @@ #include "event.h" class notGate : public gate { + public: notGate(priority_queue *eQueue, int d, wire* wire1, wire* wire2); void evaluate(int evTime); }; diff --git a/src/orGate.h b/src/orGate.h index 89a881f..dfcbd8e 100644 --- a/src/orGate.h +++ b/src/orGate.h @@ -5,6 +5,7 @@ #include "wire.h" class orGate : public gate { + public: orGate(priority_queue *eQueue, int d, wire* wire1, wire* wire2, wire* wire3); void evaluate(int evTime); diff --git a/src/radec.cpp b/src/radec.cpp index 47930d1..ba86db2 100644 --- a/src/radec.cpp +++ b/src/radec.cpp @@ -1,30 +1,38 @@ +#include #include +#include #include "wire.h" -#include "pQueue.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" using namespace std; int getDelay(string d); -bool parseCircuit(vector &gates, vector &wires, fileName); +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(gates, wires, fileName); + bool parseSuccess = parseCircuit(e, gates, wires, fileName); if(parseSuccess) { // 2. Parse the vector file to initialize the simulation Queue with initial // Wire state (i.e., value) changes - priority_queue< e; - parseSuccess = e.parseVector(fileName); + parseSuccess = parseVector(e, fileName); // 3. Simulate the circuit using Event-driven control // first, remove the top Event e in the Queue @@ -33,11 +41,13 @@ int main() { // fourth, apply e's effects // 4. Print the results of the simulation + } } -bool parseCircuit(vector &gates, vector &wires, fileName) { +bool parseCircuit(priority_queue e, vector &gates, + vector &wires, string fileName) { ifstream in; - circuit.open(fileName + ".txt"); + in.open(fileName + ".txt"); if(in.fail()) { cerr << endl << fileName << ".txt could not be opened :("; exit(1); @@ -50,10 +60,10 @@ bool parseCircuit(vector &gates, vector &wires, fileName) { getline(in, tmpString); while(!in.eof()) { - tmpType << in; + in >> tmpType; - tmpString << in; - tmp1 << in; + in >> tmpString; + in >> tmp1; if(tmpType == "INPUT") { tmpWire = new wire(tmp1, true, tmpString); wires.push_back(tmpWire); @@ -61,45 +71,45 @@ bool parseCircuit(vector &gates, vector &wires, fileName) { tmpWire = new wire(tmp1, false, tmpString); wires.push_back(tmpWire); }else if(tmpType == "NOT") { - tmp2 << in; - tmpGate = new notGate(getDelay(tmpString), findWire(tmp1), - findWire(tmp2)); + in >> tmp2; + tmpGate = new notGate(&e, getDelay(tmpString), findWire(tmp1, wires), + findWire(tmp2, wires)); gates.push_back(tmpGate); }else if(tmpType == "AND") { - tmp2 << in; - tmp3 << in; - tmpGate = new andGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), - findWire(tmp3)); + 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") { - tmp2 << in; - tmp3 << in; - tmpGate = new nandGate(getDelay(tmpString), findWire(tmp1), - findWire(tmp2), findWire(tmp3)); + 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") { - tmp2 << in; - tmp3 << in; - tmpGate = new orGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), - findWire(tmp3)); + 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") { - tmp2 << in; - tmp3 << in; - tmpGate = new xorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), - findWire(tmp3)); + 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") { - tmp2 << in; - tmp3 << in; - tmpGate = new norGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), - findWire(tmp3)); + 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") { - tmp2 << in; - tmp3 << in; - tmpGate = new xnorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), - findWire(tmp3)); + in >> tmp2; + in >> tmp3; + tmpGate = new xnorGate(&e, getDelay(tmpString), findWire(tmp1, wires), + findWire(tmp2, wires), findWire(tmp3, wires)); gates.push_back(tmpGate); } } @@ -107,7 +117,7 @@ bool parseCircuit(vector &gates, vector &wires, fileName) { wire* findWire(int n, vector wires) { for(auto i = wires.begin(); i != wires.end(); ++i) { - if(n == *i) return i; + if(n == (**i).getNumber()) return *i; } return nullptr; } @@ -116,3 +126,7 @@ int getDelay(string d) { d.resize(d.size() - 2); return atoi(d.c_str()); } + +bool parseVector(priority_queue e, string fileName) { + //TODO +} diff --git a/src/xnorGate.h b/src/xnorGate.h index 47d67da..334714c 100644 --- a/src/xnorGate.h +++ b/src/xnorGate.h @@ -5,6 +5,7 @@ #include "wire.h" class xnorGate : public gate { + public: xnorGate(priority_queue *eQueue, int d, wire* wire1, wire* wire2, wire* wire3); void evaluate(int evTime); diff --git a/src/xorGate.h b/src/xorGate.h index 2ec40c9..a429fa2 100644 --- a/src/xorGate.h +++ b/src/xorGate.h @@ -5,6 +5,7 @@ #include "wire.h" class xorGate : public gate { + public: xorGate(priority_queue *eQueue, int d, wire* wire1, wire* wire2, wire* wire3); void evaluate(int evTime);