/* filesystem/inifile.cc This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #include "auxiliary/functions.h" #include "math/mathlib.h" #include "filesystem/filesystem.h" #include "filesystem/inifile.h" #include namespace filesystem { 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()); } bool IniFile::open(const char *ininame) { if (!ininame) return false; if (inifile_stream.is_open()) return false; clear(); std::string inifile_name(ininame); inifile_name.append(".ini"); inifile_stream.open(inifile_name); if (!inifile_stream.good()) { con_warn << "Could not open " << inifile_stream.name() << "!\n"; return false; } return true; } bool IniFile::getline() { return IniStream::getline(inifile_stream); } void IniFile::unknown_value() const { con_warn << name() << " unknown value '" << value() << "' for key '" << key() << "' at line " << line() << std::endl; } void IniFile::unknown_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::unknown_error(const char *text) const { con_warn << name() << " " << (text && text[0] ? text : "unknown error") << " at line " << line() << std::endl; } void IniFile::unknown_error(const std::string &text) const { con_warn << name() << " " << text << " at line " << line() << std::endl; } void IniFile::close() { inifile_stream.close(); } } // namespace filesystem