From b15fcd7592e33b5a837047d0810e5b523fa4a7ad Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 5 Jan 2005 22:29:21 +0000 Subject: Small fix in handling spaces around delimiter in ini file. --- src/configuration.h | 69 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 13 deletions(-) (limited to 'src/configuration.h') diff --git a/src/configuration.h b/src/configuration.h index e4239ef0..bae60af3 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -31,31 +31,74 @@ #include /** - * INI configuration handler for reading (and writing) + * INI configuration handler for reading (and writing). * * \ingroup CORE */ class Configuration { public: - void init(std::string); + /** + * \brief Reads INI file and parse all options into memory. + * \param filename Full path to INI file (~/.manaworld/tmw.ini) + */ + void init(std::string filename); - bool write(std::string); + /** + * \brief Writes the current settings back to an ini-file. + * \param filename Full path to INI file (~/.manaworld/tmw.ini) + */ + bool write(std::string filename); - void setValue(std::string, std::string); - void setValue(std::string, float); + /** + * \brief Sets an option using a string value. + * \param key Option identifier. + * \param value Value. + */ + void setValue(std::string key, std::string value); - std::string getValue(std::string, std::string); - float getValue(std::string, float); + /** + * \brief Sets an option using a numeric value. + * \param key Option identifier. + * \param value Value. + */ + void setValue(std::string key, float value); + + /** + * \brief Gets a value as string. + * \param key Option identifier. + * \param deflt Default option if not there or error. + */ + std::string getValue(std::string key, std::string deflt); + + /** + * \brief Gets a value as numeric (float). + * \param key Option identifier. + * \param deflt Default option if not there or error. + */ + float getValue(std::string key, float delflt); private: - bool keyExists(std::string); + /** + * Returns wether they given key exists. + */ + bool keyExists(std::string key); + + /** + * A simple data structure to store the value of a configuration + * option. + */ + class OptionValue { + public: + /** + * Constructor. + */ + OptionValue(); - typedef struct INI_OPTION { - std::string stringValue; - float numericValue; + std::string stringValue; + float numericValue; }; - std::map iniOptions; - std::map::iterator iter; + std::map iniOptions; + std::map::iterator iter; }; #endif -- cgit v1.2.3-70-g09d2