summaryrefslogtreecommitdiffstats
path: root/general
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-01-18 06:00:44 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-01-18 06:00:44 +0000
commitd017d90324a439dfb4bd3f25d30deb672bc40fd4 (patch)
tree7ba12ff6ec958caa0f02f5e049cb4b0d38b1e74e /general
parent1d639b92a4487b21a29127f4fbe91d5b1d5d1952 (diff)
[FIX] Added 2008 to other copyright lines
[ADD] More .pro files for qmake [ADD] overworld folder for the world map stuff [ADD] Refined pokegen and pokemodr file structures git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@32 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'general')
-rw-r--r--general/Exception.h128
-rw-r--r--general/Flag.cpp2
-rw-r--r--general/Flag.h2
-rw-r--r--general/Frac.cpp16
-rw-r--r--general/Frac.h13
-rw-r--r--general/FracMatrix.h2
-rw-r--r--general/Hat.h8
-rw-r--r--general/ImageCache.cpp33
-rw-r--r--general/ImageCache.h40
-rw-r--r--general/Ini.cpp18
-rw-r--r--general/Ini.h9
-rw-r--r--general/Matrix.h10
-rw-r--r--general/Point.h2
-rw-r--r--general/Ref.cpp2
-rw-r--r--general/Ref.h2
15 files changed, 247 insertions, 40 deletions
diff --git a/general/Exception.h b/general/Exception.h
new file mode 100644
index 00000000..53a7ab4b
--- /dev/null
+++ b/general/Exception.h
@@ -0,0 +1,128 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: general/Exception.h
+// Purpose: Define exceptions used throughout PokéGen
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Wed Jan 16 13:13:13 2008
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
+// Licence:
+// 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 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, see <http://www.gnu.org/licenses/>.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __EXCEPTIONS__
+#define __EXCEPTIONS__
+
+namespace PokeGen
+{
+ class Exception
+ {
+ public:
+ Exception(const QString& c, const QString e) :
+ cls(c),
+ error(e)
+ {
+ }
+
+ QString getMsg() const
+ {
+ return QString("%1: %2").arg(cls).arg(error);
+ }
+ private:
+ QString cls;
+ QString error;
+ };
+
+ class UnusedException : public Exception
+ {
+ public:
+ UnusedException(const QString& c, const QString& var) :
+ Exception(c, QString("setting unused %1").arg(var))
+ {
+ }
+ };
+
+ class BoundsException : public Exception
+ {
+ public:
+ BoundsException(const QString& c, const QString& var) :
+ Exception(c, QString("%1 out-of-bounds").arg(var))
+ {
+ }
+ };
+
+ class IndexException : public BoundsException
+ {
+ public:
+ IndexException(const QString& c) :
+ BoundsException(c, "index")
+ {
+ }
+ };
+
+ class ReplaceException : public Exception
+ {
+ public:
+ ReplaceException(const QString& c, const QString& f) :
+ Exception(c, QString("unable to replace %1").arg(f))
+ {
+ }
+ };
+
+ class SaveException : public Exception
+ {
+ public:
+ SaveException(const QString& c, const QString& f) :
+ Exception(c, QString("unable to save %1").arg(f))
+ {
+ }
+ };
+
+ class OpenException : public Exception
+ {
+ public:
+ OpenException(const QString& c, const QString& f) :
+ Exception(c, QString("unable to open %1").arg(f))
+ {
+ }
+ };
+
+ class DirException : public Exception
+ {
+ public:
+ DirException(const QString& c, const QString& p) :
+ Exception(c, QString("unable to create path %1").arg(p))
+ {
+ }
+ };
+
+ class InvalidException : public Exception
+ {
+ public:
+ InvalidException(const QString& c, const QString& f) :
+ Exception(c, QString("%1 is invalid").arg(f))
+ {
+ }
+ };
+
+ class RemoveException : public Exception
+ {
+ public:
+ RemoveException(const QString& c, const QString& f) :
+ Exception(c, QString("unable to remove %1").arg(f))
+ {
+ }
+ };
+}
+
+#endif
diff --git a/general/Flag.cpp b/general/Flag.cpp
index f54ca329..8dc6026e 100644
--- a/general/Flag.cpp
+++ b/general/Flag.cpp
@@ -4,7 +4,7 @@
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Sun Mar 18 15:25:16 2007
-// Copyright: ©2007 Nerdy Productions
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
// 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
diff --git a/general/Flag.h b/general/Flag.h
index e236c6df..3862ad3b 100644
--- a/general/Flag.h
+++ b/general/Flag.h
@@ -4,7 +4,7 @@
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Tue Mar 20 19:22 2007
-// Copyright: ©2007 Nerdy Productions
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
// 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
diff --git a/general/Frac.cpp b/general/Frac.cpp
index 74d76881..539205ef 100644
--- a/general/Frac.cpp
+++ b/general/Frac.cpp
@@ -4,7 +4,7 @@
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Sun Mar 18 15:25:16 2007
-// Copyright: ©2007 Nerdy Productions
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
// 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
@@ -22,7 +22,7 @@
#include "Frac.h"
-void PokeGen::Frac::set(const unsigned n, const unsigned d)
+void PokeGen::Frac::set(const unsigned n, const unsigned d) throw(Exception)
{
if ((type == Improper) || ((n < d) && (type == Proper)) || ((d < n) && (type == Over1)))
{
@@ -30,26 +30,26 @@ void PokeGen::Frac::set(const unsigned n, const unsigned d)
denom = d;
}
else
- throw("Frac: values conflict with type");
+ throw(Exception("Frac", "values conflict with type"));
}
-void PokeGen::Frac::set(const unsigned n, const unsigned d, const unsigned t)
+void PokeGen::Frac::set(const unsigned n, const unsigned d, const unsigned t) throw(Exception)
{
setType(t);
set(n, d);
}
-void PokeGen::Frac::setNum(const unsigned n)
+void PokeGen::Frac::setNum(const unsigned n) throw(Exception)
{
set(n, denom);
}
-void PokeGen::Frac::setDenom(const unsigned d)
+void PokeGen::Frac::setDenom(const unsigned d) throw(Exception)
{
set(num, d);
}
-void PokeGen::Frac::setType(const unsigned t)
+void PokeGen::Frac::setType(const unsigned t) throw(BoundsException)
{
if (t < End)
{
@@ -57,7 +57,7 @@ void PokeGen::Frac::setType(const unsigned t)
set(1, 1);
}
else
- throw("Frac: type out of range");
+ throw(BoundsException("Frac", "type"));
}
void PokeGen::Frac::reduce()
diff --git a/general/Frac.h b/general/Frac.h
index 15d2e8e1..7be576c6 100644
--- a/general/Frac.h
+++ b/general/Frac.h
@@ -4,7 +4,7 @@
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Sun Mar 18 15:25:16 2007
-// Copyright: ©2007 Nerdy Productions
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
// 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
@@ -25,6 +25,7 @@
#include <QFile>
#include <QString>
+#include "Exception.h"
namespace PokeGen
{
@@ -48,11 +49,11 @@ namespace PokeGen
set(n, d, t);
}
- void set(const unsigned n, const unsigned d);
- void set(const unsigned n, const unsigned d, const unsigned t);
- void setNum(const unsigned n);
- void setDenom(const unsigned d);
- void setType(const unsigned t);
+ void set(const unsigned n, const unsigned d) throw(Exception);
+ void set(const unsigned n, const unsigned d, const unsigned t) throw(Exception);
+ void setNum(const unsigned n) throw(Exception);
+ void setDenom(const unsigned d) throw(Exception);
+ void setType(const unsigned t) throw(BoundsException);
unsigned getNum() const
{
diff --git a/general/FracMatrix.h b/general/FracMatrix.h
index f914b189..3becd3dc 100644
--- a/general/FracMatrix.h
+++ b/general/FracMatrix.h
@@ -4,7 +4,7 @@
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Fri Oct 19 12:52:16 2007
-// Copyright: ©2007 Nerdy Productions
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
// 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
diff --git a/general/Hat.h b/general/Hat.h
index 62ceac48..a6e892e0 100644
--- a/general/Hat.h
+++ b/general/Hat.h
@@ -4,7 +4,7 @@
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Tue May 29 2007 08:23:57
-// Copyright: ©2007 Nerdy Productions
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
// 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
@@ -20,8 +20,8 @@
// with this program. If not, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////
-#ifndef __POKEMOD_HAT__
-#define __POKEMOD_HAT__
+#ifndef __HAT__
+#define __HAT__
#include <QMap>
#include <cstdlib>
@@ -50,7 +50,7 @@ namespace PokeGen
}
T remove()
{
- T chosen = PickItem();
+ T chosen = pick();
if (!(--objects[chosen]))
objects.erase(chosen);
--totalWeight;
diff --git a/general/ImageCache.cpp b/general/ImageCache.cpp
new file mode 100644
index 00000000..c02342ae
--- /dev/null
+++ b/general/ImageCache.cpp
@@ -0,0 +1,33 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: general/ImageCache.h
+// Purpose: Cache for quick image loading
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Thu Jan 17 2008 13:42:44
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
+// Licence:
+// 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 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, see <http://www.gnu.org/licenses/>.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "ImageCache.h"
+
+QPixmap PokeGen::ImageCache::open(const QString& fname, const bool force) throw(OpenException)
+{
+ QPixmap pm;
+ if (force)
+ QPixmapCache::remove(fname);
+ if (!QPixmapCache::find(fname, pm))
+ throw(OpenException("ImageCache", fname));
+ return pm;
+}
diff --git a/general/ImageCache.h b/general/ImageCache.h
new file mode 100644
index 00000000..097d099c
--- /dev/null
+++ b/general/ImageCache.h
@@ -0,0 +1,40 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name: general/ImageCache.h
+// Purpose: Cache for quick image loading
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Thu Jan 17 2008 12:35:22
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
+// Licence:
+// 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 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, see <http://www.gnu.org/licenses/>.
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __IMAGECACHE__
+#define __IMAGECACHE__
+
+#include <QPixmap>
+#include <QPixmapCache>
+#include <QString>
+#include "Exception.h"
+
+namespace PokeGen
+{
+ class ImageCache
+ {
+ public:
+ static QPixmap open(const QString& fname, const bool force = false) throw(OpenException);
+ };
+}
+
+#endif
diff --git a/general/Ini.cpp b/general/Ini.cpp
index 5748a206..df2b74a0 100644
--- a/general/Ini.cpp
+++ b/general/Ini.cpp
@@ -4,7 +4,7 @@
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Fri May 4 23:27:37 2007
-// Copyright: ©2007 Nerdy Productions
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
// 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
@@ -27,16 +27,16 @@ PokeGen::Ini::Ini(const QString& fname)
load(fname);
}
-void PokeGen::Ini::load(const QString& fname)
+void PokeGen::Ini::load(const QString& fname) throw(Exception)
{
QFile fin(fname);
if (!fin.exists())
- throw("Ini: file does not exist");
+ throw(OpenException("Ini", fname));
load(fin);
fin.close();
}
-void PokeGen::Ini::load(QFile& fin)
+void PokeGen::Ini::load(QFile& fin) throw(InvalidException)
{
QTextStream file(&fin);
QString line = file.readLine();
@@ -48,25 +48,25 @@ void PokeGen::Ini::load(QFile& fin)
{
pos = line.indexOf('=');
if (pos == -1)
- throw("Ini: invalid file");
+ throw(InvalidException("Ini", fin.fileName()));
field = line.mid(0, pos - 1);
value = line.mid(pos + 1, line.length() - pos);
if (field.isEmpty())
- throw("Ini: invalid line");
+ throw(InvalidException("Ini", fin.fileName()));
fields[field] = value;
line = file.readLine();
}
}
-void PokeGen::Ini::save(const QString& fname) const
+void PokeGen::Ini::save(const QString& fname) const throw(Exception)
{
QStringList path = fname.split(QDir::separator(), QString::SkipEmptyParts);
path.removeLast();
if (!QDir().mkpath(path.join("/")))
- throw("Ini: unable to create path");
+ throw(DirException("Ini", path.join("/")));
QFile fout(fname);
if (!fout.open(QIODevice::WriteOnly))
- throw("Ini: unable to open file");
+ throw(OpenException("Ini", fname));
save(fout);
fout.close();
}
diff --git a/general/Ini.h b/general/Ini.h
index 963e6d1b..6cb441c7 100644
--- a/general/Ini.h
+++ b/general/Ini.h
@@ -4,7 +4,7 @@
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Fri May 4 23:27:37 2007
-// Copyright: ©2007 Nerdy Productions
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
// 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
@@ -29,6 +29,7 @@
#include <QString>
#include <QStringList>
#include <QTextStream>
+#include "Exception.h"
namespace PokeGen
{
@@ -38,8 +39,8 @@ namespace PokeGen
Ini();
Ini(const QString& fname);
- void load(const QString& fname);
- void save(const QString& fname) const;
+ void load(const QString& fname) throw(Exception);
+ void save(const QString& fname) const throw(Exception);
void addField(const QString& n, const bool v);
void addField(const QString& n, const unsigned char v);
@@ -64,7 +65,7 @@ namespace PokeGen
Value = 1
};
- void load(QFile& fin);
+ void load(QFile& fin) throw(InvalidException);
void save(QFile& fout) const;
QMap<QString, QString> fields;
diff --git a/general/Matrix.h b/general/Matrix.h
index bdeaa709..f4fd638e 100644
--- a/general/Matrix.h
+++ b/general/Matrix.h
@@ -4,7 +4,7 @@
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Sun Apr 8 12:51:20 2007
-// Copyright: ©2007 Nerdy Productions
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
// 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
@@ -153,13 +153,13 @@ namespace PokeGen
{
if ((height <= row) || (width <= col))
throw("Matrix: dimension out-of-bounds");
- return matrix[row][col];
+ return matrix.at(row).at(col);
}
const QVector<T> getRow(const unsigned row) const
{
if (height <= row)
throw("Matrix: dimension out-of-bounds");
- return matrix[row];
+ return matrix.at(row);
}
const QVector<T> getCol(const unsigned col) const
{
@@ -219,6 +219,10 @@ namespace PokeGen
}
return true;
}
+ bool operator!=(const Matrix<T>& rhs)
+ {
+ return !(*this == rhs);
+ }
protected:
unsigned width;
unsigned height;
diff --git a/general/Point.h b/general/Point.h
index 17c907e8..9143b491 100644
--- a/general/Point.h
+++ b/general/Point.h
@@ -4,7 +4,7 @@
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Sun Apr 8 12:53:15 2007
-// Copyright: ©2007 Nerdy Productions
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
// 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
diff --git a/general/Ref.cpp b/general/Ref.cpp
index 83432adb..e8ca482b 100644
--- a/general/Ref.cpp
+++ b/general/Ref.cpp
@@ -4,7 +4,7 @@
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Thu Feb 15 10:21:05 2007
-// Copyright: ©2007 Nerdy Productions
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
// 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
diff --git a/general/Ref.h b/general/Ref.h
index 46db4b4a..12508aed 100644
--- a/general/Ref.h
+++ b/general/Ref.h
@@ -4,7 +4,7 @@
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Thu Feb 15 8:42:45 2007
-// Copyright: ©2007 Nerdy Productions
+// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
// 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