-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (50 loc) · 1.52 KB
/
main.cpp
File metadata and controls
61 lines (50 loc) · 1.52 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
#include <iostream>
#include <fstream>
#include "ConfigParser.hpp"
class custom_ConfigParser: public ConfigParser
{
public:
custom_ConfigParser(const std::vector<std::string> &v): custom_ConfigParser(v, "="){};
custom_ConfigParser(const std::vector<std::string> &v, const std::string &sep): ConfigParser(v, sep) {};
virtual bool checkMapValidity() override final;
};
bool custom_ConfigParser::checkMapValidity(){
/* Some difficult checks in map*/
std::cout << "Checks passed!" << std::endl;
return true;
}
int main(){
std::vector<std::string> val {"key1", "key2", "key3", "key4"};
std::string line;
custom_ConfigParser line_parser(val);
// parser.viewConfig();
std::fstream my_file("data", std::ios::in);
#if 1
if(my_file.is_open()){
if(!line_parser.parseStream(my_file)){
auto map = line_parser.getMap();
// Example of writing map on stdout
std::cout << "Map:" << std::endl;
for(auto it: map){
std::cout << it.first << "=" << it.second << std::endl;
}
my_file.close();
}
else{
return 1;
}
}
#else
if (my_file.is_open()){
while ( getline (my_file,line) ){
// std::cout << "raw:" << line << '\n';
auto p = line_parser.parseString(line);
if(p != nullptr){
std::cout << "par: " << p->lvalue << "=" << p->rvalue << std::endl;
}
}
my_file.close();
}
#endif
return 0;
}