add parseVector function
This commit is contained in:
parent
d08c7cb919
commit
f64ee84269
@ -6,18 +6,19 @@ bool Simulation::parseCircuit(string fileName)
|
|||||||
in.open(fileName + ".txt");
|
in.open(fileName + ".txt");
|
||||||
if (in.fail()) {
|
if (in.fail()) {
|
||||||
cerr << endl << fileName << ".txt could not be opened :(";
|
cerr << endl << fileName << ".txt could not be opened :(";
|
||||||
exit(1);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string tmpString, tmpType;
|
string tmpString, tmpType;
|
||||||
int tmp1, tmp2, tmp3;
|
int tmp1, tmp2, tmp3;
|
||||||
Wire *tmpWire;
|
Wire *tmpWire;
|
||||||
Gate *tmpGate;
|
Gate *tmpGate;
|
||||||
|
|
||||||
|
// get rid of first line
|
||||||
getline(in, tmpString);
|
getline(in, tmpString);
|
||||||
|
|
||||||
while (!in.eof()) {
|
while (!in.eof()) {
|
||||||
in >> tmpType;
|
in >> tmpType;
|
||||||
|
|
||||||
in >> tmpString;
|
in >> tmpString;
|
||||||
in >> tmp1;
|
in >> tmp1;
|
||||||
|
|
||||||
@ -78,6 +79,37 @@ bool Simulation::parseCircuit(string fileName)
|
|||||||
gates.push_back(tmpGate);
|
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()
|
void Simulation::simulate()
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
#ifndef SIMULATION
|
#ifndef SIMULATION
|
||||||
#define SIMULATION
|
#define SIMULATION
|
||||||
|
|
||||||
#include "wire.h"
|
#include "Wire.h"
|
||||||
#include "event.h"
|
#include "Event.h"
|
||||||
#include "gate.h"
|
#include "Gate.h"
|
||||||
#include "andGate.h"
|
#include "AndGate.h"
|
||||||
#include "nandGate.h"
|
#include "NandGate.h"
|
||||||
#include "orGate.h"
|
#include "OrGate.h"
|
||||||
#include "norGate.h"
|
#include "NorGate.h"
|
||||||
#include "xnorGate.h"
|
#include "XnorGate.h"
|
||||||
#include "xorGate.h"
|
#include "XorGate.h"
|
||||||
#include "notGate.h"
|
#include "NotGate.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -21,6 +21,7 @@ using namespace std;
|
|||||||
class Simulation {
|
class Simulation {
|
||||||
public:
|
public:
|
||||||
bool parseCircuit(string fileName);
|
bool parseCircuit(string fileName);
|
||||||
|
bool parseVector(string fileName);
|
||||||
void simulate();
|
void simulate();
|
||||||
void print();
|
void print();
|
||||||
private:
|
private:
|
||||||
@ -30,6 +31,7 @@ class Simulation {
|
|||||||
priority_queue<Event> e;
|
priority_queue<Event> e;
|
||||||
vector<Gate*> gates;
|
vector<Gate*> gates;
|
||||||
vector<Wire*> wires;
|
vector<Wire*> wires;
|
||||||
|
int eventNum;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !SIMULATION
|
#endif // !SIMULATION
|
||||||
|
Loading…
Reference in New Issue
Block a user