-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigParser.cpp
More file actions
77 lines (62 loc) · 2.58 KB
/
ConfigParser.cpp
File metadata and controls
77 lines (62 loc) · 2.58 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
//
// Created by Johannes on 22.06.19.
//
#include "ConfigParser.h"
struct ConfigParser {
unsigned width = 1024;
unsigned height = 1024;
unsigned count = 3;
unsigned redStartParams[4] = {1, 1, 2, 1};
unsigned greenStartParams[4] = {1, 1, 2, 1};
unsigned blueStartParams[4] = {1, 1, 2, 1};
unsigned recursions = 2;
void load(const std::string& filename) {
std::cout << "Loading: " + filename + "\n";
std::ifstream inputStream;
inputStream.open(filename);
std::string line;
std::string firstWord;
if (inputStream.is_open()) {
bool comment = false;
while (inputStream.peek() != EOF) {
inputStream >> firstWord;
if (firstWord == "/*#") {
//comment
comment = true;
}else if(firstWord == "#*/"){
comment = false;
continue;
}
if(comment){
continue;
}
if (firstWord == "width") {
inputStream >> width;
} else if (firstWord == "height") {
inputStream >> height;
} else if (firstWord == "redStartParams") {
inputStream >> redStartParams[0] >> redStartParams[1] >> redStartParams[2] >> redStartParams[3];
} else if (firstWord == "greenStartParams") {
inputStream >> greenStartParams[0] >> greenStartParams[1] >> greenStartParams[2] >> greenStartParams[3];
} else if (firstWord == "blueStartParams") {
inputStream >> blueStartParams[0] >> blueStartParams[1] >> blueStartParams[2] >> blueStartParams[3];
} else if (firstWord == "count") {
inputStream >> count;
} else if (firstWord == "recursions") {
inputStream >> recursions;
}else {
std::cout << "Error. Parameter could not be read: " + firstWord + "\n";
}
}
} else {
std::cout << "Error. The config file could not be opened and thus could not be read. Path: " + filename +"\n";
}
inputStream.close();
}
unsigned getWidth() { return width; }
unsigned getHeigth() { return height; }
unsigned getCount() { return count; }
unsigned int *getRedStartParams() { return redStartParams; }
unsigned int *getGreenStartParams() { return greenStartParams; }
unsigned int *getBlueStartParams() { return blueStartParams; }
};