Fix the gate evaluate definition to return event

This commit is contained in:
daniel 2017-04-23 19:29:29 -04:00
parent 63211c6c8e
commit 5d61e058b4
10 changed files with 112 additions and 112 deletions

View File

@ -146,31 +146,31 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\src\andGate.h" />
<ClInclude Include="..\..\src\event.h" />
<ClInclude Include="..\..\src\gate.h" />
<ClInclude Include="..\..\src\nandGate.h" />
<ClInclude Include="..\..\src\norGate.h" />
<ClInclude Include="..\..\src\notGate.h" />
<ClInclude Include="..\..\src\orGate.h" />
<ClInclude Include="..\..\src\AndGate.h" />
<ClInclude Include="..\..\src\Event.h" />
<ClInclude Include="..\..\src\Gate.h" />
<ClInclude Include="..\..\src\NandGate.h" />
<ClInclude Include="..\..\src\NorGate.h" />
<ClInclude Include="..\..\src\NotGate.h" />
<ClInclude Include="..\..\src\OrGate.h" />
<ClInclude Include="..\..\src\Simulation.h" />
<ClInclude Include="..\..\src\wire.h" />
<ClInclude Include="..\..\src\xnorGate.h" />
<ClInclude Include="..\..\src\xorGate.h" />
<ClInclude Include="..\..\src\Wire.h" />
<ClInclude Include="..\..\src\XnorGate.h" />
<ClInclude Include="..\..\src\XorGate.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\andGate.cpp" />
<ClCompile Include="..\..\src\event.cpp" />
<ClCompile Include="..\..\src\gate.cpp" />
<ClCompile Include="..\..\src\nandGate.cpp" />
<ClCompile Include="..\..\src\norGate.cpp" />
<ClCompile Include="..\..\src\notGate.cpp" />
<ClCompile Include="..\..\src\orGate.cpp" />
<ClCompile Include="..\..\src\AndGate.cpp" />
<ClCompile Include="..\..\src\Event.cpp" />
<ClCompile Include="..\..\src\Gate.cpp" />
<ClCompile Include="..\..\src\NandGate.cpp" />
<ClCompile Include="..\..\src\NorGate.cpp" />
<ClCompile Include="..\..\src\NotGate.cpp" />
<ClCompile Include="..\..\src\OrGate.cpp" />
<ClCompile Include="..\..\src\radec.cpp" />
<ClCompile Include="..\..\src\Simulation.cpp" />
<ClCompile Include="..\..\src\wire.cpp" />
<ClCompile Include="..\..\src\xnorGate.cpp" />
<ClCompile Include="..\..\src\xorGate.cpp" />
<ClCompile Include="..\..\src\Wire.cpp" />
<ClCompile Include="..\..\src\XnorGate.cpp" />
<ClCompile Include="..\..\src\XorGate.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\readme.md" />

View File

@ -21,77 +21,77 @@
</Filter>
</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">
<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\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>
<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">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\radec.cpp">
<Filter>Source Files</Filter>
</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>
<None Include="..\..\readme.md">

View File

@ -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();
};

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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