summaryrefslogtreecommitdiffstats
path: root/pokemod/Ini.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pokemod/Ini.cpp')
-rw-r--r--pokemod/Ini.cpp165
1 files changed, 93 insertions, 72 deletions
diff --git a/pokemod/Ini.cpp b/pokemod/Ini.cpp
index 6fd7347f..e78adef6 100644
--- a/pokemod/Ini.cpp
+++ b/pokemod/Ini.cpp
@@ -47,6 +47,21 @@ void PokeGen::PokeMod::Ini::Export(const String &p) const
Export(fout);
}
+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 char v)
+{
+ fields[n] = String("%c", v);
+}
+
+void PokeGen::PokeMod::Ini::AddField(const String &n, const unsigned char v)
+{
+ fields[n] = String("%x", v);
+}
+
void PokeGen::PokeMod::Ini::AddField(const String &n, const int v)
{
fields[n] = String("%d", v);
@@ -57,36 +72,54 @@ void PokeGen::PokeMod::Ini::AddField(const String &n, const unsigned v)
fields[n] = String("%u", v);
}
-void PokeGen::PokeMod::Ini::AddField(const String &n, const unsigned char v)
-{
- fields[n] = String("%x", v);
-}
-
-void PokeGen::PokeMod::Ini::AddField(const String &n, const char *v)
-{
- fields[n] = v;
-}
-
+void PokeGen::PokeMod::Ini::AddField(const String &n, const double v)
+{
+ fields[n] = String("%f", v);
+}
+
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() const
{
return name;
}
+void PokeGen::PokeMod::Ini::GetValue(const String &field, bool &val, const bool def)
+{
+ if (!fields.count(field))
+ {
+ val = def;
+ return;
+ }
+ if (!fields[field].Convert(val))
+ val = def;
+}
+
+void PokeGen::PokeMod::Ini::GetValue(const String &field, char &val, const char def)
+{
+ if (!fields.count(field))
+ {
+ val = def;
+ return;
+ }
+ if (!fields[field].Convert(val))
+ val = def;
+}
+
+void PokeGen::PokeMod::Ini::GetValue(const String &field, unsigned char &val, const unsigned char def)
+{
+ if (!fields.count(field))
+ {
+ val = def;
+ return;
+ }
+ if (!fields[field].Convert(val))
+ val = def;
+}
+
void PokeGen::PokeMod::Ini::GetValue(const String &field, int &val, const int def)
{
if (!fields.count(field))
@@ -94,10 +127,8 @@ void PokeGen::PokeMod::Ini::GetValue(const String &field, int &val, const int de
val = def;
return;
}
- long temp;
- char *end;
- temp = std::strtol(fields[field], &end, 10);
- val = ((temp < INT_MIN) || (INT_MAX < temp) || *end) ? def : temp;
+ if (!fields[field].Convert(val))
+ val = def;
}
void PokeGen::PokeMod::Ini::GetValue(const String &field, unsigned &val, const unsigned def)
@@ -107,25 +138,43 @@ void PokeGen::PokeMod::Ini::GetValue(const String &field, unsigned &val, const u
val = def;
return;
}
- unsigned long temp;
- char *end;
- temp = std::strtoul(fields[field], &end, 10);
- val = ((UINT_MAX < temp) || *end) ? def : temp;
-}
-
-void PokeGen::PokeMod::Ini::GetValue(const String &field, unsigned char &val, const unsigned char def)
-{
- if (!fields.count(field))
- {
- val = def;
- return;
- }
- unsigned long temp;
- char *end;
- temp = std::strtoul(fields[field], &end, 10);
- val = ((UCHAR_MAX < temp) || *end) ? def : temp;
-}
-
+ if (!fields[field].Convert(val))
+ val = def;
+}
+
+void PokeGen::PokeMod::Ini::GetValue(const String &field, long &val, const long def)
+{
+ if (!fields.count(field))
+ {
+ val = def;
+ return;
+ }
+ if (!fields[field].Convert(val))
+ val = def;
+}
+
+void PokeGen::PokeMod::Ini::GetValue(const String &field, unsigned long &val, const unsigned long def)
+{
+ if (!fields.count(field))
+ {
+ val = def;
+ return;
+ }
+ if (!fields[field].Convert(val))
+ val = def;
+}
+
+void PokeGen::PokeMod::Ini::GetValue(const String &field, double &val, const double def)
+{
+ if (!fields.count(field))
+ {
+ val = def;
+ return;
+ }
+ if (!fields[field].Convert(val))
+ val = def;
+}
+
void PokeGen::PokeMod::Ini::GetValue(const String &field, String &val, const String &def)
{
if (!fields.count(field))
@@ -136,34 +185,6 @@ void PokeGen::PokeMod::Ini::GetValue(const String &field, String &val, const Str
val = fields[field];
}
-void PokeGen::PokeMod::Ini::GetValue(const String &field, bool &val, const bool def)
-{
- if (!fields.count(field))
- {
- val = def;
- return;
- }
- if (fields[field] == "true")
- val = true;
- else if (fields[field] == "false")
- val = false;
- else
- val = def;
-}
-
-void PokeGen::PokeMod::Ini::GetValue(const String &field, double &val, const double def)
-{
- if (!fields.count(field))
- {
- val = def;
- return;
- }
- char *end;
- val = std::strtod(fields[field].c_str(), &end);
- if (*end)
- val = def;
-}
-
bool PokeGen::PokeMod::Ini::IsValid() const
{
return isValid;
@@ -175,7 +196,7 @@ bool PokeGen::PokeMod::Ini::Load(std::ifstream &file)
std::string field;
std::string value;
fields.clear();
- unsigned pos;
+ size_t pos;
name = "";
isValid = true;
std::getline(file, line);