-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputConfig.h
126 lines (118 loc) · 3.8 KB
/
InputConfig.h
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
int IntInput(string input = "config_file.txt", string key = "TEST")
{
fstream newfile;
int int_num = 0;
newfile.open(input,ios::in); //open a file to perform read operation using file object
if (newfile.is_open())
{ //checking whether the file is open
string tp;
while(getline(newfile, tp))
{ //read data from file object and put it into string.
if (tp.rfind(key, 0) == 0)
{ // pos=0 limits the search to the prefix
istringstream stream(tp);
string s;
stream >> s >> int_num;// s starts with prefix
//cout << run << "\n";
//cout << tp << "\n"; //print the data of the string
}
}
newfile.close(); //close the file object.
}
return int_num;
}
double DoubleInput(string input = "config_file.txt", string key = "TEST")
{
fstream newfile;
double double_num = 0;
newfile.open(input,ios::in); //open a file to perform read operation using file object
if (newfile.is_open())
{ //checking whether the file is open
string tp;
while(getline(newfile, tp))
{ //read data from file object and put it into string.
if (tp.rfind(key, 0) == 0)
{ // pos=0 limits the search to the prefix
istringstream stream(tp);
string s;
stream >> s >> double_num;// s starts with prefix
//cout << run << "\n";
//cout << tp << "\n"; //print the data of the string
}
}
newfile.close(); //close the file object.
}
return double_num;
}
string StringInput(string input = "config_file.txt", string key = "TEST")
{
fstream newfile;
string string_text;
newfile.open(input,ios::in); //open a file to perform read operation using file object
if (newfile.is_open())
{ //checking whether the file is open
string tp;
while(getline(newfile, tp))
{ //read data from file object and put it into string.
if (tp.rfind(key, 0) == 0)
{ // pos=0 limits the search to the prefix
istringstream stream(tp);
string s;
stream >> s >> string_text;// s starts with prefix
}
}
newfile.close(); //close the file object.
}
return string_text;
}
bool BoolInput(string input = "config_file.txt", string key = "TEST")
{
fstream newfile;
string bool_condition;
bool b = false;
newfile.open(input,ios::in); //open a file to perform read operation using file object
if (newfile.is_open())
{ //checking whether the file is open
string tp;
while(getline(newfile, tp))
{ //read data from file object and put it into string.
if (tp.rfind(key, 0) == 0)
{ // pos=0 limits the search to the prefix
istringstream stream(tp);
string s;
stream >> s >> bool_condition; // s starts with prefix
if (bool_condition == "1"){b = true;}
cout << "test: " << b << "\n";
//cout << tp << "\n"; //print the data of the string
}
}
newfile.close(); //close the file object.
}
return b;
}
std::vector<int> IntVectorInput(string input = "config_file.txt", string key = "TEST")
{
fstream newfile;
std::vector<int> int_vector;
newfile.open(input,ios::in); //open a file to perform read operation using file object
if (newfile.is_open())
{ //checking whether the file is open
string tp;
while(getline(newfile, tp))
{ //read data from file object and put it into string.
if (tp.rfind(key, 0) == 0)
{ // pos=0 limits the search to the prefix
istringstream stream(tp);
string s;
while(stream >> s)
{
if(s=="CHANNEL") continue; // skip key string
int_vector.push_back(std::stoi(s)); // convert string into int
}
}
}
newfile.close(); //close the file object.
}
// for (int n:int_vector) cout << "Vector element:" << n << endl; // check vector elements
return int_vector;
}