diff --git a/src/nandGate.cpp b/src/nandGate.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/nandGate.h b/src/nandGate.h new file mode 100644 index 0000000..f2ab0fd --- /dev/null +++ b/src/nandGate.h @@ -0,0 +1,10 @@ +#ifndef AND +#define AND + +class andGate : public gate { + public: + andGate(wire* wire1 = nullptr, wire* wire2 = nullptr, wire* wire3 = nullptr); + int evaluate(); +}; + +#endif // !AND diff --git a/src/norGate.cpp b/src/norGate.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/norGate.h b/src/norGate.h new file mode 100644 index 0000000..178e872 --- /dev/null +++ b/src/norGate.h @@ -0,0 +1,9 @@ +#ifndef OR +#define OR + +class orGate : public gate { + orGate(wire* wire1 = nullptr, wire* wire2 = nullptr, wire* wire3 = nullptr); + int evaluate(); +}; + +#endif // !OR diff --git a/src/notGate.h b/src/notGate.h index 210ea80..af06f5a 100644 --- a/src/notGate.h +++ b/src/notGate.h @@ -2,7 +2,7 @@ #define NOT class not : public gate { - notGate(wire* wire1 = nullptr, wire* wire2 = nullptr); + notGate(int delay, wire* wire1 = nullptr, wire* wire2 = nullptr); int evaluate(); }; diff --git a/src/radec.cpp b/src/radec.cpp index 08fad7c..f40fbb7 100644 --- a/src/radec.cpp +++ b/src/radec.cpp @@ -1,9 +1,15 @@ +#include #include "wire.h" #include "pQueue.h" #include "orGate.h" #include "andGate.h" #include "notGate.h" +using namespace std; + +int getDelay(string d); +wire* findWire(int n, vector wires); + int main() { // 1. Parse circuit file to create in-memory data structure of Gates and Wires // to simulate @@ -28,6 +34,80 @@ int main() { // 4. Print the results of the simulation } -bool parseCircuit(gates, wires) { +bool parseCircuit(gates, wires, fileName) { + ifstream in; + circuit.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()) { + tmpType << in; + + tmpString << in; + tmp1 << in; + 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") { + tmp2 << in; + tmpGate = new notGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2)); + gates.push_back(tmpGate); + }else if(tmpType == "AND") { + tmp2 << in; + tmp3 << in; + tmpGate = new andGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), + findWire(tmp3)); + gates.push_back(tmpGate); + }else if(tmpType == "NAND") { + tmp2 << in; + tmp3 << in; + tmpGate = new nandGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), + findWire(tmp3)); + gates.push_back(tmpGate); + }else if(tmpType == "OR") { + tmp2 << in; + tmp3 << in; + tmpGate = new orGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), + findWire(tmp3)); + gates.push_back(tmpGate); + }else if(tmpType == "XOR") { + tmp2 << in; + tmp3 << in; + tmpGate = new xorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), + findWire(tmp3)); + gates.push_back(tmpGate); + }else if(tmpType == "NOR") { + tmp2 << in; + tmp3 << in; + tmpGate = new norGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), + findWire(tmp3)); + gates.push_back(tmpGate); + }else if(tmpType == "XNOR") { + tmp2 << in; + tmp3 << in; + tmpGate = new xnorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), + findWire(tmp3)); + gates.push_back(tmpGate); + } + } +} + +wire* findWire(int n, vector wires) { //TODO } + +int getDelay(string d) { + d.resize(d.size() - 2); + return atoi(d.c_str()); +} diff --git a/src/wire.h b/src/wire.h index 0bc88d4..4449d03 100644 --- a/src/wire.h +++ b/src/wire.h @@ -9,7 +9,7 @@ class gate; class wire { public: - wire(int number, string name = ""); + wire(int number, bool io, string name = ""); int getState() const; void setState(bool newValue, int setTime); diff --git a/src/xnorGate.cpp b/src/xnorGate.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/xnorGate.h b/src/xnorGate.h new file mode 100644 index 0000000..178e872 --- /dev/null +++ b/src/xnorGate.h @@ -0,0 +1,9 @@ +#ifndef OR +#define OR + +class orGate : public gate { + orGate(wire* wire1 = nullptr, wire* wire2 = nullptr, wire* wire3 = nullptr); + int evaluate(); +}; + +#endif // !OR diff --git a/src/xorGate.cpp b/src/xorGate.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/xorGate.h b/src/xorGate.h new file mode 100644 index 0000000..178e872 --- /dev/null +++ b/src/xorGate.h @@ -0,0 +1,9 @@ +#ifndef OR +#define OR + +class orGate : public gate { + orGate(wire* wire1 = nullptr, wire* wire2 = nullptr, wire* wire3 = nullptr); + int evaluate(); +}; + +#endif // !OR