-
Notifications
You must be signed in to change notification settings - Fork 1
/
MapFile.cpp
52 lines (44 loc) · 1.1 KB
/
MapFile.cpp
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
#include "MapFile.h"
using namespace std;
namespace fs = std::experimental::filesystem;
void MapFile::load_file(fs::path file)
{
ifstream fin(file.string());
string line , key , value;
//This line was to get rid of [Desktop Entry] line at the begining of the file
//Since I'm not going to support it in this implementation so I'm deleting it
//getline(fin, line);
while (getline(fin, line))
{
stringstream ss(line);
getline(ss, key, '=');
getline(ss, value);
if (table[key] == "")
{
table[key] = value;
}
}
}
void MapFile::save_file(fs::path file){
ofstream fout(file.string());
for(auto prop : table){
fout << prop.first << "=" << prop.second << endl;
}
}
std::string &MapFile::value_of(std::string key){
return table[key];
}
bool string_to_bool(std::string str){
if(str == "true"){
return true;
}else if(str == "false"){
return false;
}
}
std::string bool_to_string(bool condition){
if(condition){
return "true";
}else{
return "false";
}
}