This commit is contained in:
Joel Beckmeyer 2017-04-24 21:09:55 -04:00
commit 75f7f3abd9
2 changed files with 43 additions and 0 deletions

View File

@ -23,6 +23,19 @@ int Wire::getValue(int wantedTime) const
} }
} }
char Wire::getChar(int wantedTime) const
{
if (getValue(wantedTime) == -1) {
return 'x';
}
else if (getValue(wantedTime) == 0) {
return '_';
}
else {
return '-';
}
}
bool Wire::setValue(int newValue, int setTime) bool Wire::setValue(int newValue, int setTime)
{ {
if (getValue(setTime) != newValue) { if (getValue(setTime) != newValue) {
@ -50,6 +63,11 @@ Gate * Wire::getGate(int index)
return nullptr; return nullptr;
} }
void Wire::setLast(int last)
{
lastEvent = last;
}
int Wire::getNumber() const int Wire::getNumber() const
{ {
return WireNumber; return WireNumber;
@ -64,3 +82,22 @@ string Wire::getName() const
{ {
return name; return name;
} }
int Wire::getLast() const
{
return lastEvent;
}
ostream & operator<<(ostream & out, const Wire & c)
{
if (c.isPrint) {
int len = 0;
out << setw(10) << c.name;
while (len <= 60 && len <= c.lastEvent)
{
out << setw(0) << c.getChar(len++);
}
out << endl;
}
return out;
}

View File

@ -4,6 +4,7 @@
#include <vector> #include <vector>
#include <queue> #include <queue>
#include <string> #include <string>
#include <iomanip>
using namespace std; using namespace std;
@ -16,12 +17,17 @@ class Wire {
void addGate(Gate* newGate); void addGate(Gate* newGate);
int getValue(int wantedTime) const; int getValue(int wantedTime) const;
char getChar(int wantedTime) const;
int getNumber() const; int getNumber() const;
string getName() const; string getName() const;
int getLast() const;
bool setValue(int newValue, int setTime); bool setValue(int newValue, int setTime);
void convertToIO(string newName); void convertToIO(string newName);
Gate* getGate(int index); Gate* getGate(int index);
void setLast(int last);
friend ostream& operator<<(ostream &out, const Wire &c);
private: private:
int WireNumber, value, lastEvent; int WireNumber, value, lastEvent;