forked from vchukanov/cppimagefilterbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_reader.cpp
More file actions
50 lines (44 loc) · 1.29 KB
/
config_reader.cpp
File metadata and controls
50 lines (44 loc) · 1.29 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
#include "config_reader.h"
config_reader::config_reader() {}
void config_reader::read(std::string config_filename) {
std::ifstream in(config_filename);
int counter = 0;
if (!in.is_open())
throw "Cannot open file.";
else {
std::string line;
while (getline(in, line)) {
config_data support_struct;
std::istringstream i(line);
for (std::string str; i >> str;) {
if (counter == 0)
support_struct.nameOfFilter = str;
else
support_struct.boardersOfArea.push_back(stoi(str));
counter++;
}
if (!(support_struct.nameOfFilter.length() != 0 && support_struct.boardersOfArea.size() == 4))
throw "Incorrect format of config.";
this->confData.push_back(support_struct);
counter = 0;
}
}
in.close();
}
void config_reader::toAreaBoarders(int height, int width) {
for (int j = 0; j < confData.size(); j++) {
for (int i = 0; i < this->confData[j].boardersOfArea.size(); i++) {
if (this->confData[j].boardersOfArea[i] != 0) {
int rem = this->confData[j].boardersOfArea[i];
if (i == 0 || i == 2)
this->confData[j].boardersOfArea[i] = height / rem;
if (i == 1 || i == 3)
this->confData[j].boardersOfArea[i] = width / rem;
}
}
}
}
std::vector<config_data> config_reader::getConfigData() {
return confData;
}
config_reader::~config_reader() {}