-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigparser.cpp
More file actions
44 lines (31 loc) · 981 Bytes
/
Copy pathconfigparser.cpp
File metadata and controls
44 lines (31 loc) · 981 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
36
37
38
39
40
41
42
43
44
#include "configparser.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include "config.hpp"
#include "utils.hpp"
void ConfigParser::read(std::string const &filename)
{
std::ifstream file(filename.c_str());
if(!file)
throw std::runtime_error("Error: Can't read config file " + filename);
for(std::string line; std::getline(file, line); )
{
std::istringstream stream(line);
std::string key;
std::string value;
stream >> key;
std::getline(stream, value);
Config::set(key, Utils::trim(value));
}
file.close();
}
void ConfigParser::write(const std::string& filename)
{
std::ofstream file(filename.c_str());
if(!file)
throw std::runtime_error("Error: Can't write config file " + filename);
for(auto const& pair: Config::map())
file << pair.first << " " << pair.second << std::endl;
file.close();
}