Fix the gate evaluate definition to return event
This commit is contained in:
@@ -9,7 +9,7 @@ using namespace std;
|
||||
class NandGate : public Gate {
|
||||
public:
|
||||
NandGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||
void evaluate(int time);
|
||||
Event evaluate(int time);
|
||||
int getDelay();
|
||||
};
|
||||
|
||||
|
@@ -6,9 +6,9 @@
|
||||
|
||||
class NorGate : public Gate {
|
||||
public:
|
||||
NorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||
void evaluate(int evTime);
|
||||
int getDelay();
|
||||
NorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||
Event evaluate(int evTime);
|
||||
int getDelay();
|
||||
};
|
||||
|
||||
#endif // !NOR
|
||||
|
@@ -6,9 +6,9 @@
|
||||
|
||||
class NotGate : public Gate {
|
||||
public:
|
||||
NotGate(int d, Wire* wire1, Wire* wire2);
|
||||
void evaluate(int evTime);
|
||||
int getDelay();
|
||||
NotGate(int d, Wire* wire1, Wire* wire2);
|
||||
Event evaluate(int evTime);
|
||||
int getDelay();
|
||||
};
|
||||
|
||||
#endif // !NOT
|
||||
|
@@ -6,9 +6,9 @@
|
||||
|
||||
class OrGate : public Gate {
|
||||
public:
|
||||
OrGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||
void evaluate(int evTime);
|
||||
int getDelay();
|
||||
OrGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||
Event evaluate(int evTime);
|
||||
int getDelay();
|
||||
};
|
||||
|
||||
#endif // !OR
|
||||
|
@@ -11,8 +11,8 @@ bool Simulation::parseCircuit(string fileName)
|
||||
|
||||
string tmpString, tmpType;
|
||||
int tmp1, tmp2, tmp3;
|
||||
wire *tmpWire;
|
||||
gate *tmpGate;
|
||||
Wire *tmpWire;
|
||||
Gate *tmpGate;
|
||||
getline(in, tmpString);
|
||||
|
||||
while (!in.eof()) {
|
||||
@@ -22,58 +22,58 @@ bool Simulation::parseCircuit(string fileName)
|
||||
in >> tmp1;
|
||||
|
||||
if (tmpType == "INPUT") {
|
||||
tmpWire = new wire(tmp1, true, tmpString);
|
||||
tmpWire = new Wire(tmp1, true, tmpString);
|
||||
wires.push_back(tmpWire);
|
||||
}
|
||||
else if (tmpType == "OUTPUT") {
|
||||
tmpWire = new wire(tmp1, false, tmpString);
|
||||
tmpWire = new Wire(tmp1, false, tmpString);
|
||||
wires.push_back(tmpWire);
|
||||
}
|
||||
else if (tmpType == "NOT") {
|
||||
in >> tmp2;
|
||||
tmpGate = new notGate(getDelay(tmpString), findWire(tmp1),
|
||||
tmpGate = new NotGate(getDelay(tmpString), findWire(tmp1),
|
||||
findWire(tmp2));
|
||||
gates.push_back(tmpGate);
|
||||
}
|
||||
else if (tmpType == "AND") {
|
||||
in >> tmp2;
|
||||
in >> tmp3;
|
||||
tmpGate = new andGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||
tmpGate = new AndGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||
findWire(tmp3));
|
||||
gates.push_back(tmpGate);
|
||||
}
|
||||
else if (tmpType == "NAND") {
|
||||
in >> tmp2;
|
||||
in >> tmp3;
|
||||
tmpGate = new nandGate(getDelay(tmpString), findWire(tmp1),
|
||||
tmpGate = new NandGate(getDelay(tmpString), findWire(tmp1),
|
||||
findWire(tmp2), findWire(tmp3));
|
||||
gates.push_back(tmpGate);
|
||||
}
|
||||
else if (tmpType == "OR") {
|
||||
in >> tmp2;
|
||||
in >> tmp3;
|
||||
tmpGate = new orGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||
tmpGate = new OrGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||
findWire(tmp3));
|
||||
gates.push_back(tmpGate);
|
||||
}
|
||||
else if (tmpType == "XOR") {
|
||||
in >> tmp2;
|
||||
in >> tmp3;
|
||||
tmpGate = new xorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||
tmpGate = new XorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||
findWire(tmp3));
|
||||
gates.push_back(tmpGate);
|
||||
}
|
||||
else if (tmpType == "NOR") {
|
||||
in >> tmp2;
|
||||
in >> tmp3;
|
||||
tmpGate = new norGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||
tmpGate = new NorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||
findWire(tmp3));
|
||||
gates.push_back(tmpGate);
|
||||
}
|
||||
else if (tmpType == "XNOR") {
|
||||
in >> tmp2;
|
||||
in >> tmp3;
|
||||
tmpGate = new xnorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||
tmpGate = new XnorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||
findWire(tmp3));
|
||||
gates.push_back(tmpGate);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ void Simulation::print()
|
||||
{
|
||||
}
|
||||
|
||||
wire * Simulation::findWire(int n)
|
||||
Wire * Simulation::findWire(int n)
|
||||
{
|
||||
for (auto i = wires.begin(); i != wires.end(); ++i) {
|
||||
if (n == (**i).getNumber()) return *i;
|
||||
|
@@ -24,12 +24,12 @@ class Simulation {
|
||||
void simulate();
|
||||
void print();
|
||||
private:
|
||||
wire* findWire(int n);
|
||||
Wire* findWire(int n);
|
||||
int getDelay(string d);
|
||||
|
||||
priority_queue<event> e;
|
||||
vector<gate*> gates;
|
||||
vector<wire*> wires;
|
||||
priority_queue<Event> e;
|
||||
vector<Gate*> gates;
|
||||
vector<Wire*> wires;
|
||||
};
|
||||
|
||||
#endif // !SIMULATION
|
||||
|
@@ -6,9 +6,9 @@
|
||||
|
||||
class XnorGate : public Gate {
|
||||
public:
|
||||
XnorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||
void evaluate(int evTime);
|
||||
int getDelay();
|
||||
XnorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||
Event evaluate(int evTime);
|
||||
int getDelay();
|
||||
};
|
||||
|
||||
#endif // !XNOR
|
||||
|
@@ -6,9 +6,9 @@
|
||||
|
||||
class XorGate : public Gate {
|
||||
public:
|
||||
XorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||
void evaluate(int evTime);
|
||||
int getDelay();
|
||||
XorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||
Event evaluate(int evTime);
|
||||
int getDelay();
|
||||
};
|
||||
|
||||
#endif // !XOR
|
||||
|
Reference in New Issue
Block a user