add the print operator to the wire class

This commit is contained in:
daniel 2017-04-24 21:05:59 -04:00
parent 7475eb8087
commit 3e968534ed
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)
{
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;
}

View File

@ -4,6 +4,7 @@
#include <vector>
#include <queue>
#include <string>
#include <iomanip>
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;