diff --git a/src/Wire.cpp b/src/Wire.cpp index f3b8aa7..bd078d2 100644 --- a/src/Wire.cpp +++ b/src/Wire.cpp @@ -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) { if (getValue(setTime) != newValue) { @@ -50,6 +63,11 @@ Gate * Wire::getGate(int index) return nullptr; } +void Wire::setLast(int last) +{ + lastEvent = last; +} + int Wire::getNumber() const { return WireNumber; @@ -64,3 +82,22 @@ string Wire::getName() const { 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; +} diff --git a/src/Wire.h b/src/Wire.h index c7c514e..151a891 100644 --- a/src/Wire.h +++ b/src/Wire.h @@ -4,6 +4,7 @@ #include #include #include +#include using namespace std; @@ -16,12 +17,17 @@ class Wire { void addGate(Gate* newGate); int getValue(int wantedTime) const; + char getChar(int wantedTime) const; int getNumber() const; string getName() const; + int getLast() const; bool setValue(int newValue, int setTime); void convertToIO(string newName); Gate* getGate(int index); + void setLast(int last); + + friend ostream& operator<<(ostream &out, const Wire &c); private: int WireNumber, value, lastEvent;