Add getters for the event class. Add getGate function to wire class.

This commit is contained in:
daniel 2017-04-24 20:13:22 -04:00
parent 496b61d77b
commit 7475eb8087
4 changed files with 38 additions and 6 deletions

View File

@ -7,6 +7,21 @@ Event::Event(int num, int value, int setTime, Wire * output){
out = output; out = output;
} }
int Event::getValue() const
{
return evValue;
}
int Event::getTime() const
{
return evTime;
}
Wire * Event::getOutput() const
{
return out;
}
bool operator<(const Event &e1, const Event &e2) { bool 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;

View File

@ -8,6 +8,10 @@ class Event {
public: public:
Event(int num, int value, int setTime, Wire * output); Event(int num, int value, int setTime, Wire * output);
friend bool operator<(const Event &e1, const Event &e2); friend bool operator<(const Event &e1, const Event &e2);
int getValue() const;
int getTime() const;
Wire* getOutput() const;
private: private:
int evNum, evValue, evTime; int evNum, evValue, evTime;
Wire *out; Wire *out;

View File

@ -23,13 +23,17 @@ int Wire::getValue(int wantedTime) const
} }
} }
void Wire::setValue(int newValue, int setTime) bool Wire::setValue(int newValue, int setTime)
{ {
historyTimes.push_back(setTime); if (getValue(setTime) != newValue) {
historyValues.push_back(newValue); historyTimes.push_back(setTime);
if (lastEvent < setTime) { historyValues.push_back(newValue);
lastEvent = setTime; if (lastEvent < setTime) {
lastEvent = setTime;
}
return true; // I changed the value
} }
return false; // Nothing changed
} }
void Wire::convertToIO(string newName) void Wire::convertToIO(string newName)
@ -38,6 +42,14 @@ void Wire::convertToIO(string newName)
isPrint = true; isPrint = true;
} }
Gate * Wire::getGate(int index)
{
if (index >= gates.size()) {
return gates[index];
}
return nullptr;
}
int Wire::getNumber() const int Wire::getNumber() const
{ {
return WireNumber; return WireNumber;

View File

@ -19,8 +19,9 @@ class Wire {
int getNumber() const; int getNumber() const;
string getName() const; string getName() const;
void setValue(int newValue, int setTime); bool setValue(int newValue, int setTime);
void convertToIO(string newName); void convertToIO(string newName);
Gate* getGate(int index);
private: private:
int WireNumber, value, lastEvent; int WireNumber, value, lastEvent;