Add Queue as input for nand constructor

This commit is contained in:
daniel 2017-04-10 20:28:37 -04:00
parent 030cb65800
commit 42037af8fa
4 changed files with 14 additions and 8 deletions

View File

@ -11,6 +11,7 @@ class gate {
wire *in1, *in2, *out; wire *in1, *in2, *out;
priority_queue<event> *e; priority_queue<event> *e;
int delay; int delay;
priority_queue<event> *e;
}; };
#endif // !GATE #endif // !GATE

View File

@ -1,21 +1,23 @@
#include "nandGate.h" #include "nandGate.h"
nandGate::nandGate(int d, wire * wire1, wire * wire2, wire * wire3) nandGate::nandGate(priority_queue<event> *eQueue, int d, wire * wire1, wire * wire2, wire * wire3)
{ {
in1 = wire1; in1 = wire1;
in2 = wire2; in2 = wire2;
out = wire3; out = wire3;
delay = d; delay = d;
e = eQueue;
} }
int nandGate::evaluate(int time) void nandGate::evaluate(int time)
{ {
if (in1->getValue(time) == 0 || in2->getValue(time) == 0) { if (in1->getValue(time) == 0 || in2->getValue(time) == 0) {
out->setValue(1, time + delay); if (out->getValue(time + delay) != 1) {
return 1;
out->setValue(1, time + delay);
}
} }
else if{ else {
out->setValue(0, time + delay); out->setValue(0, time + delay);
return 0;
} }
} }

View File

@ -8,8 +8,8 @@ using namespace std;
class nandGate : public gate { class nandGate : public gate {
public: public:
nandGate(int d, wire* wire1 = nullptr, wire* wire2 = nullptr, wire* wire3 = nullptr); nandGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2, wire* wire3);
int evaluate(int time); void evaluate(int time);
}; };
#endif // !NAND #endif // !NAND

View File

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