fix all gate classes and add pointer to priority queue
This commit is contained in:
parent
517d6e333e
commit
ef14a61ba6
@ -2,8 +2,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
andGate::andGate(wire* wire1 = nullptr, wire* wire2 = nullptr,
|
||||
wire* wire3 = nullptr) : in1(wire1), in2(wire2), out(wire3) {}
|
||||
andGate::andGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3) : e(eQueue), delay(d), in1(wire1), in2(wire2), out(wire3) {}
|
||||
|
||||
int andGate::evaluate(int evTime) {
|
||||
int val1 = in1->getValue();
|
||||
|
@ -3,8 +3,8 @@
|
||||
|
||||
class andGate : public gate {
|
||||
public:
|
||||
andGate(wire* wire1 = nullptr, wire* wire2 = nullptr,
|
||||
wire* wire3 = nullptr);
|
||||
andGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3);
|
||||
int evaluate(int evTime);
|
||||
};
|
||||
|
||||
|
@ -5,10 +5,11 @@ class wire;
|
||||
class gate {
|
||||
public:
|
||||
gate();
|
||||
virtual int evaluate() = 0;
|
||||
virtual void evaluate() = 0;
|
||||
|
||||
protected:
|
||||
wire *in1, *in2, *out;
|
||||
priority_queue<event> *e;
|
||||
int delay;
|
||||
priority_queue<event> *e;
|
||||
};
|
||||
|
@ -0,0 +1,10 @@
|
||||
#include "norGate.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
norGate::norGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3) : e(eQueue), delay(d), in1(wire1), in2(wire2), out(wire3);
|
||||
|
||||
void norGate::evaluate(int evTime) {
|
||||
//TODO
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
#ifndef OR
|
||||
#define OR
|
||||
#ifndef NOR
|
||||
#define NOR
|
||||
|
||||
class orGate : public gate {
|
||||
orGate(wire* wire1 = nullptr, wire* wire2 = nullptr, wire* wire3 = nullptr);
|
||||
int evaluate();
|
||||
class norGate : public gate {
|
||||
norGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3);
|
||||
void evaluate(int evTime);
|
||||
};
|
||||
|
||||
#endif // !OR
|
||||
#endif // !NOR
|
||||
|
@ -2,13 +2,12 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
notGate::notGate(int gateDelay, wire* wire1 = nullptr, wire* wire2 = nullptr)
|
||||
: delay(gateDelay), in1(wire1), out(wire2) {}
|
||||
notGate::notGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2)
|
||||
: e(eQueue), delay(gateDelay), in1(wire1), out(wire2) {}
|
||||
|
||||
notGate::evaluate() {
|
||||
void notGate::evaluate(int evTime) {
|
||||
int val = in1->getValue();
|
||||
|
||||
if(val != -1) {
|
||||
return !val;
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,9 @@
|
||||
#include "wire.h"
|
||||
#include "event.h"
|
||||
|
||||
class notGate : public gate {
|
||||
notGate(int delay, wire* wire1 = nullptr, wire* wire2 = nullptr);
|
||||
int evaluate();
|
||||
class not : public gate {
|
||||
notGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2);
|
||||
void evaluate(int evTime);
|
||||
};
|
||||
|
||||
#endif // !NOT
|
||||
|
@ -0,0 +1,10 @@
|
||||
#include "orGate.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
orGate::orGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3) : e(eQueue), delay(d), in1(wire1), in2(wire2), out(wire3);
|
||||
|
||||
void orGate::evaluate(int evTime) {
|
||||
//TODO
|
||||
}
|
@ -2,8 +2,9 @@
|
||||
#define OR
|
||||
|
||||
class orGate : public gate {
|
||||
orGate(wire* wire1 = nullptr, wire* wire2 = nullptr, wire* wire3 = nullptr);
|
||||
int evaluate();
|
||||
orGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3);
|
||||
void evaluate(int evTime);
|
||||
};
|
||||
|
||||
#endif // !OR
|
||||
|
@ -0,0 +1,11 @@
|
||||
#include "xnorGate.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
xnorGate::xnorGate(priority_queue<event> *eQueue, int d, wire* wire1,
|
||||
wire* wire2, wire* wire3) : e(eQueue), delay(d), in1(wire1), in2(wire2),
|
||||
out(wire3);
|
||||
|
||||
void xnorGate::evaluate(int evTime) {
|
||||
//TODO
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
#ifndef OR
|
||||
#define OR
|
||||
#ifndef XNOR
|
||||
#define XNOR
|
||||
|
||||
class orGate : public gate {
|
||||
orGate(wire* wire1 = nullptr, wire* wire2 = nullptr, wire* wire3 = nullptr);
|
||||
int evaluate();
|
||||
class xnorGate : public gate {
|
||||
xnorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3);
|
||||
void evaluate(int evTime);
|
||||
};
|
||||
|
||||
#endif // !OR
|
||||
#endif // !XNOR
|
||||
|
@ -0,0 +1,11 @@
|
||||
#include "xorGate.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
xorGate::xorGate(priority_queue<event> *eQueue, int d, wire* wire1,
|
||||
wire* wire2, wire* wire3) : e(eQueue), delay(d), in1(wire1), in2(wire2),
|
||||
out(wire3);
|
||||
|
||||
void xorGate::evaluate(int evTime) {
|
||||
//TODO
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
#ifndef OR
|
||||
#define OR
|
||||
#ifndef XOR
|
||||
#define XOR
|
||||
|
||||
class orGate : public gate {
|
||||
orGate(wire* wire1 = nullptr, wire* wire2 = nullptr, wire* wire3 = nullptr);
|
||||
int evaluate();
|
||||
class xorGate : public gate {
|
||||
xorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3);
|
||||
void evaluate(int evTime);
|
||||
};
|
||||
|
||||
#endif // !OR
|
||||
#endif // !XOR
|
||||
|
Loading…
Reference in New Issue
Block a user