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;
}
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) {
if(e1.evTime == e2.evTime) {
return e1.evNum > e2.evNum;

View File

@ -8,6 +8,10 @@ class Event {
public:
Event(int num, int value, int setTime, Wire * output);
friend bool operator<(const Event &e1, const Event &e2);
int getValue() const;
int getTime() const;
Wire* getOutput() const;
private:
int evNum, evValue, evTime;
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)
{
if (getValue(setTime) != newValue) {
historyTimes.push_back(setTime);
historyValues.push_back(newValue);
if (lastEvent < setTime) {
lastEvent = setTime;
}
return true; // I changed the value
}
return false; // Nothing changed
}
void Wire::convertToIO(string newName)
@ -38,6 +42,14 @@ void Wire::convertToIO(string newName)
isPrint = true;
}
Gate * Wire::getGate(int index)
{
if (index >= gates.size()) {
return gates[index];
}
return nullptr;
}
int Wire::getNumber() const
{
return WireNumber;

View File

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