Define the wire class

Fix the pointers in gate
This commit is contained in:
daniel 2017-04-10 18:57:03 -04:00
parent 0abbc7440e
commit a7a03caa95
6 changed files with 130 additions and 8 deletions

View File

@ -146,12 +146,30 @@
</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\pQueue.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\pQueue.cpp" />
<ClCompile Include="..\..\src\wire.cpp" />
<ClCompile Include="..\..\src\xnorGate.cpp" />
<ClCompile Include="..\..\src\xorGate.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -13,6 +13,12 @@
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Source Files\Gates">
<UniqueIdentifier>{59351a28-3bcc-400e-a008-0a016d171325}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Gates">
<UniqueIdentifier>{a3a5f1ed-c6cc-458f-b222-1230ba792714}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\gate.h">
@ -21,13 +27,67 @@
<ClInclude Include="..\..\src\wire.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\event.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\pQueue.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>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\gate.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\wire.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\event.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\pQueue.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>
</ItemGroup>
</Project>

View File

@ -1 +1,5 @@
#include "gate.h"
gate::gate()
{
}

View File

@ -8,7 +8,7 @@ class gate {
virtual int evaluate() = 0;
protected:
wire* in1, in2, out;
wire *in1, *in2, *out;
int delay;
};

View File

@ -0,0 +1,37 @@
#include "wire.h"
wire::wire(int number, bool io, string inName)
{
wireNumber = number;
isInput = io;
name = inName;
value = -1;
lastEvent = 0;
}
int wire::getValue(int time) const
{
return history[time];
}
void wire::setValue(int newValue, int setTime)
{
while (setTime < 60 &&
(history[setTime] == -1 || history[setTime] == history[setTime+1])) {
history[setTime] = newValue;
if (lastEvent < setTime) {
lastEvent = setTime;
}
setTime++;
}
}
int wire::getNumber() const
{
return wireNumber;
}
void wire::addGate(gate * newGate)
{
gates.push_back(newGate);
}

View File

@ -5,20 +5,23 @@
#include <queue>
#include <string>
using namespace std;
class gate;
class wire {
public:
wire(int number, bool io, string name = "");
wire(int number, bool io, string inName = "");
int getState() const;
void setState(bool newValue, int setTime);
int getValue(int time) const;
void setValue(int newValue, int setTime);
int getNumber() const;
void addGate(gate* newGate);
private:
int wireNumber, value;
int wireNumber, value, lastEvent;
vector<int> history (60, -1);
string name;
bool isInput;
vector<gate*> gates;