From f56a38083c7e2c4a5f6c333197a3753a642e258d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atle=20Hellvik=20Havs=C3=B8?= Date: Sun, 28 Nov 2010 13:19:46 +0100 Subject: Added a Config class. Example usage: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- common/config.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 common/config.h (limited to 'common/config.h') 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 +#include + +//! Utility class for handling configuration file +//! Supported format in config file is: +//! keyword = value +//! example: nick = xyz +class Config{ + private: + //! Map in the format + std::map 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 -- cgit v1.2.3