-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.h
52 lines (48 loc) · 1.25 KB
/
config.h
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
#ifndef OCELOT_CONFIG_H
#define OCELOT_CONFIG_H
#include <string>
#include <map>
class confval {
private:
bool bool_val;
uint32_t uint_val;
std::string str_val;
enum {
CONF_NONEXISTENT,
CONF_BOOL,
CONF_UINT,
CONF_STR,
} val_type;
public:
confval();
confval(bool value);
confval(uint32_t value);
confval(const char * value);
uint32_t get_uint();
bool get_bool();
std::string get_str();
void set(const std::string &val);
};
class config {
private:
template <typename T> void add(const std::string &setting_name, T value);
std::string trim(const std::string str);
void init();
confval * get(const std::string &setting_name);
std::map<std::string, confval> settings;
confval * dummy_setting;
public:
config();
void load(std::istream &conf_file);
void load(const std::string &conf_file_path, std::istream &conf_file);
void reload();
bool get_bool(const std::string &setting_name);
uint32_t get_uint(const std::string &setting_name);
std::string get_str(const std::string &setting_name);
void set(const std::string &setting_name, const std::string &value);
};
template <typename T> void config::add(const std::string &setting_name, T value) {
confval setting(value);
settings[setting_name] = setting;
}
#endif