diff --git a/src/Simulation.cpp b/src/Simulation.cpp index a0e9c58..5b809d0 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -6,18 +6,19 @@ bool Simulation::parseCircuit(string fileName) in.open(fileName + ".txt"); if (in.fail()) { cerr << endl << fileName << ".txt could not be opened :("; - exit(1); + return false; } string tmpString, tmpType; int tmp1, tmp2, tmp3; Wire *tmpWire; Gate *tmpGate; + + // get rid of first line getline(in, tmpString); while (!in.eof()) { in >> tmpType; - in >> tmpString; in >> tmp1; @@ -78,6 +79,37 @@ bool Simulation::parseCircuit(string fileName) gates.push_back(tmpGate); } } + return true; +} + +bool parseVector(string fileName) { + ifstream in; + in.open(fileName + "_v.txt"); + if (in.fail()) { + cerr << endl << fileName << "_v.txt could not be opened :("; + return false; + } + + string tmpString; + int timeInt, valInt; + + // get rid of first line + getline(in, tmpString); + + while(!in.eof()) { + in >> tmpString; + in >> tmpString; + in >> timeInt; + in >> valInt; + + for(auto i = wires.begin(); i != wires.end(); ++i) { + if(i->getName() == tmpString) { + tmpWire = i; + } + } + + e.push(Event(eventNum++, valInt, timeInt, tmpWire)); + } } void Simulation::simulate() diff --git a/src/Simulation.h b/src/Simulation.h index 16bc64d..80491ca 100644 --- a/src/Simulation.h +++ b/src/Simulation.h @@ -1,16 +1,16 @@ #ifndef SIMULATION #define SIMULATION -#include "wire.h" -#include "event.h" -#include "gate.h" -#include "andGate.h" -#include "nandGate.h" -#include "orGate.h" -#include "norGate.h" -#include "xnorGate.h" -#include "xorGate.h" -#include "notGate.h" +#include "Wire.h" +#include "Event.h" +#include "Gate.h" +#include "AndGate.h" +#include "NandGate.h" +#include "OrGate.h" +#include "NorGate.h" +#include "XnorGate.h" +#include "XorGate.h" +#include "NotGate.h" #include #include #include @@ -21,6 +21,7 @@ using namespace std; class Simulation { public: bool parseCircuit(string fileName); + bool parseVector(string fileName); void simulate(); void print(); private: @@ -30,6 +31,7 @@ class Simulation { priority_queue e; vector gates; vector wires; + int eventNum; }; #endif // !SIMULATION