made formating better

This commit is contained in:
daniel 2017-04-25 20:51:41 -04:00
parent 4f3f006d0d
commit ed164155f8
5 changed files with 36 additions and 16 deletions

View File

@ -1,6 +1,7 @@
#include "Simulation.h"
#include <iostream>
#include <iomanip>
#include <sstream>
bool Simulation::parseCircuit(string fileName)
{
@ -138,7 +139,7 @@ bool Simulation::parseVector(string fileName) {
}
}
void Simulation::simulate() {
void Simulation::simulate(int simTime) {
// loop through event queue
while(!e.empty()) {
bool changed;
@ -151,7 +152,7 @@ void Simulation::simulate() {
output->setValue(tmpEvent.getValue(), tmpEvent.getTime());
// if the wire value changes, evaluate gates
if(changed && !(tmpEvent.getTime() > 60)) {
if(changed && !(tmpEvent.getTime() > simTime)) {
Gate * tmpGate;
Event gateEvent(-1, -1, nullptr);
int index = 0;
@ -170,7 +171,7 @@ void Simulation::simulate() {
}
}
void Simulation::print()
void Simulation::print(int simTime)
{
int lastTime = 0;
int tmpTime = 0;
@ -181,18 +182,22 @@ void Simulation::print()
}
}
cout << "\n\nWire Traces: \n";
// now iterate through wires, printing each of them
for(auto i = wires.begin(); i != wires.end(); ++i) {
(**i).setLast(lastTime);
(**i).setPrintLen(simTime);
cout << **i;
}
int t = 0;
cout << setw(10) << "TIME ";
while(t <= 60 && t <= lastTime) {
cout << setw(5) << left << t;
cout << setw(6) << "TIME: ";
while(t < simTime && t <= lastTime) {
cout << setfill('.') << setw(5) << left << t;
t += 5;
}
cout << t << endl;
}
Wire * Simulation::findWire(int n)

View File

@ -22,8 +22,8 @@ class Simulation {
public:
bool parseCircuit(string fileName);
bool parseVector(string fileName);
void simulate();
void print();
void simulate(int);
void print(int);
private:
Wire* findWire(int n);
int getDelay(string d);

View File

@ -60,7 +60,7 @@ void Wire::convertToIO(string newName)
isPrint = true;
}
Gate * Wire::getGate(int index)
Gate * Wire::getGate(int index) const
{
if (index < gates.size()) {
return gates[index];
@ -73,6 +73,11 @@ void Wire::setLast(int last)
lastEvent = last;
}
void Wire::setPrintLen(int len)
{
printLen = len;
}
int Wire::getNumber() const
{
return WireNumber;
@ -97,12 +102,12 @@ 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(6) << c.name + ": ";
while (len <= c.printLen && len <= c.lastEvent)
{
out << setw(0) << c.getChar(len++);
}
out << endl;
out << endl << endl;
}
return out;
}

View File

@ -25,13 +25,14 @@ class Wire {
void setValue(int newValue, int setTime);
bool doesChange(int newValue, int setTime);
void convertToIO(string newName);
Gate* getGate(int index);
Gate* getGate(int index) const;
void setLast(int last);
void setPrintLen(int);
friend ostream& operator<<(ostream &out, const Wire &c);
private:
int WireNumber, value, lastEvent;
int WireNumber, value, lastEvent, printLen;
vector<int> historyTimes;
vector<int> historyValues;
string name;

View File

@ -7,9 +7,17 @@ int main() {
// to simulate
string fileName;
Simulation e;
int len = 60;
cout << "Please enter filename: ";
getline(cin, fileName);
cout << "How long do you want to simulate to (default 60)? ";
if (cin.peek() == '\n') {
len = 60;
}
else if (!(cin >> len)) {
cout << "Invalid input using 60.\n";
}
e.parseCircuit(fileName);
// 2. Parse the vector file to initialize the simulation Queue with initial
@ -21,8 +29,9 @@ int main() {
// second, determine if e causes a future Wire state change
// third, create and queue any future Wire state changes as new Events
// fourth, apply e's effects
e.simulate();
e.simulate(len);
// 4. Print the results of the simulation
e.print();
e.print(len);
system("pause");
}