finish fixing class names

This commit is contained in:
Joel Beckmeyer 2017-04-23 19:18:11 -04:00
parent e5273f96e2
commit 66e5ae9418
6 changed files with 161 additions and 0 deletions

39
src/Wire.cpp Normal file
View File

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

30
src/Wire.h Normal file
View File

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

32
src/XnorGate.cpp Normal file
View File

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

14
src/XnorGate.h Normal file
View File

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

32
src/XorGate.cpp Normal file
View File

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

14
src/XorGate.h Normal file
View File

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