fix capitalization of classes

This commit is contained in:
Joel Beckmeyer 2017-04-23 19:13:23 -04:00
parent 8cf81bed17
commit e5273f96e2
14 changed files with 276 additions and 3 deletions

31
src/AndGate.cpp Normal file
View File

@ -0,0 +1,31 @@
#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;
}

14
src/AndGate.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef AND
#define AND
#include "Gate.h"
#include "Event.h"
#include "Wire.h"
class AndGate : public Gate {
public:
AndGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
Event evaluate(int evTime);
int getDelay();
};
#endif // !AND

16
src/Event.cpp Normal file
View File

@ -0,0 +1,16 @@
#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;
}

16
src/Event.h Normal file
View File

@ -0,0 +1,16 @@
#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

17
src/Gate.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef GATE
#define GATE
#include "Event.h"
class Wire;
class Gate {
public:
virtual Event evaluate(int) = 0;
protected:
Wire *in1, *in2, *out;
int delay;
};
#endif // !GATE

30
src/NandGate.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "NandGate.h"
NandGate::NandGate(int d, Wire * wire1, Wire * wire2, Wire * wire3)
{
delay = d;
in1 = wire1;
in2 = wire2;
out = wire3;
}
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;
}

16
src/NandGate.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef NAND
#define NAND
#include "Gate.h"
#include "Event.h"
#include "Wire.h"
using namespace std;
class NandGate : public Gate {
public:
NandGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
void evaluate(int time);
int getDelay();
};
#endif // !NAND

31
src/NorGate.cpp Normal file
View File

@ -0,0 +1,31 @@
#include "NorGate.h"
using namespace std;
NorGate::NorGate(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;
}

14
src/NorGate.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef NOR
#define NOR
#include "Gate.h"
#include "Event.h"
#include "Wire.h"
class NorGate : public Gate {
public:
NorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
void evaluate(int evTime);
int getDelay();
};
#endif // !NOR

30
src/NotGate.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "NotGate.h"
using namespace std;
NotGate::NotGate(int d, Wire* wire1, Wire* wire2) {
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;
}

14
src/NotGate.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef NOT
#define NOT
#include "Gate.h"
#include "Wire.h"
#include "Event.h"
class NotGate : public Gate {
public:
NotGate(int d, Wire* wire1, Wire* wire2);
void evaluate(int evTime);
int getDelay();
};
#endif // !NOT

30
src/OrGate.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "OrGate.h"
using namespace std;
OrGate::OrGate(int d, Wire* wire1, Wire* wire2, Wire* wire3) {
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;
}

14
src/OrGate.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef OR
#define OR
#include "Gate.h"
#include "Event.h"
#include "Wire.h"
class OrGate : public Gate {
public:
OrGate(int d, Wire* wire1, Wire* wire2, Wire* wire3);
void evaluate(int evTime);
int getDelay();
};
#endif // !OR

View File

@ -1,8 +1,8 @@
#include "wire.h"
#include "Wire.h"
wire::wire(int number, bool io, string inName)
Wire::Wire(int number, bool io, string inName)
{
wireNumber = number;
WireNumber = number;
isPrint = io;
name = inName;
value = -1;