SimpCfg: Convert to a class
This commit is contained in:
parent
28ae0c5b02
commit
1ecca5a7ec
1 changed files with 78 additions and 71 deletions
|
@ -21,9 +21,19 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
std::string str_trim(std::string sin, std::string trimChars=" \t\n") {
|
||||||
|
sin.erase(sin.find_last_not_of(trimChars)+1);
|
||||||
|
sin.erase(0, sin.find_first_not_of(trimChars));
|
||||||
|
return sin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SimpCfg {
|
||||||
|
private:
|
||||||
std::map<std::string, std::map<std::string, std::string>> mapStrings = {};
|
std::map<std::string, std::map<std::string, std::string>> mapStrings = {};
|
||||||
std::map<std::string, std::map<std::string, bool>> mapBools = {};
|
std::map<std::string, std::map<std::string, bool>> mapBools = {};
|
||||||
|
public:
|
||||||
void sc_set_string(std::string &group, std::string &key, std::string &value) {
|
void sc_set_string(std::string &group, std::string &key, std::string &value) {
|
||||||
auto gm = mapStrings[group];
|
auto gm = mapStrings[group];
|
||||||
gm[key] = value;
|
gm[key] = value;
|
||||||
|
@ -44,12 +54,6 @@ bool sc_get_bool(std::string &group, std::string &key) {
|
||||||
return gm[key];
|
return gm[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string str_trim(std::string sin, std::string trimChars=" \t\n") {
|
|
||||||
sin.erase(sin.find_last_not_of(trimChars)+1);
|
|
||||||
sin.erase(0, sin.find_first_not_of(trimChars));
|
|
||||||
return sin;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sc_load(std::string &fname) {
|
void sc_load(std::string &fname) {
|
||||||
std::ifstream f {fname};
|
std::ifstream f {fname};
|
||||||
if (!f) {
|
if (!f) {
|
||||||
|
@ -103,11 +107,14 @@ void sc_load(std::string &fname) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#ifdef TEST_LOGIC
|
#ifdef TEST_LOGIC
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
std::string fname {argv[1]};
|
std::string fname {argv[1]};
|
||||||
sc_load(fname);
|
SimpCfg sc;
|
||||||
|
sc.sc_load(fname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue