add some functionality to andGate class
This commit is contained in:
parent
bc949ffea7
commit
9d0f5beb74
@ -0,0 +1,11 @@
|
|||||||
|
#include "andGate.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
andGate::andGate(wire* wire1 = nullptr, wire* wire2 = nullptr,
|
||||||
|
wire* wire3 = nullptr) : in1(wire1), in2(wire2), out(wire3) {}
|
||||||
|
|
||||||
|
int andGate::evaluate(int evTime) {
|
||||||
|
int bool1 = in1 -> getValue();
|
||||||
|
return ( in1 -> getValue(evTime) ) && ( in2 -> getValue(evTime) );
|
||||||
|
}
|
@ -3,8 +3,9 @@
|
|||||||
|
|
||||||
class andGate : public gate {
|
class andGate : public gate {
|
||||||
public:
|
public:
|
||||||
andGate(wire* wire1 = nullptr, wire* wire2 = nullptr, wire* wire3 = nullptr);
|
andGate(wire* wire1 = nullptr, wire* wire2 = nullptr,
|
||||||
int evaluate();
|
wire* wire3 = nullptr);
|
||||||
|
int evaluate(int evTime);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !AND
|
#endif // !AND
|
||||||
|
@ -5,6 +5,7 @@ using namespace std;
|
|||||||
event::event(event, value, setTime, wire) : evNum(event), evValue(value),
|
event::event(event, value, setTime, wire) : evNum(event), evValue(value),
|
||||||
evTime(setTime), wireNum(wire) {}
|
evTime(setTime), wireNum(wire) {}
|
||||||
|
|
||||||
|
// operator overload so that priority_queue will function correctly
|
||||||
bool event::operator<(const event &e1, const event &e2) {
|
bool event::operator<(const event &e1, const event &e2) {
|
||||||
if(e1.evTime == e2.evTime) {
|
if(e1.evTime == e2.evTime) {
|
||||||
return e1.evNum > e2.evNum;
|
return e1.evNum > e2.evNum;
|
||||||
|
@ -23,7 +23,7 @@ int main() {
|
|||||||
if(parseSuccess) {
|
if(parseSuccess) {
|
||||||
// 2. Parse the vector file to initialize the simulation Queue with initial
|
// 2. Parse the vector file to initialize the simulation Queue with initial
|
||||||
// Wire state (i.e., value) changes
|
// Wire state (i.e., value) changes
|
||||||
queue e;
|
priority_queue< e;
|
||||||
parseSuccess = e.parseVector(fileName);
|
parseSuccess = e.parseVector(fileName);
|
||||||
|
|
||||||
// 3. Simulate the circuit using Event-driven control
|
// 3. Simulate the circuit using Event-driven control
|
||||||
|
Loading…
Reference in New Issue
Block a user