Fix the gate evaluate definition to return event
This commit is contained in:
parent
63211c6c8e
commit
5d61e058b4
@ -146,31 +146,31 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\andGate.h" />
|
<ClInclude Include="..\..\src\AndGate.h" />
|
||||||
<ClInclude Include="..\..\src\event.h" />
|
<ClInclude Include="..\..\src\Event.h" />
|
||||||
<ClInclude Include="..\..\src\gate.h" />
|
<ClInclude Include="..\..\src\Gate.h" />
|
||||||
<ClInclude Include="..\..\src\nandGate.h" />
|
<ClInclude Include="..\..\src\NandGate.h" />
|
||||||
<ClInclude Include="..\..\src\norGate.h" />
|
<ClInclude Include="..\..\src\NorGate.h" />
|
||||||
<ClInclude Include="..\..\src\notGate.h" />
|
<ClInclude Include="..\..\src\NotGate.h" />
|
||||||
<ClInclude Include="..\..\src\orGate.h" />
|
<ClInclude Include="..\..\src\OrGate.h" />
|
||||||
<ClInclude Include="..\..\src\Simulation.h" />
|
<ClInclude Include="..\..\src\Simulation.h" />
|
||||||
<ClInclude Include="..\..\src\wire.h" />
|
<ClInclude Include="..\..\src\Wire.h" />
|
||||||
<ClInclude Include="..\..\src\xnorGate.h" />
|
<ClInclude Include="..\..\src\XnorGate.h" />
|
||||||
<ClInclude Include="..\..\src\xorGate.h" />
|
<ClInclude Include="..\..\src\XorGate.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\andGate.cpp" />
|
<ClCompile Include="..\..\src\AndGate.cpp" />
|
||||||
<ClCompile Include="..\..\src\event.cpp" />
|
<ClCompile Include="..\..\src\Event.cpp" />
|
||||||
<ClCompile Include="..\..\src\gate.cpp" />
|
<ClCompile Include="..\..\src\Gate.cpp" />
|
||||||
<ClCompile Include="..\..\src\nandGate.cpp" />
|
<ClCompile Include="..\..\src\NandGate.cpp" />
|
||||||
<ClCompile Include="..\..\src\norGate.cpp" />
|
<ClCompile Include="..\..\src\NorGate.cpp" />
|
||||||
<ClCompile Include="..\..\src\notGate.cpp" />
|
<ClCompile Include="..\..\src\NotGate.cpp" />
|
||||||
<ClCompile Include="..\..\src\orGate.cpp" />
|
<ClCompile Include="..\..\src\OrGate.cpp" />
|
||||||
<ClCompile Include="..\..\src\radec.cpp" />
|
<ClCompile Include="..\..\src\radec.cpp" />
|
||||||
<ClCompile Include="..\..\src\Simulation.cpp" />
|
<ClCompile Include="..\..\src\Simulation.cpp" />
|
||||||
<ClCompile Include="..\..\src\wire.cpp" />
|
<ClCompile Include="..\..\src\Wire.cpp" />
|
||||||
<ClCompile Include="..\..\src\xnorGate.cpp" />
|
<ClCompile Include="..\..\src\XnorGate.cpp" />
|
||||||
<ClCompile Include="..\..\src\xorGate.cpp" />
|
<ClCompile Include="..\..\src\XorGate.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\readme.md" />
|
<None Include="..\..\readme.md" />
|
||||||
|
@ -21,77 +21,77 @@
|
|||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\gate.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\wire.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\event.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\andGate.h">
|
|
||||||
<Filter>Header Files\Gates</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\nandGate.h">
|
|
||||||
<Filter>Header Files\Gates</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\norGate.h">
|
|
||||||
<Filter>Header Files\Gates</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\orGate.h">
|
|
||||||
<Filter>Header Files\Gates</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\notGate.h">
|
|
||||||
<Filter>Header Files\Gates</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\xnorGate.h">
|
|
||||||
<Filter>Header Files\Gates</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\xorGate.h">
|
|
||||||
<Filter>Header Files\Gates</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\Simulation.h">
|
<ClInclude Include="..\..\src\Simulation.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\AndGate.h">
|
||||||
|
<Filter>Header Files\Gates</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\NandGate.h">
|
||||||
|
<Filter>Header Files\Gates</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\NorGate.h">
|
||||||
|
<Filter>Header Files\Gates</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\NotGate.h">
|
||||||
|
<Filter>Header Files\Gates</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\OrGate.h">
|
||||||
|
<Filter>Header Files\Gates</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\XnorGate.h">
|
||||||
|
<Filter>Header Files\Gates</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\XorGate.h">
|
||||||
|
<Filter>Header Files\Gates</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Event.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Gate.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Wire.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\wire.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\event.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\andGate.cpp">
|
|
||||||
<Filter>Source Files\Gates</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\gate.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\nandGate.cpp">
|
|
||||||
<Filter>Source Files\Gates</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\norGate.cpp">
|
|
||||||
<Filter>Source Files\Gates</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\notGate.cpp">
|
|
||||||
<Filter>Source Files\Gates</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\orGate.cpp">
|
|
||||||
<Filter>Source Files\Gates</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\xnorGate.cpp">
|
|
||||||
<Filter>Source Files\Gates</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\xorGate.cpp">
|
|
||||||
<Filter>Source Files\Gates</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\Simulation.cpp">
|
<ClCompile Include="..\..\src\Simulation.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\radec.cpp">
|
<ClCompile Include="..\..\src\radec.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\AndGate.cpp">
|
||||||
|
<Filter>Source Files\Gates</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\NandGate.cpp">
|
||||||
|
<Filter>Source Files\Gates</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\NorGate.cpp">
|
||||||
|
<Filter>Source Files\Gates</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\NotGate.cpp">
|
||||||
|
<Filter>Source Files\Gates</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\OrGate.cpp">
|
||||||
|
<Filter>Source Files\Gates</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\XnorGate.cpp">
|
||||||
|
<Filter>Source Files\Gates</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\XorGate.cpp">
|
||||||
|
<Filter>Source Files\Gates</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\Event.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\Gate.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\Wire.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\readme.md">
|
<None Include="..\..\readme.md">
|
||||||
|
@ -9,7 +9,7 @@ using namespace std;
|
|||||||
class NandGate : public Gate {
|
class NandGate : public Gate {
|
||||||
public:
|
public:
|
||||||
NandGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
NandGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||||
void evaluate(int time);
|
Event evaluate(int time);
|
||||||
int getDelay();
|
int getDelay();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
class NorGate : public Gate {
|
class NorGate : public Gate {
|
||||||
public:
|
public:
|
||||||
NorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
NorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||||
void evaluate(int evTime);
|
Event evaluate(int evTime);
|
||||||
int getDelay();
|
int getDelay();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
class NotGate : public Gate {
|
class NotGate : public Gate {
|
||||||
public:
|
public:
|
||||||
NotGate(int d, Wire* wire1, Wire* wire2);
|
NotGate(int d, Wire* wire1, Wire* wire2);
|
||||||
void evaluate(int evTime);
|
Event evaluate(int evTime);
|
||||||
int getDelay();
|
int getDelay();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
class OrGate : public Gate {
|
class OrGate : public Gate {
|
||||||
public:
|
public:
|
||||||
OrGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
OrGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||||
void evaluate(int evTime);
|
Event evaluate(int evTime);
|
||||||
int getDelay();
|
int getDelay();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ bool Simulation::parseCircuit(string fileName)
|
|||||||
|
|
||||||
string tmpString, tmpType;
|
string tmpString, tmpType;
|
||||||
int tmp1, tmp2, tmp3;
|
int tmp1, tmp2, tmp3;
|
||||||
wire *tmpWire;
|
Wire *tmpWire;
|
||||||
gate *tmpGate;
|
Gate *tmpGate;
|
||||||
getline(in, tmpString);
|
getline(in, tmpString);
|
||||||
|
|
||||||
while (!in.eof()) {
|
while (!in.eof()) {
|
||||||
@ -22,58 +22,58 @@ bool Simulation::parseCircuit(string fileName)
|
|||||||
in >> tmp1;
|
in >> tmp1;
|
||||||
|
|
||||||
if (tmpType == "INPUT") {
|
if (tmpType == "INPUT") {
|
||||||
tmpWire = new wire(tmp1, true, tmpString);
|
tmpWire = new Wire(tmp1, true, tmpString);
|
||||||
wires.push_back(tmpWire);
|
wires.push_back(tmpWire);
|
||||||
}
|
}
|
||||||
else if (tmpType == "OUTPUT") {
|
else if (tmpType == "OUTPUT") {
|
||||||
tmpWire = new wire(tmp1, false, tmpString);
|
tmpWire = new Wire(tmp1, false, tmpString);
|
||||||
wires.push_back(tmpWire);
|
wires.push_back(tmpWire);
|
||||||
}
|
}
|
||||||
else if (tmpType == "NOT") {
|
else if (tmpType == "NOT") {
|
||||||
in >> tmp2;
|
in >> tmp2;
|
||||||
tmpGate = new notGate(getDelay(tmpString), findWire(tmp1),
|
tmpGate = new NotGate(getDelay(tmpString), findWire(tmp1),
|
||||||
findWire(tmp2));
|
findWire(tmp2));
|
||||||
gates.push_back(tmpGate);
|
gates.push_back(tmpGate);
|
||||||
}
|
}
|
||||||
else if (tmpType == "AND") {
|
else if (tmpType == "AND") {
|
||||||
in >> tmp2;
|
in >> tmp2;
|
||||||
in >> tmp3;
|
in >> tmp3;
|
||||||
tmpGate = new andGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
tmpGate = new AndGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||||
findWire(tmp3));
|
findWire(tmp3));
|
||||||
gates.push_back(tmpGate);
|
gates.push_back(tmpGate);
|
||||||
}
|
}
|
||||||
else if (tmpType == "NAND") {
|
else if (tmpType == "NAND") {
|
||||||
in >> tmp2;
|
in >> tmp2;
|
||||||
in >> tmp3;
|
in >> tmp3;
|
||||||
tmpGate = new nandGate(getDelay(tmpString), findWire(tmp1),
|
tmpGate = new NandGate(getDelay(tmpString), findWire(tmp1),
|
||||||
findWire(tmp2), findWire(tmp3));
|
findWire(tmp2), findWire(tmp3));
|
||||||
gates.push_back(tmpGate);
|
gates.push_back(tmpGate);
|
||||||
}
|
}
|
||||||
else if (tmpType == "OR") {
|
else if (tmpType == "OR") {
|
||||||
in >> tmp2;
|
in >> tmp2;
|
||||||
in >> tmp3;
|
in >> tmp3;
|
||||||
tmpGate = new orGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
tmpGate = new OrGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||||
findWire(tmp3));
|
findWire(tmp3));
|
||||||
gates.push_back(tmpGate);
|
gates.push_back(tmpGate);
|
||||||
}
|
}
|
||||||
else if (tmpType == "XOR") {
|
else if (tmpType == "XOR") {
|
||||||
in >> tmp2;
|
in >> tmp2;
|
||||||
in >> tmp3;
|
in >> tmp3;
|
||||||
tmpGate = new xorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
tmpGate = new XorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||||
findWire(tmp3));
|
findWire(tmp3));
|
||||||
gates.push_back(tmpGate);
|
gates.push_back(tmpGate);
|
||||||
}
|
}
|
||||||
else if (tmpType == "NOR") {
|
else if (tmpType == "NOR") {
|
||||||
in >> tmp2;
|
in >> tmp2;
|
||||||
in >> tmp3;
|
in >> tmp3;
|
||||||
tmpGate = new norGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
tmpGate = new NorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||||
findWire(tmp3));
|
findWire(tmp3));
|
||||||
gates.push_back(tmpGate);
|
gates.push_back(tmpGate);
|
||||||
}
|
}
|
||||||
else if (tmpType == "XNOR") {
|
else if (tmpType == "XNOR") {
|
||||||
in >> tmp2;
|
in >> tmp2;
|
||||||
in >> tmp3;
|
in >> tmp3;
|
||||||
tmpGate = new xnorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
tmpGate = new XnorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
||||||
findWire(tmp3));
|
findWire(tmp3));
|
||||||
gates.push_back(tmpGate);
|
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) {
|
for (auto i = wires.begin(); i != wires.end(); ++i) {
|
||||||
if (n == (**i).getNumber()) return *i;
|
if (n == (**i).getNumber()) return *i;
|
||||||
|
@ -24,12 +24,12 @@ class Simulation {
|
|||||||
void simulate();
|
void simulate();
|
||||||
void print();
|
void print();
|
||||||
private:
|
private:
|
||||||
wire* findWire(int n);
|
Wire* findWire(int n);
|
||||||
int getDelay(string d);
|
int getDelay(string d);
|
||||||
|
|
||||||
priority_queue<event> e;
|
priority_queue<Event> e;
|
||||||
vector<gate*> gates;
|
vector<Gate*> gates;
|
||||||
vector<wire*> wires;
|
vector<Wire*> wires;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !SIMULATION
|
#endif // !SIMULATION
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
class XnorGate : public Gate {
|
class XnorGate : public Gate {
|
||||||
public:
|
public:
|
||||||
XnorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
XnorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||||
void evaluate(int evTime);
|
Event evaluate(int evTime);
|
||||||
int getDelay();
|
int getDelay();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
class XorGate : public Gate {
|
class XorGate : public Gate {
|
||||||
public:
|
public:
|
||||||
XorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
XorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
|
||||||
void evaluate(int evTime);
|
Event evaluate(int evTime);
|
||||||
int getDelay();
|
int getDelay();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user