Define the wire class
Fix the pointers in gate
This commit is contained in:
@@ -1 +1,5 @@
|
||||
#include "gate.h"
|
||||
|
||||
gate::gate()
|
||||
{
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ class gate {
|
||||
virtual int evaluate() = 0;
|
||||
|
||||
protected:
|
||||
wire* in1, in2, out;
|
||||
wire *in1, *in2, *out;
|
||||
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 <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;
|
||||
|
Reference in New Issue
Block a user