diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-05-19 03:27:00 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-05-19 03:27:00 +0000 |
| commit | e6bd0fad66fcce1a81d5b61ba6afd856d8f84d67 (patch) | |
| tree | 5a33febc4ec0f5efe270bed38f4c7c451694ead4 /general | |
| parent | c0634abfb225376249023faf524f5252f47f5090 (diff) | |
| download | sigen-e6bd0fad66fcce1a81d5b61ba6afd856d8f84d67.tar.gz sigen-e6bd0fad66fcce1a81d5b61ba6afd856d8f84d67.tar.xz sigen-e6bd0fad66fcce1a81d5b61ba6afd856d8f84d67.zip | |
[FIX] general is now merged into pokemod
[FIX] Added ItemEffect widget code
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@153 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'general')
| -rw-r--r-- | general/Flag.cpp | 58 | ||||
| -rw-r--r-- | general/Flag.h | 66 | ||||
| -rw-r--r-- | general/Fraction.cpp | 35 | ||||
| -rw-r--r-- | general/Fraction.h | 87 | ||||
| -rw-r--r-- | general/Hat.h | 90 | ||||
| -rw-r--r-- | general/Matrix.h | 210 | ||||
| -rw-r--r-- | general/Point.h | 78 | ||||
| -rw-r--r-- | general/TODO | 1 | ||||
| -rw-r--r-- | general/general.pro | 29 |
9 files changed, 0 insertions, 654 deletions
diff --git a/general/Flag.cpp b/general/Flag.cpp deleted file mode 100644 index e08ba9f0..00000000 --- a/general/Flag.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> - * - * 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/>. - */ - -// Header include -#include "Flag.h" - -const QStringList Flag::ValueStr = QStringList() << "Off" << "On" << "Ignore"; - -Flag::Flag(const int flag, const int status) : - m_flag(flag) -{ - setStatus(status); -} - -void Flag::set(const int flag, const int status) -{ - setFlag(flag); - setStatus(status); -} - -void Flag::setFlag(const int flag) -{ - m_flag = flag; -} - -void Flag::setStatus(const int status) -{ - if (End <= status) - { - m_status = Ignore; - return; - } - m_status = status; -} - -int Flag::flag() const -{ - return m_flag; -} - -int Flag::status() const -{ - return m_status; -} diff --git a/general/Flag.h b/general/Flag.h deleted file mode 100644 index 55b3a73d..00000000 --- a/general/Flag.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> - * - * 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 __FLAG__ -#define __FLAG__ - -// Qt includes -#include <QStringList> - -class Flag -{ - public: - enum - { - Off, - On, - Ignore, - End - }; - static const QStringList ValueStr; - - Flag(const int flag = 0, const int status = Off); - - void set(const int flag, const int status); - void setFlag(const int flag); - void setStatus(const int status); - - int flag() const; - int status() const; - - inline Flag& operator=(const Flag& rhs) - { - if (this == &rhs) - return *this; - m_flag = rhs.m_flag; - m_status = rhs.m_status; - return *this; - } - inline bool operator==(const Flag& rhs) const - { - return ((m_flag == rhs.m_flag) && (m_status == rhs.m_status)); - } - inline bool operator!=(const Flag& rhs) const - { - return !(*this == rhs); - } - private: - int m_flag; - int m_status; -}; - -#endif diff --git a/general/Fraction.cpp b/general/Fraction.cpp deleted file mode 100644 index a4a41e7d..00000000 --- a/general/Fraction.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> - * - * 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/>. - */ - -// Header include -#include "Fraction.h" - -void Fraction::set(const int numerator, const int denominator) -{ - m_numerator = numerator; - m_denominator = denominator; -} - -void Fraction::reduce() -{ - int i = m_numerator; - int j = m_denominator; - while (i - j) - (i > j) ? (i -= j) : (j -= i); - m_numerator /= i; - m_denominator /= i; -} diff --git a/general/Fraction.h b/general/Fraction.h deleted file mode 100644 index 2c1dc663..00000000 --- a/general/Fraction.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> - * - * 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 __FRAC__ -#define __FRAC__ - -// Qt includes -#include <QMetaType> - -class Fraction -{ - public: - inline Fraction() - { - set(1, 1); - } - inline Fraction(const int numerator, const int denominator) - { - set(numerator, denominator); - } - - void set(const int numerator, const int denominator); - inline void setNumerator(const int numerator) - { - set(numerator, m_denominator); - } - inline void setDenominator(const int denominator) - { - set(m_numerator, denominator); - } - - inline int numerator() const - { - return m_numerator; - } - inline int denominator() const - { - return m_denominator; - } - - void reduce(); - - inline operator double() const - { - return (double(m_numerator) / m_denominator); - } - inline Fraction operator*(const Fraction& rhs) const - { - return Fraction(m_numerator * rhs.m_numerator, m_denominator * rhs.m_denominator); - } - inline Fraction& operator=(const Fraction& rhs) - { - if (this == &rhs) - return *this; - m_numerator = rhs.m_numerator; - m_denominator = rhs.m_denominator; - return *this; - } - inline bool operator==(const Fraction& rhs) const - { - return ((m_numerator == rhs.m_numerator) && (m_denominator == rhs.m_denominator)); - } - inline bool operator!=(const Fraction& rhs) const - { - return !(*this == rhs); - } - private: - int m_numerator; - int m_denominator; -}; -Q_DECLARE_METATYPE(Fraction) - -#endif diff --git a/general/Hat.h b/general/Hat.h deleted file mode 100644 index 2b7fccea..00000000 --- a/general/Hat.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> - * - * 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 __HAT__ -#define __HAT__ - -// Qt includes -#include <QtGlobal> -#include <QDateTime> -#include <QMap> - -template<class T> class Hat -{ - public: - Hat() : - m_count(0) - { - qsrand(QDateTime().toTime_t()); - } - - T pick() const - { - int choice = qrand() % m_count; - foreach (T key, m_objects.keys()) - { - choice -= m_objects[key]; - if (choice < 0) - break; - } - return key; - } - T take() - { - T chosen = pick(); - if (!(--m_objects[chosen])) - m_objects.erase(chosen); - --m_count; - return chosen; - } - void setCount(const T& key, const unsigned weight) - { - if (m_objects.contains(key)) - m_count -= m_objects[key]; - m_objects[key] = weight; - m_count += weight; - } - void add(const T& key, const unsigned weight) - { - m_objects[key] += weight; - m_count += weight; - } - unsigned count() const - { - return m_count; - } - unsigned count(const T& key) const - { - if (m_objects.contains(key)) - return m_objects[key]; - return 0; - } - double chance(const T& key) const - { - return (double(count(key)) / m_count); - } - - unsigned operator[](const T& key) const - { - return count(key); - } - private: - QMap<T, unsigned> m_objects; - unsigned m_count; -}; - -#endif diff --git a/general/Matrix.h b/general/Matrix.h deleted file mode 100644 index 8d714f9d..00000000 --- a/general/Matrix.h +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> - * - * 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 __MATRIX__ -#define __MATRIX__ - -// General includes -#include "Point.h" - -// Qt includes -#include <QVector> - -template<class T> class Matrix -{ - public: - Matrix() : - m_width(0), - m_height(0) - { - } - Matrix(const int height, const int width, const T& value = T()) - { - resize(height, width, value); - } - Matrix(const Matrix<T>& rhs) - { - *this = rhs; - } - - void addRow(const T& value = T()) - { - m_width += !m_width; - m_matrix.append(QVector<T>(m_width, value)); - ++m_height; - } - void addColumn(const T& value = T()) - { - if (!m_height) - { - m_matrix.append(QVector<T>(1)); - ++m_height; - } - foreach (QVector<T> row, m_matrix) - row.append(value); - ++m_width; - } - void insertRow(const int row, const T& value = T()) - { - if (m_height < row) - return; - m_width += !m_width; - m_matrix.insert(row, QVector<T>(m_width, value)); - ++m_height; - } - void insertColumn(const int column, const T& value = T()) - { - if (m_width < column) - return; - if (!m_height) - { - m_matrix.append(QVector<T>(1)); - ++m_height; - } - foreach (QVector<T> row, m_matrix) - row.insert(column, value); - ++m_width; - } - void deleteRow(const int row) - { - if (m_height <= row) - return; - m_matrix.remove(row); - if (!(--m_height)) - m_width = 0; - } - void deleteColumn(const int column) - { - if (m_width <= column) - return; - foreach (QVector<T> row, m_matrix) - row.remove(column); - if (!(--m_width)) - m_height = 0; - } - void clear() - { - m_width = 0; - m_height = 0; - m_matrix.clear(); - } - - void set(const int row, const int column, const T& value) - { - if ((m_height <= row) || (m_width <= column)) - return; - (m_matrix[row])[column] = value; - } - void resize(const int height, const int width, const T& value = T()) - { - clear(); - m_width = width; - m_height = height; - if (!m_width ^ !m_height) - { - if (m_width) - ++m_height; - if (m_height) - ++m_width; - } - m_matrix = QVector< QVector<T> >(m_height, QVector<T>(m_width, value)); - } - - T at(const int row, const int column) const - { - if ((m_height <= row) || (m_width <= column)) - return T(); - return m_matrix.at(row).at(column); - } - QVector<T> row(const int row) const - { - if (height <= row) - return QVector<T>(); - return m_matrix.at(row); - } - QVector<T> column(const int column) const - { - if (m_width <= column) - return QVector<T>(); - QVector<T> col; - foreach (QVector<T> row, m_matrix) - col.append(row.at(column)); - return col; - } - int height() const - { - return m_height; - } - int width() const - { - return m_width; - } - Point size() const - { - return Point(m_width, m_height); - } - - T& operator()(const int row, const int column) - { - // FIXME: compile error if used :( - if ((m_height <= row) || (m_width <= column)) - return T(); - return m_matrix[row][column]; - } - T operator()(const int row, const int column) const - { - return at(row, column); - } - Matrix<T>& operator=(const Matrix<T>& rhs) - { - if (this == &rhs) - return *this; - resize(rhs.m_height, rhs.m_width); - for (int i = 0; i < m_height; ++i) - { - for (int j = 0; j < m_width; ++j) - m_matrix[i][j] = rhs.m_matrix[i][j]; - } - return *this; - } - bool operator==(const Matrix<T>& rhs) const - { - if (this == &rhs) - return true; - if ((m_height != rhs.m_height) || (m_width == rhs.m_width)) - return false; - for (int i = 0; i < m_height; ++i) - { - for (int j = 0; j < m_width; ++j) - { - if (m_matrix[i][j] != rhs.m_matrix[i][j]) - return false; - } - } - return true; - } - bool operator!=(const Matrix<T>& rhs) const - { - return !(*this == rhs); - } - protected: - int m_width; - int m_height; - QVector< QVector<T> > m_matrix; -}; - -#endif diff --git a/general/Point.h b/general/Point.h deleted file mode 100644 index 0525f85b..00000000 --- a/general/Point.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> - * - * 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 __POINT__ -#define __POINT__ - -class Point -{ - public: - inline Point(const int x = 0, const int y = 0) : - m_x(x), - m_y(y) - { - } - inline Point(const Point& rhs) - { - *this = rhs; - } - - inline void set(const int x, const int y) - { - m_x = x; - m_y = y; - } - inline void setX(const int x) - { - m_x = x; - } - inline void setY(const int y) - { - m_y = y; - } - - inline int x() const - { - return m_x; - } - inline int y() const - { - return m_y; - } - - Point& operator=(const Point& rhs) - { - if (this == &rhs) - return *this; - m_x = rhs.m_x; - m_y = rhs.m_y; - return *this; - } - inline bool operator==(const Point& rhs) const - { - return ((m_x == rhs.m_x) && (m_y == rhs.m_y)); - } - inline bool operator!=(const Point& rhs) const - { - return !(*this == rhs); - } - private: - int m_x; - int m_y; -}; - -#endif diff --git a/general/TODO b/general/TODO deleted file mode 100644 index ccc403c1..00000000 --- a/general/TODO +++ /dev/null @@ -1 +0,0 @@ -FlagWidget diff --git a/general/general.pro b/general/general.pro deleted file mode 100644 index 71c61d60..00000000 --- a/general/general.pro +++ /dev/null @@ -1,29 +0,0 @@ -include(../version.pro) -TEMPLATE = lib -OBJECTS_DIR = .obj -DESTDIR = ../bin - -CONFIG += qt \ - warn_on \ - dll -!win32 { - CONFIG += debug -} - -SOURCES += Flag.cpp \ - Fraction.cpp - -HEADERS += Flag.h \ - Fraction.h \ - Hat.h \ - Matrix.h \ - Point.h - -isEmpty(PREFIX) { - PREFIX = $$(PREFIX) -} -isEmpty(PREFIX) { - PREFIX = /usr -} -target.path = $$PREFIX/lib$$system(kde4-config --libsuffix) -INSTALLS += target |
