summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-02-23 06:58:42 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-02-23 06:58:42 +0000
commitda42e77ec57e3ecf0ecc2e1b8fe8b21a50ac58cd (patch)
tree5098a835087cf1c81cf4d81d4d444703e1253c6e
parentd7bc310363c98994457e7882e7010e276169f00a (diff)
downloadsigen-da42e77ec57e3ecf0ecc2e1b8fe8b21a50ac58cd.tar.gz
sigen-da42e77ec57e3ecf0ecc2e1b8fe8b21a50ac58cd.tar.xz
sigen-da42e77ec57e3ecf0ecc2e1b8fe8b21a50ac58cd.zip
[FIX] Matrix edge cases around 0 x 0 dimension
[FIX] Build order in pokegen.pro git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@73 6ecfd1a5-f3ed-3746-8530-beee90d26b22
-rw-r--r--Changelog8
-rw-r--r--general/Matrix.h94
-rwxr-xr-xpokegen.pro16
-rw-r--r--pokemodr/PokeModrUI.cpp12
4 files changed, 67 insertions, 63 deletions
diff --git a/Changelog b/Changelog
index b890ed4c..a152792e 100644
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,12 @@
-----------------
+Rev: 73
+Date: 23 February 2008
+User: MathStuf
+-----------------
+[FIX] Matrix edge cases around 0 x 0 dimension
+[FIX] Build order in pokegen.pro
+
+-----------------
Rev: 72
Date: 22 February 2008
User: MathStuf
diff --git a/general/Matrix.h b/general/Matrix.h
index 26f9d703..f1613c09 100644
--- a/general/Matrix.h
+++ b/general/Matrix.h
@@ -28,7 +28,7 @@
#include <QVector>
#include <QVectorIterator>
-#include "Ini.h"
+#include "Exception.h"
template<class T> class Matrix
{
@@ -43,6 +43,13 @@ template<class T> class Matrix
height(h),
matrix(h, QVector<T>(w, d))
{
+ if (!width ^ !height)
+ {
+ if (width)
+ addRow(d);
+ if (height)
+ addCol(d);
+ }
}
Matrix(const Matrix<T>& rhs) :
width(rhs.getWidth()),
@@ -56,87 +63,70 @@ template<class T> class Matrix
}
}
- void load(const QString& fname)
- {
- Ini ini(fname);
- ini.getValue("width", width, 0);
- ini.getValue("height", height, 0);
- if (!(width && height))
- return;
- matrix.resize(width, QVector<T>(height, 0));
- for (int i = 0; i < width; ++i)
- {
- for (int j = 0; j < height; ++j)
- {
- T k;
- ini.getValue(QString("Element-%1-%2").arg(i).arg(j), k, 0);
- matrix[i][j] = k;
- }
- }
- }
- void save(const QString& fname, const QString& val) const
- {
- Ini ini;
- ini.addField("height", height);
- ini.addField("width", width);
- for (int i = 0; i < width; ++i)
- {
- for (int j = 0; j < height; ++j)
- ini.addField(QString("Element-%1-%2").arg(i).arg(j), matrix[i][j]);
- }
- ini.save(fname);
- }
-
void addRow(const T& d = T())
{
+ width += !width;
matrix.append(QVector<T>(width, d));
++height;
}
void addCol(const T& d = T())
{
+ if (!height)
+ {
+ matrix.append(QVector<T>());
+ ++height;
+ }
for (QMutableVectorIterator< QVector<T> > i(matrix); i.hasNext(); )
i.next().append(d);
++width;
}
- void insertRow(const int pos, const T& d = T())
+ void insertRow(const int pos, const T& d = T()) throw(BoundsException)
{
if (height < pos)
- throw("Matrix: dimension out-of-bounds");
+ throw(BoundsException("Matrix", "dimension"));
+ width += !width;
matrix.insert(pos, QVector<T>(width, d));
++height;
}
- void insertCol(const int pos, const T& d = T())
+ void insertCol(const int pos, const T& d = T()) throw(BoundsException)
{
if (width < pos)
- throw("Matrix: dimension out-of-bounds");
+ throw(BoundsException("Matrix", "dimension"));
+ if (!height)
+ {
+ matrix.append(QVector<T>());
+ ++height;
+ }
for (QMutableVectorIterator< QVector<T> > i(matrix); i.hasNext(); )
i.next().insert(pos, d);
++width;
}
- void deleteRow(const int pos)
+ void deleteRow(const int pos) throw(BoundsException)
{
if (height <= pos)
- throw("Matrix: dimension out-of-bounds");
+ throw(BoundsException("Matrix", "dimension"));
matrix.remove(pos);
- --height;
+ if (!(--height))
+ width = 0;
}
- void deleteCol(const int pos)
+ void deleteCol(const int pos) throw(BoundsException)
{
if (width <= pos)
- throw("Matrix: dimension out-of-bounds");
+ throw(BoundsException("Matrix", "dimension"));
for (QMutableVectorIterator< QVector<T> > i(matrix); i.hasNext(); )
i.next().remove(pos);
- --width;
+ if (!(--width))
+ height = 0;
}
void clear()
{
matrix.clear();
}
- void set(const int row, const int col, const T& s)
+ void set(const int row, const int col, const T& s) throw(BoundsException)
{
if ((height <= row) || (width <= col))
- throw("Matrix: dimension out-of-bounds");
+ throw(BoundsException("Matrix", "dimension"));
(*this)(row, col) = s;
}
void resize(const int h, const int w, const T& d = T())
@@ -147,22 +137,22 @@ template<class T> class Matrix
matrix = QVector< QVector<T> >(h, QVector<T>(w, d));
}
- const T& at(const int row, const int col) const
+ const T& at(const int row, const int col) const throw(BoundsException)
{
if ((height <= row) || (width <= col))
- throw("Matrix: dimension out-of-bounds");
+ throw(BoundsException("Matrix", "dimension"));
return matrix.at(row).at(col);
}
- const QVector<T> getRow(const int row) const
+ const QVector<T> getRow(const int row) const throw(BoundsException)
{
if (height <= row)
- throw("Matrix: dimension out-of-bounds");
+ throw(BoundsException("Matrix", "dimension"));
return matrix.at(row);
}
- const QVector<T> getCol(const int col) const
+ const QVector<T> getCol(const int col) const throw(BoundsException)
{
if (width <= col)
- throw("Matrix: dimension out-of-bounds");
+ throw(BoundsException("Matrix", "dimension"));
QVector<T> c;
for (QVectorIterator< QVector<T> > i(matrix); i.hasNext(); )
c.append(i.next().at(col));
@@ -177,10 +167,10 @@ template<class T> class Matrix
return width;
}
- T& operator()(const int row, const int col)
+ T& operator()(const int row, const int col) throw(BoundsException)
{
if ((height <= row) || (width <= col))
- throw("Matrix: dimension out-of-bounds");
+ throw(BoundsException("Matrix", "dimension"));
return (matrix[row])[col];
}
const T& operator()(const int row, const int col) const
diff --git a/pokegen.pro b/pokegen.pro
index 2cb351dd..30a51857 100755
--- a/pokegen.pro
+++ b/pokegen.pro
@@ -2,14 +2,18 @@ VERSION = 0.0.1
TEMPLATE = subdirs
CONFIG += ordered qt warn_on
-SUBDIRS = battle general menus overworld pokegen pokemod pokemodr
-
distsrc.target = distsrc
-distsrc.commands = tar -c . | bzip2 --best -c > ../releases/pokegen-$${VERSION}.tar.bz2
+distsrc.commands = "tar -c . | bzip2 --best -c > ../releases/pokegen-$${VERSION}.tar.bz2"
rpm.target = rpm
-rpm.commands = rpmbuild -bt ../releases/pokegen-$${VERSION}.tar.bz2 \
- cp /usr/src/redhat/RPMS/$${ARCH}/pokegen-$${VERSION}.$${ARCH}.rpm ../pkg/
+rpm.commands = "rpmbuild -bt ../releases/pokegen-$${VERSION}.tar.bz2; cp /usr/src/redhat/RPMS/$${ARCH}/pokegen-$${VERSION}.$${ARCH}.rpm ../pkg/"
rpm.depends = distsrc
-QMAKE_EXTRA_UNIX_TARGETS += distsrc rpm
+QMAKE_EXTRA_UNIX_TARGETS += "distsrc rpm"
+SUBDIRS = general \
+ pokemod \
+ pokemodr \
+ menus \
+ overworld \
+ battle \
+ pokegen
diff --git a/pokemodr/PokeModrUI.cpp b/pokemodr/PokeModrUI.cpp
index cdc976ec..b36a17a6 100644
--- a/pokemodr/PokeModrUI.cpp
+++ b/pokemodr/PokeModrUI.cpp
@@ -43,6 +43,7 @@
#include "MapUI.h"
#include "MoveUI.h"
#include "NatureUI.h"
+#include "PokemodUI.h"
#include "RulesUI.h"
#include "SpeciesUI.h"
#include "SpeciesAbilityUI.h"
@@ -72,6 +73,10 @@ PokeModrUI::PokeModrUI(KConfigGroup cfg, KConfigGroup history, QWidget* parent)
// Testing
pokemod = new Pokemod();
+ pokemod->newTile()->setName("foo");
+ pokemod->newTile()->setName("bar");
+ pokemod->newTile()->setName("baz");
+// formPanel->setWidget(new PokemodUI(pokemod, formPanel));
// formPanel->setWidget(new AbilityUI(pokemod->newAbility(), formPanel));
// formPanel->setWidget(new AuthorUI(pokemod->newAuthor(), formPanel));
// formPanel->setWidget(new BadgeUI(pokemod->newBadge(), formPanel));
@@ -80,10 +85,7 @@ PokeModrUI::PokeModrUI(KConfigGroup cfg, KConfigGroup history, QWidget* parent)
// formPanel->setWidget(new EggGroupUI(pokemod->newEggGroup(), formPanel));
// formPanel->setWidget(new ItemUI(pokemod->newItem(), formPanel));
// formPanel->setWidget(new ItemTypeUI(pokemod->newItemType(), formPanel));
-// formPanel->setWidget(new MapUI(pokemod->newMap(), formPanel));
- pokemod->newItem()->setName("foo");
- pokemod->newItem()->setName("bar");
- pokemod->newItem()->setName("baz");
+ formPanel->setWidget(new MapUI(pokemod->newMap(), formPanel));
// formPanel->setWidget(new MoveUI(pokemod->newMove(), formPanel));
// formPanel->setWidget(new NatureUI(pokemod->newNature(), formPanel));
// formPanel->setWidget(new SpeciesUI(pokemod->newSpecies(), formPanel));
@@ -91,7 +93,7 @@ PokeModrUI::PokeModrUI(KConfigGroup cfg, KConfigGroup history, QWidget* parent)
// formPanel->setWidget(new SpeciesEvolutionUI(pokemod->newSpecies()->newEvolution(), formPanel));
// formPanel->setWidget(new SpeciesItemUI(pokemod->newSpecies()->newItem(), formPanel));
// formPanel->setWidget(new SpeciesMoveUI(pokemod->newSpecies()->newMove(), formPanel));
- formPanel->setWidget(new StoreUI(pokemod->newStore(), formPanel));
+// formPanel->setWidget(new StoreUI(pokemod->newStore(), formPanel));
// formPanel->setWidget(new RulesUI(pokemod->getRules(), formPanel));
// formPanel->setWidget(new TileUI(pokemod->newTile(), formPanel));
// formPanel->setWidget(new TimeUI(pokemod->newTime(), formPanel));