-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbmodel.cpp
93 lines (84 loc) · 2.42 KB
/
bbmodel.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "bbmodel.h"
#include <QStringList>
#include <QFile>
BbModel::BbModel() {
}
void BbModel::addBbData(QString dataString) {
int id = dataString.section(":",6,6).toInt();
double staticT = dataString.section(":",11,11).toDouble();
double staticEn = dataString.section(":",12,12).toDouble();
double dynT = dataString.section(":",13,13).toDouble();
double dynEn = dataString.section(":",14,14).toDouble();
bbData.insert(id, new Data(dynEn, staticEn, dynT, staticT, id));
addAssociation(id, dataString.section(":",7,7).toInt(), dataString.section(":",8,8).toInt());
}
void BbModel::addAssociation(int id, int StL, int EnL) {
int *tmp;
tmp = new int[2];
tmp[0] = StL;
tmp[1] = EnL;
srcList.insert(id, tmp);
}
bool BbModel::findBbLines(QString filename) {
QFile file;
int n=1;
QRegExp rx(".:");
file.setFileName(filename+".ll");
if(file.open(QIODevice::ReadOnly)) {
QString line = file.readLine().constData();
while(line.size() != 0) {
if(line.contains(rx) && !line.contains("\"")){
startLine.append(n);
if(startLine.size() == endLine.size()+2) {
endLine.append(n-1);
}
}
if(line.startsWith("}")) {
endLine.append(n-1);
}
line = file.readLine().constData();
n++;
}
file.close();
return true;
}
else
return false;
}
int BbModel::start(int line) {
if(line < startLine.at(0))
return 0;
else {
QList<int>::iterator itr = qLowerBound(startLine.begin(), startLine.end(), line);
if(*itr == line)
return line;
else {
itr--;
return *itr;
}
}
}
int BbModel::end(int line) {
if(line > endLine.at(endLine.size() - 1))
return 0;
else {
QList<int>::iterator itr = qLowerBound(endLine.begin(), endLine.end(), line);
if(line < startLine.at(endLine.indexOf(*itr)))
return 0;
else
return *itr;
}
}
int* BbModel::getSrc(int line) {
return srcList.value(startLine.indexOf(start(line))+1);
}
int* BbModel::bbLines(int id) {
int *result;
result = new int[2];
result[0] = startLine.at(id-1);
result[1] = endLine.at(id-1);
return result;
}
Data* BbModel::getData(int line) {
return bbData.value(startLine.indexOf(start(line))+1);
}