From 7475eb80870d3d2c7967eeb1089abae19ec783c7 Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 24 Apr 2017 20:13:22 -0400 Subject: [PATCH] Add getters for the event class. Add getGate function to wire class. --- src/Event.cpp | 15 +++++++++++++++ src/Event.h | 4 ++++ src/Wire.cpp | 22 +++++++++++++++++----- src/Wire.h | 3 ++- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/Event.cpp b/src/Event.cpp index 8c275ef..6da4bce 100644 --- a/src/Event.cpp +++ b/src/Event.cpp @@ -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; diff --git a/src/Event.h b/src/Event.h index 4a482de..348cb09 100644 --- a/src/Event.h +++ b/src/Event.h @@ -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; diff --git a/src/Wire.cpp b/src/Wire.cpp index b533855..f3b8aa7 100644 --- a/src/Wire.cpp +++ b/src/Wire.cpp @@ -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); - historyValues.push_back(newValue); - if (lastEvent < setTime) { - lastEvent = 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; diff --git a/src/Wire.h b/src/Wire.h index ac45f1d..c7c514e 100644 --- a/src/Wire.h +++ b/src/Wire.h @@ -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;