diff options
author | Stijn Buys <ingar@osirion.org> | 2009-02-08 15:27:59 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2009-02-08 15:27:59 +0000 |
commit | 2386bda56b33de68370fa8acc76e39ddddd836c6 (patch) | |
tree | 6de102324d33a70625c90c5839c17dcdc26ac47d /src/filesystem/inifile.cc | |
parent | c8a6ff1c0693ca1bd9025dcbdd7c22e3d193f8dd (diff) |
changed inifile and map to use filesystem::IFileStream
Diffstat (limited to 'src/filesystem/inifile.cc')
-rw-r--r-- | src/filesystem/inifile.cc | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/src/filesystem/inifile.cc b/src/filesystem/inifile.cc index e83c08f..c6cc625 100644 --- a/src/filesystem/inifile.cc +++ b/src/filesystem/inifile.cc @@ -13,11 +13,37 @@ namespace filesystem { -IniFile::IniFile() {} +IniFile::IniFile(const char *ininame) +{ + if (ininame) + open(ininame); +} + +IniFile::IniFile(const std::string & ininame) +{ + if (ininame.size()) + open(ininame.c_str()); +} + +IniFile::~IniFile() +{ + if (inifile_stream.is_open()) + inifile_stream.close(); +} + +bool IniFile::open(std::string const & ininame) +{ + return open(ininame.c_str()); +} -IniFile::~IniFile() {} +bool IniFile::open(const char *ininame) +{ -bool IniFile::open(std::string const & name) { + if (!ininame) + return false; + + if (inifile_stream.is_open()) + return false; last_read_was_section = false; last_read_was_key = false; @@ -26,26 +52,15 @@ bool IniFile::open(std::string const & name) { section_current = ""; line_number = 0; - inifile_name.assign("ini/"); - inifile_name.append(name); + std::string inifile_name("ini/"); + inifile_name.append(ininame); inifile_name.append(".ini"); - - filesystem::File *f = filesystem::open(inifile_name.c_str()); - if (!f) { - con_warn << "Could not open " << inifile_name << std::endl; - return false; - } - - std::string fn = f->path(); - fn.append(f->name()); - filesystem::close(f); - - inifile_ifs.open(fn.c_str()); - if (!inifile_ifs.is_open()) { - con_warn << "Could not stream " << fn << "!\n"; + + inifile_stream.open(inifile_name); + if (!inifile_stream.good()) { + con_warn << "Could not open " << inifile_stream.name() << "!\n"; return false; } - return true; } @@ -70,10 +85,10 @@ bool IniFile::getline() { key_current = ""; value_current = ""; - if (!inifile_ifs.is_open()) + if (!inifile_stream.is_open()) return false; - if (inifile_ifs.getline(line, 1023)) { + if (inifile_stream.getline(line, 1023)) { std::string s(line); aux::trim(s); line_number++; @@ -266,7 +281,7 @@ void IniFile::unknown_section() const void IniFile::close() { - inifile_ifs.close(); + inifile_stream.close(); } } // namespace filesystem |