This commit is contained in:
Joel Beckmeyer 2017-04-10 21:29:11 -04:00
commit 5229141506
10 changed files with 46 additions and 12 deletions

View File

@ -3,11 +3,16 @@
using namespace std; using namespace std;
andGate::andGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2, andGate::andGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
wire* wire3) : e(eQueue), delay(d), in1(wire1), in2(wire2), out(wire3) {} wire* wire3) {
e = eQueue;
delay = d;
in1 = wire1;
in2 = wire2;
out = wire3;
}
int andGate::evaluate(int evTime) { int andGate::evaluate(int evTime) {
int val1 = in1->getValue(); int val1 = in1->getValue(evTime);
int val2 = in2->getValue(); int val2 = in2->getValue(evTime);
if(val1 != -1 && val2 != -1) { if(val1 != -1 && val2 != -1) {
return val1 && val2; return val1 && val2;
} }

View File

@ -1,5 +1,8 @@
#ifndef AND #ifndef AND
#define AND #define AND
#include "gate.h"
#include "event.h"
#include "wire.h"
class andGate : public gate { class andGate : public gate {
public: public:

View File

@ -1,7 +1,11 @@
#include "event.h" #include "event.h"
event::event(int num, int value, int setTime, int wire, wire *output) : evNum(num), evValue(value), event::event(int num, int value, int setTime, wire * output){
evTime(setTime), out(output) {} evNum = num;
evValue = value;
evTime = setTime;
out = output;
}
bool event::operator<(const event &e1) { bool event::operator<(const event &e1) {
if(evTime == e1.evTime) { if(evTime == e1.evTime) {

View File

@ -1,9 +1,9 @@
#ifndef EVENT #ifndef EVENT
#define EVENT #define EVENT
using namespace std; using namespace std;
#include "wire.h" #include "wire.h"
class event { class event {
public: public:
event(int num, int value, int setTime, wire * output); event(int num, int value, int setTime, wire * output);

View File

@ -1,5 +1,8 @@
#ifndef NOR #ifndef NOR
#define NOR #define NOR
#include "gate.h"
#include "event.h"
#include "wire.h"
class norGate : public gate { class norGate : public gate {
norGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2, norGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,

View File

@ -2,8 +2,13 @@
using namespace std; using namespace std;
notGate::notGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2) notGate::notGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2) {
: e(eQueue), delay(gateDelay), in1(wire1), out(wire2) {} e = eQueue;
delay = d;
in1 = wire1;
out = wire2;
}
void notGate::evaluate(int evTime) { void notGate::evaluate(int evTime) {
int val = in1->getValue(); int val = in1->getValue();

View File

@ -1,7 +1,10 @@
#ifndef OR #ifndef OR
#define OR #define OR
#include "gate.h"
#include "event.h"
#include "wire.h"
class xnorGate : public gate { class orGate : public gate {
orGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2, orGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
wire* wire3); wire* wire3);
void evaluate(int evTime); void evaluate(int evTime);

View File

@ -1,5 +1,8 @@
#ifndef XNOR #ifndef XNOR
#define XNOR #define XNOR
#include "gate.h"
#include "event.h"
#include "wire.h"
class xnorGate : public gate { class xnorGate : public gate {
xnorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2, xnorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,

View File

@ -3,8 +3,13 @@
using namespace std; using namespace std;
xorGate::xorGate(priority_queue<event> *eQueue, int d, wire* wire1, xorGate::xorGate(priority_queue<event> *eQueue, int d, wire* wire1,
wire* wire2, wire* wire3) : e(eQueue), delay(d), in1(wire1), in2(wire2), wire* wire2, wire* wire3) {
out(wire3); e = eQueue;
delay = d;
in1 = wire1;
in2 = wire2;
out = wire3;
}
void xorGate::evaluate(int evTime) { void xorGate::evaluate(int evTime) {
//TODO //TODO

View File

@ -1,5 +1,8 @@
#ifndef XOR #ifndef XOR
#define XOR #define XOR
#include "gate.h"
#include "event.h"
#include "wire.h"
class xorGate : public gate { class xorGate : public gate {
xorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2, xorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,