From a7a03caa95fdee87ac0be878e2f756078c38dfba Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 10 Apr 2017 18:57:03 -0400 Subject: [PATCH] Define the wire class Fix the pointers in gate --- Radec/Radec/Radec.vcxproj | 18 +++++++++ Radec/Radec/Radec.vcxproj.filters | 66 +++++++++++++++++++++++++++++-- src/gate.cpp | 4 ++ src/gate.h | 2 +- src/wire.cpp | 37 +++++++++++++++++ src/wire.h | 11 ++++-- 6 files changed, 130 insertions(+), 8 deletions(-) diff --git a/Radec/Radec/Radec.vcxproj b/Radec/Radec/Radec.vcxproj index 96d9724..43f9dbb 100644 --- a/Radec/Radec/Radec.vcxproj +++ b/Radec/Radec/Radec.vcxproj @@ -146,12 +146,30 @@ + + + + + + + + + + + + + + + + + + diff --git a/Radec/Radec/Radec.vcxproj.filters b/Radec/Radec/Radec.vcxproj.filters index 1eee084..6171174 100644 --- a/Radec/Radec/Radec.vcxproj.filters +++ b/Radec/Radec/Radec.vcxproj.filters @@ -13,6 +13,12 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {59351a28-3bcc-400e-a008-0a016d171325} + + + {a3a5f1ed-c6cc-458f-b222-1230ba792714} + @@ -21,13 +27,67 @@ Header Files + + Header Files + + + Header Files + + + Header Files\Gates + + + Header Files\Gates + + + Header Files\Gates + + + Header Files\Gates + + + Header Files\Gates + + + Header Files\Gates + + + Header Files\Gates + - - Source Files - Source Files + + Source Files + + + Source Files + + + Source Files\Gates + + + Source Files + + + Source Files\Gates + + + Source Files\Gates + + + Source Files\Gates + + + Source Files\Gates + + + Source Files\Gates + + + Source Files\Gates + \ No newline at end of file diff --git a/src/gate.cpp b/src/gate.cpp index 8b13789..613bbe0 100644 --- a/src/gate.cpp +++ b/src/gate.cpp @@ -1 +1,5 @@ +#include "gate.h" +gate::gate() +{ +} diff --git a/src/gate.h b/src/gate.h index f63152a..acb0281 100644 --- a/src/gate.h +++ b/src/gate.h @@ -8,7 +8,7 @@ class gate { virtual int evaluate() = 0; protected: - wire* in1, in2, out; + wire *in1, *in2, *out; int delay; }; diff --git a/src/wire.cpp b/src/wire.cpp index e69de29..f4765de 100644 --- a/src/wire.cpp +++ b/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); +} diff --git a/src/wire.h b/src/wire.h index 0428904..102fc55 100644 --- a/src/wire.h +++ b/src/wire.h @@ -5,20 +5,23 @@ #include #include +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 history (60, -1); string name; bool isInput; vector gates;