diff options
author | Stijn Buys <ingar@osirion.org> | 2008-10-06 18:20:06 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-10-06 18:20:06 +0000 |
commit | d13118f006f0249577c5a829c2c22a33fe12d8ac (patch) | |
tree | d6ed21994e4433de06eedd6bb1bc1223d7d2ca1a /src | |
parent | 094221dae7b094bf0d61128634a00d52b265b0d5 (diff) |
updated inifile API
Diffstat (limited to 'src')
-rw-r--r-- | src/filesystem/filesystem.h | 1 | ||||
-rw-r--r-- | src/filesystem/inifile.cc | 35 | ||||
-rw-r--r-- | src/filesystem/inifile.h | 13 |
3 files changed, 42 insertions, 7 deletions
diff --git a/src/filesystem/filesystem.h b/src/filesystem/filesystem.h index f8740d1..b0232f2 100644 --- a/src/filesystem/filesystem.h +++ b/src/filesystem/filesystem.h @@ -9,6 +9,7 @@ #include "filesystem/file.h" #include "filesystem/diskfile.h" +#include "filesystem/inifile.h" #include <string> #include <list> diff --git a/src/filesystem/inifile.cc b/src/filesystem/inifile.cc index 47baebf..90efa15 100644 --- a/src/filesystem/inifile.cc +++ b/src/filesystem/inifile.cc @@ -58,6 +58,10 @@ bool IniFile::got_section(const char * sectionlabel) const { return (last_read_was_section && (section_current.compare(sectionlabel) == 0)); } +bool IniFile::in_section(const char * sectionlabel) const { + return ((section_current.compare(sectionlabel) == 0)); +} + bool IniFile::getline() { char line[1024]; @@ -71,6 +75,7 @@ bool IniFile::getline() { if (inifile_ifs.getline(line, 1024)) { std::string s(line); + aux::trim(s); line_number++; if (s.size() == 0) { @@ -115,6 +120,11 @@ bool IniFile::getline() { return false; } +bool IniFile::got_key() const +{ + return last_read_was_key; +} + bool IniFile::got_key_string(const char * keylabel, std::string & valuestring) { if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { valuestring.assign(value_current); @@ -172,12 +182,19 @@ bool IniFile::got_key_angle(const char * keylabel, float & f) { bool IniFile::got_key_color(const char * keylabel, math::Color & color) { if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { std::istringstream is(value_current); - float r, g, b; + float r, g, b, a; if ((is >> r) && (is >> g) && (is >> b)) { - if ((r > 1) || (g > 1) || (b > 1)) { - r /= 255; g /= 255; b /= 255; + if ((r > 1.0f) || (g > 1.0f) || (b > 1.0f)) { + if (is >> a) { + a /= 255.0f; + } + r /= 255.0f; g /= 255.0f; b /= 255.0f; + } else { + if (!(is >> a)) { + a = 1.0f; + } } - color = math::Color(r, g, b); + color = math::Color(r, g, b, a); } else { color = math::Color(); } @@ -220,6 +237,16 @@ bool IniFile::got_key_bool(const char * keylabel, bool & b) return false; } +void IniFile::unkown_key() const +{ + con_warn << name() << " unknown key '" << key() << "' at line " << line() << std::endl; +} + +void IniFile::unknown_section() const +{ + con_warn << name() << " unknown section '" << section() << "' at line " << line() << std::endl; +} + void IniFile::close() { inifile_ifs.close(); diff --git a/src/filesystem/inifile.h b/src/filesystem/inifile.h index 3efcfc4..765f1af 100644 --- a/src/filesystem/inifile.h +++ b/src/filesystem/inifile.h @@ -52,13 +52,14 @@ public: /// true if the last read statement was a section header bool got_section() const; + /// true if the current section matches + bool in_section(const char *sectionlabel) const; + /// true if the last read statement was a certain section header bool got_section(const char * sectionlabel) const; /// true if the last read statement was a key=value pair - inline bool got_key() const { - return last_read_was_key; - } + bool got_key() const; bool got_key(const char * keylabel); @@ -80,6 +81,12 @@ public: return line_number; } + /// print a default unkown key error + void unkown_key() const; + + /// print a default unkown section error + void unknown_section() const; + /// return true of the ini file is open for reading inline bool is_open() { return inifile_ifs.is_open(); } |