-
Notifications
You must be signed in to change notification settings - Fork 0
/
delay_file.cpp
36 lines (33 loc) · 962 Bytes
/
delay_file.cpp
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
#include "delay_file.h"
#include <fstream>
#include <iostream>
#include <vector>
#include "Utils.h"
DelayFile::DelayFile(std::string file_name) : m_file_name(file_name) {
using namespace std;
ifstream in_file;
if(file_name.empty()) {
return;
}
in_file.open(file_name);
if (!in_file) {
cerr << "Unable to open delay file \"" << file_name << "\"" << endl;
return;
}
string line;
vector<string> fileLines = Utils::getLinesFromDelayFile(file_name);
for (auto line : fileLines) {
std::vector<std::string> split = Utils::splitStringByDelimiter(line, ' ');
std::string& name = split[0];
int delay = std::stoi(split[1]);
m_delay_map.insert({name, delay});
}
in_file.close();
}
int DelayFile::delay_of_element(std::string name) const {
try {
return m_delay_map.at(name);
} catch (...) {
return 0; // assume unspecified delays are 0
}
}