Fix the class names in simulation .cpp

This commit is contained in:
daniel 2017-04-23 19:24:33 -04:00
parent 66e5ae9418
commit 7bf89ece15
19 changed files with 0 additions and 450 deletions

View File

@ -1,31 +0,0 @@
#include "andGate.h"
using namespace std;
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) {
if (in1->getValue(evTime) == 0 || in2->getValue(evTime) == 0) {
if (out->getValue(evTime + delay) != 0) {
e->push(event(e->size, 0, evTime + delay, out));
out->setValue(0, evTime + delay);
}
}
else if(in1->getValue(evTime) == 1 && in2->getValue(evTime) == 1){
if (out->getValue(evTime + delay) != 1) {
e->push(event(e->size, 1, evTime + delay, out));
out->setValue(1, evTime + delay);
}
}
}
int andGate::getDelay()
{
return delay;
}

View File

@ -1,15 +0,0 @@
#ifndef AND
#define AND
#include "gate.h"
#include "event.h"
#include "wire.h"
class andGate : public gate {
public:
andGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
wire* wire3);
void evaluate(int evTime);
int getDelay();
};
#endif // !AND

View File

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

View File

@ -1,16 +0,0 @@
#ifndef EVENT
#define EVENT
using namespace std;
#include "wire.h"
class event {
public:
event(int num, int value, int setTime, wire * output);
friend bool operator<(const event &e1, const event &e2);
private:
int evNum, evValue, evTime;
wire *out;
};
#endif // !EVENT

View File

@ -1,19 +0,0 @@
#ifndef GATE
#define GATE
#include "event.h"
class wire;
class gate {
public:
gate();
virtual void evaluate(int) = 0;
protected:
wire *in1, *in2, *out;
priority_queue<event> *e;
int delay;
};
#endif // !GATE

View File

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

View File

@ -1,16 +0,0 @@
#ifndef NAND
#define NAND
#include "gate.h"
#include "event.h"
#include "wire.h"
using namespace std;
class nandGate : public gate {
public:
nandGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2, wire* wire3);
void evaluate(int time);
int getDelay();
};
#endif // !NAND

View File

@ -1,32 +0,0 @@
#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) {
if (in1->getValue(evTime) == 1 || in2->getValue(evTime) == 1) {
if (out->getValue(evTime + delay) != 0) {
e->push(event(e->size, 0, evTime + delay, out));
out->setValue(0, evTime + delay);
}
}
else if (in1->getValue(evTime) == 0 && in2->getValue(evTime) == 0) {
if (out->getValue(evTime + delay) != 1) {
e->push(event(e->size, 1, evTime + delay, out));
out->setValue(1, evTime + delay);
}
}
}
int norGate::getDelay()
{
return delay;
}

View File

@ -1,15 +0,0 @@
#ifndef NOR
#define NOR
#include "gate.h"
#include "event.h"
#include "wire.h"
class norGate : public gate {
public:
norGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
wire* wire3);
void evaluate(int evTime);
int getDelay();
};
#endif // !NOR

View File

@ -1,31 +0,0 @@
#include "notGate.h"
using namespace std;
notGate::notGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2) {
e = eQueue;
delay = d;
in1 = wire1;
out = wire2;
}
void notGate::evaluate(int evTime) {
if (in1->getValue(evTime) == 0) {
if (out->getValue(evTime + delay) != 0) {
e->push(event(e->size, 0, evTime + delay, out));
out->setValue(0, evTime + delay);
}
}
else{
if (out->getValue(evTime + delay) != 1) {
e->push(event(e->size, 1, evTime + delay, out));
out->setValue(1, evTime + delay);
}
}
}
int notGate::getDelay()
{
return delay;
}

View File

@ -1,14 +0,0 @@
#ifndef NOT
#define NOT
#include "gate.h"
#include "wire.h"
#include "event.h"
class notGate : public gate {
public:
notGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2);
void evaluate(int evTime);
int getDelay();
};
#endif // !NOT

