This commit is contained in:
Joel Beckmeyer
2017-04-10 19:41:12 -04:00
8 changed files with 133 additions and 24 deletions

View File

@@ -1,14 +0,0 @@
#include "event.h"
using namespace std;
event::event(event, value, setTime, wire) : evNum(event), evValue(value),
evTime(setTime), wireNum(wire) {}
// operator overload so that priority_queue will function correctly
bool event::operator<(const event &e1, const event &e2) {
if(e1.evTime == e2.evTime) {
return e1.evNum > e2.evNum;
}
return e1.evTime > e2.evTime;
}

View File

@@ -1,10 +1,11 @@
#ifndef EVENT
#define EVENT
class event {
public:
event(event, value, setTime, wire);
bool operator<(const event &e1, const event &e2);
event(int num, int value, int setTime, int wire);
bool operator<(const event &e1);
private:
int evNum, evValue, evTime, wireNum;
};

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;