-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStore.cpp
More file actions
executable file
·99 lines (63 loc) · 1.78 KB
/
Store.cpp
File metadata and controls
executable file
·99 lines (63 loc) · 1.78 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
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
#include "Store.h"
Store::Store(){}
void Store::Initialise(std::string filename){
std::ifstream file(filename.c_str());
std::string line;
if(file.is_open()){
while (getline(file,line)){
if (line.size()>0){
if (line.at(0)=='#')continue;
std::string key;
std::string value;
std::stringstream stream(line);
if(stream>>key>>value) m_variables[key]=value;
}
}
}
else std::cout<<"\033[38;5;196m WARNING!!!: Config file "<<filename<<" does not exist no config loaded \033[0m"<<std::endl;
file.close();
}
void Store::Print(){
for (std::map<std::string,std::string>::iterator it=m_variables.begin(); it!=m_variables.end(); ++it){
std::cout<< it->first << " => " << it->second <<std::endl;
}
}
void Store::Delete(){
m_variables.clear();
}
void Store::JsonParser(std::string input){
int type=0;
std::string key;
std::string value;
for(std::string::size_type i = 0; i < input.size(); ++i) {
if(input[i]=='\"')type++;
else if(type==1)key+=input[i];
else if(type==3)value+=input[i];
else if(type==4){
type=0;
m_variables[key]=value;
key="";
value="";
}
/*
if(input[i]!=',' && input[i]!='{' && input[i]!='}' && input[i]!='\"' && input[i]!=':' && input[i]!=',')pair<<input[i];
else if(input[i]==':')pair<<" ";
else if(input[i]==',') {
std::cout<<" i = "<<i<<" pair = "<<pair<<std::endl;
pair>>key>>value;
*/
//pair.clear();
//}
}
}
bool Store::Has(std::string key){
return (m_variables.count(key)!=0);
}
const std::map<std::string,std::string>* Store::GetMap(){
return &m_variables;
}
bool Store::Erase(std::string key){
if(not Has(key)) return false;
m_variables.erase(key);
return true;
}