View File

@ -1,32 +0,0 @@
#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) {
if (in1->getValue(evTime) == 1 || in2->getValue(evTime) == 1) {
if (out->getValue(evTime + delay) != 1) {
e->push(event(e->size, 1, evTime + delay, out));
out->setValue(1, evTime + delay);
}
}
else if (in1->getValue(evTime) == 0 && in2->getValue(evTime) == 0) {
if (out->getValue(evTime + delay) != 0) {
e->push(event(e->size, 0, evTime + delay, out));
out->setValue(0, evTime + delay);
}
}
}
int orGate::getDelay()
{
return delay;
}

View File

@ -1,15 +0,0 @@
#ifndef OR
#define OR
#include "gate.h"
#include "event.h"
#include "wire.h"
class orGate : public gate {
public:
orGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
wire* wire3);
void evaluate(int evTime);
int getDelay();
};
#endif // !OR

View File

@ -1,39 +0,0 @@
#include "Wire.h"
Wire::Wire(int number, bool io, string inName)
{
WireNumber = number;
isPrint = io;
name = inName;
value = -1;
lastEvent = 0;
history.insert(history.begin(), 60, -1);
}
int wire::getValue(int time) const
{
for (auto i = history.begin() + time; i != history.begin(); i--) {
if (i[0] != -1) {
return i[0];
}
}
return -1;
}
void wire::setValue(int newValue, int setTime)
{
history[setTime] = newValue;
if (lastEvent < setTime) {
lastEvent = setTime;
}
}
int wire::getNumber() const
{
return wireNumber;
}
void wire::addGate(gate * newGate)
{
gates.push_back(newGate);
}

View File

@ -1,30 +0,0 @@
#ifndef WIRE
#define WIRE
#include <vector>
#include <queue>
#include <string>
using namespace std;
class gate;
class wire {
public:
wire(int number, bool io, string inName = "");
int getValue(int time) const;
void setValue(int newValue, int setTime);
int getNumber() const;
void addGate(gate* newGate);
private:
int wireNumber, value, lastEvent;
vector<int> history;
string name;
bool isPrint;
vector<gate*> gates;
};
#endif // !WIRE

View File

@ -1,34 +0,0 @@
#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) {
if (in1->getValue(evTime) != -1 && in2->getValue(evTime) != -1) {
if (in1->getValue(evTime) == in2->getValue(evTime)) {
if (out->getValue(evTime + delay) != 1) {
e->push(event(e->size, 1, evTime + delay, out));
out->setValue(1, evTime + delay);
}
}
else {
if (out->getValue(evTime + delay) != 0) {
e->push(event(e->size, 0, evTime + delay, out));
out->setValue(0, evTime + delay);
}
}
}
}
int xnorGate::getDelay()
{
return delay;
}

View File

@ -1,15 +0,0 @@
#ifndef XNOR
#define XNOR
#include "gate.h"
#include "event.h"
#include "wire.h"
class xnorGate : public gate {
public:
xnorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
wire* wire3);
void evaluate(int evTime);
int getDelay();
};
#endif // !XNOR

View File

@ -1,34 +0,0 @@
#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) {
if (in1->getValue(evTime) != -1 && in2->getValue(evTime) != -1) {
if (in1->getValue(evTime) != in2->getValue(evTime)) {
if (out->getValue(evTime + delay) != 1) {
e->push(event(e->size, 1, evTime + delay, out));
out->setValue(1, evTime + delay);
}
}
else {
if (out->getValue(evTime + delay) != 0) {
e->push(event(e->size, 0, evTime + delay, out));
out->setValue(0, evTime + delay);
}
}
}
}
int xorGate::getDelay()
{
return delay;
}

View File

@ -1,15 +0,0 @@
#ifndef XOR
#define XOR
#include "gate.h"
#include "event.h"
#include "wire.h"
class xorGate : public gate {
public:
xorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
wire* wire3);
void evaluate(int evTime);
int getDelay();
};
#endif // !XOR