-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigParser.cpp
More file actions
35 lines (30 loc) · 984 Bytes
/
Copy pathConfigParser.cpp
File metadata and controls
35 lines (30 loc) · 984 Bytes
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
#include "ConfigParser.h"
#include <utility>
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#include <tuple>
ConfigParser::ConfigParser(std::string configName): configName(std::move(configName)) {}
std::vector<ConfigTuple> ConfigParser::Parse() {
std::ifstream file(configName);
if(!file.is_open()) {
throw std::runtime_error("Error opening file " + configName);
}
std::vector<ConfigTuple> parsed;
for(std::string line; std::getline(file, line);) {
std::istringstream s(line);
std::vector<std::string> args;
std::string arg;
while(std::getline(s, arg, ' ')) {
args.push_back(arg);
}
if(args.empty()) {
throw std::runtime_error("Empty line in config file");
}
std::string converterName = args[0];
ConfigTuple tuple(args[0], args);
parsed.push_back(tuple);
}
return parsed;
};