Skip to content

Commit ff9b253

Browse files
author
xinoip
committed
create delay_file container class
1 parent 75b35f7 commit ff9b253

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

PLODE.pro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ SOURCES += \
2626
main.cpp \
2727
mainwindow.cpp \
2828
singlepath.cpp \
29-
variationmodel.cpp
29+
variationmodel.cpp \
30+
delay_file.cpp
3031

3132
HEADERS += \
3233
PLODELib.h \
@@ -37,7 +38,8 @@ HEADERS += \
3738
delayparser.h \
3839
mainwindow.h \
3940
singlepath.h \
40-
variationmodel.h
41+
variationmodel.h \
42+
delay_file.h
4143

4244
FORMS += \
4345
mainwindow.ui

delay_file.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "delay_file.h"
2+
#include <fstream>
3+
#include <iostream>
4+
#include <vector>
5+
#include "Utils.h"
6+
7+
DelayFile::DelayFile(std::string file_name) : m_file_name(file_name) {
8+
using namespace std;
9+
ifstream in_file;
10+
in_file.open(file_name);
11+
if (!in_file) {
12+
cerr << "Unable to open delay file \"" << file_name << "\"" << endl;
13+
return;
14+
}
15+
16+
string line;
17+
vector<string> fileLines = Utils::getLinesFromDelayFile(file_name);
18+
for (auto line : fileLines) {
19+
std::vector<std::string> split = Utils::splitStringByDelimiter(line, ' ');
20+
std::string& name = split[0];
21+
int delay = std::stoi(split[1]);
22+
m_delay_map.insert({name, delay});
23+
}
24+
in_file.close();
25+
}
26+
27+
int DelayFile::delay_of_element(std::string name) const {
28+
try {
29+
return m_delay_map.at(name);
30+
} catch (...) {
31+
return 0; // assume unspecified delays are 0
32+
}
33+
}

delay_file.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef DELAY_FILE_H
2+
#define DELAY_FILE_H
3+
4+
#include <string>
5+
#include <map>
6+
7+
class DelayFile {
8+
public:
9+
DelayFile(std::string file_name);
10+
11+
int delay_of_element(std::string name) const;
12+
13+
private:
14+
std::string m_file_name;
15+
std::map<std::string, int> m_delay_map;
16+
};
17+
18+
#endif

foo.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
NAND2_1 5
2-
NAND2_2 3
3-
NAND2_3 4
1+
NAND2_1 3
2+
NAND2_2 4
3+
NAND2_3 2
44
NAND2_4 5
5-
NAND2_5 6
5+
NAND2_5 1
66
NAND2_6 7

0 commit comments

Comments
 (0)