Skip to content

Commit 0316c8f

Browse files
committed
SimpCfg: Initial skeleton : get and set string and bool values
1 parent e118f4c commit 0316c8f

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

common/simpcfg.hpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#pragma once
2+
3+
/**
4+
* Provide a simple config file logic
5+
* It can consist of multiple config groups.
6+
* * the group name needs to start at the begining of the line.
7+
* Each group can inturn contain multiple config fields wrt that group.
8+
* * the group fields need to have 1 or more space at the begining of line.
9+
*
10+
*/
11+
12+
#include <map>
13+
#include <string>
14+
#include <vector>
15+
#include <fstream>
16+
17+
#include "log.h"
18+
19+
20+
std::map<std::string, std::map<std::string, std::string>> mapStrings = {};
21+
std::map<std::string, std::map<std::string, bool>> mapBools = {};
22+
23+
void sc_set_string(std::string &group, std::string &key, std::string &value) {
24+
auto gm = mapStrings[group];
25+
gm[key] = value;
26+
}
27+
28+
void sc_set_bool(std::string &group, std::string &key, bool value) {
29+
auto gm = mapBools[group];
30+
gm[key] = value;
31+
}
32+
33+
std::string sc_get_string(std::string &group, std::string &key) {
34+
auto gm = mapStrings[group];
35+
return gm[key];
36+
}
37+
38+
bool sc_get_bool(std::string &group, std::string &key) {
39+
auto gm = mapBools[group];
40+
return gm[key];
41+
}
42+
43+
std::string str_trim(std::string &sin) {
44+
std::string sout = sin;
45+
sout.erase(sout.find_last);
46+
}
47+
48+
bool sc_load(std::string &fname) {
49+
std::ifstream f {fname};
50+
if (!f) {
51+
LOG_TEELN("ERRR:%s:%s:failed to load...", __func__, fname);
52+
exit(2);
53+
}
54+
while(!f.eof()) {
55+
std::string curl;
56+
getline(f, curl);
57+
if (curl.empty()) {
58+
continue;
59+
}
60+
61+
}
62+
}

0 commit comments

Comments
 (0)