diff options
Diffstat (limited to 'src/filesystem/inifile.h')
-rw-r--r-- | src/filesystem/inifile.h | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/filesystem/inifile.h b/src/filesystem/inifile.h index d3984c5..ba7eb6a 100644 --- a/src/filesystem/inifile.h +++ b/src/filesystem/inifile.h @@ -7,13 +7,11 @@ #ifndef __INCLUDED_FILESYSTEM_INIFILE_H__ #define __INCLUDED_FILESYSTEM_INIFILE_H__ -// project headers -#include "filesystem/file.h" - -// C++ headers #include <string> #include <fstream> +#include "filesystem/file.h" + namespace filesystem { /// a class to read .ini files @@ -21,15 +19,17 @@ namespace filesystem { * consists of one or more [section] headers followed by one or more key=value * pairs. Lines starting with # or ; are considered comments */ -class IniFile : public File { +class IniFile { public: IniFile(); virtual ~IniFile(); /// open the file for reading - virtual void open(const char * filename, std::ios_base::openmode mode = std::ios_base::in); + /** the filename will get the "ini/" prefix and ".ini" suffix + */ + virtual void open(std::string const & name); - IniFile & getline(); + bool getline(); /// current section label inline std::string section() const { @@ -48,6 +48,7 @@ public: /// true if the last read statement was a section header bool got_section() const; + /// true if the last read statement was a certain section header bool got_section(const char * sectionlabel) const; @@ -55,6 +56,7 @@ public: inline bool got_key() const { return last_read_was_key; } + /// check if the last read key=value pair matches keylabel and store the value in valuestring bool got_key_string(char * const keylabel, std::string & valuestring); @@ -62,15 +64,26 @@ public: return line_number; } + /// return true of the ini file is open for reading + inline bool is_open() const { return inifile_ifs.is_open(); } + + /// current filename + inline std::string const & name() const {return inifile_name; } + + /// close the file + void close(); + private: - std::string section_current; - std::string key_current; - std::string value_current; + std::string section_current; + std::string key_current; + std::string value_current; - bool last_read_was_key; - bool last_read_was_section; + bool last_read_was_key; + bool last_read_was_section; - unsigned int line_number; + unsigned int line_number; + std::ifstream inifile_ifs; + std::string inifile_name; }; } |