summaryrefslogtreecommitdiff
path: root/common/config.h
diff options
context:
space:
mode:
authorAtle Hellvik Havsø <atle@havso.net>2010-11-28 13:19:46 +0100
committerAtle Hellvik Havsø <atle@havso.net>2010-11-28 13:19:46 +0100
commitf56a38083c7e2c4a5f6c333197a3753a642e258d (patch)
treed9cede821d24b0b5c04da62d1334b48ca4347a7a /common/config.h
parent36ebdbc3b66c3772e4b4e7600e9de5cbb2d9c3a6 (diff)
Added a Config class. Example usage:
Config hei; hei.add_element("nick", n); hei.add_element("server", s); hei.add_element("port", p); hei.get_element("nick"); hei.get_element("server"); hei.get_element("port"); Signed-off-by: Atle Hellvik Havsø <atle@havso.net>
Diffstat (limited to 'common/config.h')
-rw-r--r--common/config.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/common/config.h b/common/config.h
new file mode 100644
index 0000000..87e9765
--- /dev/null
+++ b/common/config.h
@@ -0,0 +1,48 @@
+#ifndef CONFIG_H
+#define CONFIG_H
+
+#include <string>
+#include <map>
+
+//! Utility class for handling configuration file
+//! Supported format in config file is:
+//! keyword = value
+//! example: nick = xyz
+class Config{
+ private:
+ //! Map in the format <id, value>
+ std::map<std::string, std::string> config;
+
+ //! The path to the configuration file
+ std::string path;
+
+ //! Loads configuration from file
+ void load_conf();
+
+ //! Saves configuration to file
+ void save_conf();
+
+ public:
+ //! Constructs a object with the default configuration path
+ Config();
+ //! Constructs a object with a custom configuration path
+ Config(std::string path);
+ //! Deletes the object, saving the configuration to a file
+ ~Config();
+
+ //! Adds a std::string value to the configuration
+ //! \param keyword Keyword associated with the value inserted
+ //! \param value The value for the associated keyword
+ void add_element(std::string keyword, std::string value);
+
+ //! Adds a int value to the configuration
+ //! \param keyword Keyword associated with the value inserted
+ //! \param value The value for the associated keyword
+ void add_element(std::string keyword, const int value);
+
+ //! Gets a element from the configuration
+ //! \param keyword The keyword you want the value from
+ std::string get_element(std::string keyword);
+};
+
+#endif