fix all gate classes and add pointer to priority queue
This commit is contained in:
parent
f365f0ab2b
commit
030cb65800
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
#define NOT
|
||||
|
||||
class not : public gate {
|
||||
notGate(int delay, wire* wire1 = nullptr, wire* wire2 = nullptr);
|
||||
int evaluate();
|
||||
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