-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulation.cpp
More file actions
49 lines (38 loc) · 921 Bytes
/
Simulation.cpp
File metadata and controls
49 lines (38 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "Simulation.h"
#include <fstream>
#include <iostream>
using namespace std;
Simulation::Simulation()
: testCaseFile(),
currentTime(0) {}
void Simulation::init(const string &file) {
testCaseFile = file;
currentTime = 0;
}
void Simulation::run() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
istream *in = &cin;
ifstream fin;
if (!testCaseFile.empty()) {
fin.open(testCaseFile);
if (fin.is_open()) {
in = &fin;
} else {
cerr << "Could not open " << testCaseFile
<< ", reading from stdin instead.\n";
}
}
string line;
while (getline(*in, line)) {
currentTime++;
tm.processCommand(line);
}
}
void Simulation::processNextCommand(const string &line) {
currentTime++;
tm.processCommand(line);
}
void Simulation::queryState() {
tm.queryState();
}