Define the wire class
Fix the pointers in gate
This commit is contained in:
parent
0abbc7440e
commit
a7a03caa95
@ -146,12 +146,30 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\..\src\andGate.h" />
|
||||||
|
<ClInclude Include="..\..\src\event.h" />
|
||||||
<ClInclude Include="..\..\src\gate.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\wire.h" />
|
||||||
|
<ClInclude Include="..\..\src\xnorGate.h" />
|
||||||
|
<ClInclude Include="..\..\src\xorGate.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\..\src\andGate.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\event.cpp" />
|
||||||
<ClCompile Include="..\..\src\gate.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\wire.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\xnorGate.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\xorGate.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
@ -13,6 +13,12 @@
|
|||||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
<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>
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
</Filter>
|
</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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\gate.h">
|
<ClInclude Include="..\..\src\gate.h">
|
||||||
@ -21,13 +27,67 @@
|
|||||||
<ClInclude Include="..\..\src\wire.h">
|
<ClInclude Include="..\..\src\wire.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\gate.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\wire.cpp">
|
<ClCompile Include="..\..\src\wire.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</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>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -1 +1,5 @@
|
|||||||
|
#include "gate.h"
|
||||||
|
|
||||||
|
gate::gate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@ -8,7 +8,7 @@ class gate {
|
|||||||
virtual int evaluate() = 0;
|
virtual int evaluate() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wire* in1, in2, out;
|
wire *in1, *in2, *out;
|
||||||
int delay;
|
int delay;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
37
src/wire.cpp
37
src/wire.cpp
@ -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);
|
||||||
|
}
|
11
src/wire.h
11
src/wire.h
@ -5,20 +5,23 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
class gate;
|
class gate;
|
||||||
|
|
||||||
class wire {
|
class wire {
|
||||||
public:
|
public:
|
||||||
wire(int number, bool io, string name = "");
|
wire(int number, bool io, string inName = "");
|
||||||
|
|
||||||
int getState() const;
|
int getValue(int time) const;
|
||||||
void setState(bool newValue, int setTime);
|
void setValue(int newValue, int setTime);
|
||||||
|
|
||||||
int getNumber() const;
|
int getNumber() const;
|
||||||
void addGate(gate* newGate);
|
void addGate(gate* newGate);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int wireNumber, value;
|
int wireNumber, value, lastEvent;
|
||||||
|
vector<int> history (60, -1);
|
||||||
string name;
|
string name;
|
||||||
bool isInput;
|
bool isInput;
|
||||||
vector<gate*> gates;
|
vector<gate*> gates;
|
||||||
|
Loading…
Reference in New Issue
Block a user