diff options
author | Erik Andersson <erik@packy.se> | 2016-11-22 23:56:43 +0100 |
---|---|---|
committer | Erik Andersson <erik@packy.se> | 2016-11-22 23:56:43 +0100 |
commit | 41954fffc10bfd230f857f57c6871b412d5f2e91 (patch) | |
tree | 010bcf28f294a58b4a22b7276cf615758648bcbe /src/config.h | |
parent | ed374a8dbcdaaf273964293d2805bdd61b148022 (diff) | |
download | ocelot-master.zip ocelot-master.tar.gz ocelot-master.tar.bz2 |
Diffstat (limited to 'src/config.h')
-rw-r--r-- | src/config.h | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/src/config.h b/src/config.h index 97d9d68..ce76ec4 100644 --- a/src/config.h +++ b/src/config.h @@ -2,38 +2,51 @@ #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: - std::string host; - unsigned int port; - unsigned int max_connections; - unsigned int max_read_buffer; - unsigned int max_request_size; - unsigned int timeout_interval; - unsigned int schedule_interval; - unsigned int max_middlemen; - - unsigned int announce_interval; - unsigned int peers_timeout; - - unsigned int reap_peers_interval; - unsigned int del_reason_lifetime; - - // MySQL - std::string mysql_db; - std::string mysql_host; - std::string mysql_username; - std::string mysql_password; - - // Site communication - std::string site_host; - std::string site_password; - std::string site_path; - - std::string report_password; - 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 |