-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkFlowParser.cpp
More file actions
112 lines (98 loc) · 2.39 KB
/
Copy pathWorkFlowParser.cpp
File metadata and controls
112 lines (98 loc) · 2.39 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "WorkFlowParser.h"
#include <iostream>
#include <fstream>
#include "CantOpenFileException.h"
void WorkFlowParser::readWorkFlowFile(std::string filename) {
std::ifstream file;
try {
file.open(filename, std::ios::in);
}
catch (std::exception& exception) {
throw CantOpenFileException("Can't open file " + filename);
}
bool blockSection = true;
while (!file.eof()) {
std::string line = "";
std::getline(file, line);
if (line == "csed") { blockSection = false; }
if (blockSection) {
parseBlockString(line);
}
else {
parseScheme(line);
}
}
file.close();
}
void WorkFlowParser::parseBlockString(std::string& line) {
if (line == "desc") { return; }
BlockArguments blockArgs;
std::string word = "";
int count = 0;
int id;
for (int i = 0; i <= line.size(); i++) {
if (i == line.size() || !isalpha(line[i]) && !isdigit(line[i]) && !ispunct(line[i])) {
if (word.size() > 0) {
if (count == 0) {
try {
id = std::stoi(word);
}
catch (std::invalid_argument& exception) {
throw std::invalid_argument("Id is not a number");
}
}
else if (count == 1) {
blockArgs.setName(word);
}
else {
std::list<std::string> params = blockArgs.getParams();
params.push_back(word);
blockArgs.setParams(params);
}
count++;
word = "";
}
}
else {
if (line[i] != '=') { word.push_back(line[i]); }
}
}
bunchOfBlocksArgs.insert(std::make_pair(id, blockArgs));
}
void WorkFlowParser::parseScheme(std::string& line) {
if (line == "csed") { return; }
std::string num;
int id;
for (int i = 0; i <= line.size(); i++) {
if (i != line.size() && isdigit(line[i])) {
num.push_back(line[i]);
}
else {
if (num.size() > 0) {
try {
id = std::stoi(num);
}
catch (std::invalid_argument& exception) {
throw std::invalid_argument("Id is not a number");
}
scheme.push_back(id);
num = "";
}
}
}
if (num.size() > 0) {
try {
id = std::stoi(num);
}
catch (std::invalid_argument& exception) {
throw std::invalid_argument("Id ia not be a number");
}
scheme.push_back(id);
}
}
const std::map<int, BlockArguments>& WorkFlowParser::getBunchOfBlocksArgs() const {
return bunchOfBlocksArgs;
}
const std::list<int>& WorkFlowParser::getScheme() const {
return scheme;
}