diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2007-05-11 01:33:42 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2007-05-11 01:33:42 +0000 |
| commit | fafbdab97afb5ec6498ea0ab66b693b9e335f6f1 (patch) | |
| tree | 2f8ad1e735f3b15b123ea2353fedec8affd22790 /pokemod/Ini.cpp | |
| parent | 0d2d8121cbb6a45180d88021fe2e5ac86b3532e3 (diff) | |
| download | sigen-fafbdab97afb5ec6498ea0ab66b693b9e335f6f1.tar.gz sigen-fafbdab97afb5ec6498ea0ab66b693b9e335f6f1.tar.xz sigen-fafbdab97afb5ec6498ea0ab66b693b9e335f6f1.zip | |
Starting INI migration
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@9 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Ini.cpp')
| -rw-r--r-- | pokemod/Ini.cpp | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/pokemod/Ini.cpp b/pokemod/Ini.cpp index 4c108564..6b8448d8 100644 --- a/pokemod/Ini.cpp +++ b/pokemod/Ini.cpp @@ -47,20 +47,14 @@ void PokeGen::PokeMod::Ini::Export(const String &p) Export(fout);
}
-template<typename T>
-void PokeGen::PokeMod::Ini::AddField<T>(const String &n, const T v)
+void PokeGen::PokeMod::Ini::AddField(const String &n, const int v)
{
- std::stringstream ss;
- std::string s;
- ss << v;
- ss >> s;
- fields[n] = s;
+ fields[n] = String("%d", v);
}
-template<>
-void PokeGen::PokeMod::Ini::AddField<bool>(const String &n, const bool v)
+void PokeGen::PokeMod::Ini::AddField(const String &n, const unsigned v)
{
- fields[n] = v ? "true" : "false";
+ fields[n] = String("%u", v);
}
void PokeGen::PokeMod::Ini::AddField(const String &n, const String &v)
@@ -68,6 +62,16 @@ void PokeGen::PokeMod::Ini::AddField(const String &n, const String &v) fields[n] = v;
}
+void PokeGen::PokeMod::Ini::AddField(const String &n, const bool v)
+{
+ fields[n] = v ? "true" : "false";
+}
+
+void PokeGen::PokeMod::Ini::AddField(const String &n, const double v)
+{
+ fields[n] = String("%f", v);
+}
+
PokeGen::PokeMod::String PokeGen::PokeMod::Ini::GetName()
{
return name;
@@ -99,7 +103,7 @@ void PokeGen::PokeMod::Ini::GetValue(const String &field, unsigned &val, unsigne val = ((UINT_MAX < temp) || *end) ? def : temp;
}
-void PokeGen::PokeMod::Ini::GetValue(const String &field, String &val)
+void PokeGen::PokeMod::Ini::GetValue(const String &field, String &val, const String &def)
{
if (!fields.count(field))
{
@@ -147,20 +151,20 @@ bool PokeGen::PokeMod::Ini::Load(std::ifstream &file) String line;
String field;
String value;
- int pos;
fields.clear();
+ unsigned pos;
name = "";
isValid = true;
std::getline(file, line);
- if (line[0] != '[')
+ if (line.at(0) != '[')
return (isValid = false);
- if ((pos = line.find(']')) != line.length() - 1)
+ if (line.at(line.length() - 1) != ']')
return (isValid = false);
- name.assign(line, 1, pos - 1);
+ name.assign(line, 1, line.length() - 2);
std::getline(file, line);
while (!line.empty())
{
- if (line[0] == '[')
+ if (line.at(0) == '[')
return (isValid = false);
pos = line.find('=');
if (pos == std::string::npos)
|
