Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/filesystem/inifile.cc')
-rw-r--r--src/filesystem/inifile.cc61
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