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

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