diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2007-07-21 01:39:22 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2007-07-21 01:39:22 +0000 |
| commit | e94d9893b8753e72adb92b2c5eb203830ddf641c (patch) | |
| tree | fe283d6ede1cfe1a1613742811fb5b34fb8db68c /pokemod/Frac.cpp | |
| parent | 65cc463f1d91fe99acf1c4dd9bce7e0038593022 (diff) | |
| download | sigen-e94d9893b8753e72adb92b2c5eb203830ddf641c.tar.gz sigen-e94d9893b8753e72adb92b2c5eb203830ddf641c.tar.xz sigen-e94d9893b8753e72adb92b2c5eb203830ddf641c.zip | |
Moved to GPLv3 and Qt4, Changed String -> QString, other minor fixes
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@23 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Frac.cpp')
| -rw-r--r-- | pokemod/Frac.cpp | 81 |
1 files changed, 39 insertions, 42 deletions
diff --git a/pokemod/Frac.cpp b/pokemod/Frac.cpp index d252d416..36a131c0 100644 --- a/pokemod/Frac.cpp +++ b/pokemod/Frac.cpp @@ -6,133 +6,130 @@ // Created: Sun Mar 18 15:25:16 2007
// Copyright: ©2007 Nerdy Productions
// Licence:
-// This program is free software; you can redistribute it and/or modify
+// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
+// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
-//
+//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-//
+//
// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+// with this program. If not, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////
#include "Frac.h"
-PokeGen::PokeMod::Frac::Frac(const bool i) :
+PokeGen::PokeMod::Frac::Frac(const unsigned t) :
num(1),
denom(1),
- improper(i)
+ type((t < FR_END) ? t : FR_PROPER)
{
Log::Write("Frac: Initializing", PM_DEBUG_DEBUG);
}
-PokeGen::PokeMod::Frac::Frac(const unsigned n, const unsigned d, const bool i)
+PokeGen::PokeMod::Frac::Frac(const unsigned n, const unsigned d, const unsigned t)
{
- Log::Write(String("Frac: Initializing as %u/%u (%u)", n, d, i), PM_DEBUG_DEBUG);
- Set(n, d, i);
+ Log::Write(QString("Frac: Initializing as %1/%2 (%3)").arg(n).arg(d).arg(t), PM_DEBUG_DEBUG);
+ Set(n, d, t);
}
void PokeGen::PokeMod::Frac::ImportIni(Ini &ini)
{
LogImportStart("Frac");
- ini.GetValue("improper", improper, false);
+ ini.GetValue("type", type, FR_PROPER);
ini.GetValue("num", num, 1);
ini.GetValue("denom", denom, 1);
- Log::Write(String("Frac Import: Imported %u/%u", num, denom), PM_DEBUG_INFO);
+ Log::Write(QString("Frac Import: Imported %1/%2").arg(num).arg(denom), PM_DEBUG_INFO);
}
-void PokeGen::PokeMod::Frac::ExportIni(std::ofstream &fout, const String &val)
+void PokeGen::PokeMod::Frac::ExportIni(QFile &fout, const QString &val)
{
- Log::Write(String("Frac Export: Starting %u/%u as %s", num, denom, val.c_str()), PM_DEBUG_INFO);
+ Log::Write(QString("Frac Export: Starting %1/%2 as %3").arg(num).arg(denom).arg(val), PM_DEBUG_INFO);
Reduce();
Ini exFrac(val);
exFrac.AddField("num", num);
exFrac.AddField("denom", denom);
- exFrac.AddField("improper", improper);
+ exFrac.AddField("type", type);
exFrac.Export(fout);
- Log::Write(String("Frac Export: Finished %u/%u as %s", num, denom, val.c_str()), PM_DEBUG_INFO);
+ Log::Write(QString("Frac Export: Finished %1/%2 as %3").arg(num).arg(denom).arg(val), PM_DEBUG_INFO);
}
void PokeGen::PokeMod::Frac::Set(const unsigned n, const unsigned d)
{
- Log::Write(String("Frac: Setting to %u/%u", n, d), PM_DEBUG_DEBUG);
+ Log::Write(QString("Frac: Setting to %1/%2").arg(n).arg(d), PM_DEBUG_DEBUG);
SetDenom(d);
SetNum(n);
Reduce();
}
-void PokeGen::PokeMod::Frac::Set(const unsigned n, const unsigned d, const bool i)
+void PokeGen::PokeMod::Frac::Set(const unsigned n, const unsigned d, const unsigned t)
{
- SetImproper(i);
+ SetType(t);
Set(n, d);
}
void PokeGen::PokeMod::Frac::SetNum(const unsigned n)
{
- if ((n <= denom) || improper)
+ if ((type == FR_IMPROPER) || ((n <= denom) && (type == FR_PROPER)) || ((denom <= n) && (type == FR_OVER1)))
{
- Log::Write(String("Frac: Setting numerator to %u (%u/%u)", n, n, denom), PM_DEBUG_DEBUG);
+ LogSetVar("Frac", 0, "numerator", n);
num = n;
}
- else
- Log::Write(String("Frac: Setting tried to set numerator to %u when denominator is %u", n, denom), PM_DEBUG_DEBUG);
}
void PokeGen::PokeMod::Frac::SetDenom(const unsigned d)
{
if (d)
{
- Log::Write(String("Frac: Setting denominator to %u", d), PM_DEBUG_DEBUG);
+ LogSetVar("Frac", 0, "denominator", d);
denom = d;
}
else
Log::Write("Frac: Attempting to set denominator to 0", PM_DEBUG_DEBUG);
- if ((num <= denom) && !improper)
- {
- Log::Write(String("Frac: Setting numerator to 1 after denominator reset to (%u)", d), PM_DEBUG_DEBUG);
- num = denom % num;
- }
+ if (((d <= num) && (type == FR_PROPER)) || ((num <= d) && (type == FR_OVER1)))
+ SetNum(d);
}
-void PokeGen::PokeMod::Frac::SetImproper(const bool i)
+void PokeGen::PokeMod::Frac::SetType(const unsigned t)
{
- Log::Write(String("Frac: Setting as %s", i ? "improper" : "proper"), PM_DEBUG_DEBUG);
- improper = i;
- Set(num, denom);
+ if (t < FR_END)
+ {
+ LogSetVar("Frac", 0, "type", t);
+ type = t;
+ Set(num, denom);
+ }
}
unsigned PokeGen::PokeMod::Frac::GetNum() const
{
- Log::Write(String("Frac: Fetching the numerator (%u)", num), PM_DEBUG_DEBUG);
+ LogFetchVar("Frac", 0, "numerator", num);
return num;
}
unsigned PokeGen::PokeMod::Frac::GetDenom() const
{
- Log::Write(String("Frac: Fetching the denominator (%u)", denom), PM_DEBUG_DEBUG);
+ LogFetchVar("Frac", 0, "denominator", denom);
return denom;
}
-bool PokeGen::PokeMod::Frac::GetImproper() const
+unsigned PokeGen::PokeMod::Frac::GetType() const
{
- Log::Write(String("Frac: Fetching improper (%u)", improper), PM_DEBUG_DEBUG);
- return improper;
+ LogFetchVar("Frac", 0, "type", type);
+ return type;
}
float PokeGen::PokeMod::Frac::GetValue() const
{
- Log::Write(String("Frac: Fetching the value (%f)", num / denom), PM_DEBUG_DEBUG);
+ Log::Write(QString("Frac: Fetching the value (%1)").arg(num / denom), PM_DEBUG_DEBUG);
return (num / denom);
}
void PokeGen::PokeMod::Frac::Reduce()
{
- Log::Write(String("Frac: Reducing %u/%u", num, denom), PM_DEBUG_DEBUG);
+ Log::Write(QString("Frac: Reducing %1/%2").arg(num).arg(denom), PM_DEBUG_DEBUG);
for (unsigned i = 2; i <= (num < denom ? num : denom); ++i)
{
while (!((num % i) || (denom % i)))
@@ -141,7 +138,7 @@ void PokeGen::PokeMod::Frac::Reduce() denom /= i;
}
}
- Log::Write(String("Frac: Reduced to %u/%u", num, denom), PM_DEBUG_DEBUG);
+ Log::Write(QString("Frac: Reduced to %1/%2").arg(num).arg(denom), PM_DEBUG_DEBUG);
}
PokeGen::PokeMod::Frac::operator float() const
|
