Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: b0cab0275994b754c242bfe05077ff05ceeca813 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
   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 <sstream>

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