summaryrefslogtreecommitdiffstats
path: root/sigcore
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-10-17 05:46:40 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-10-17 05:46:40 +0000
commitb3e1495f7a626bb4429ff5e4f3ad39ae9654f23b (patch)
tree8a188df964484e7dcf630e792dccfa1766c2f8f0 /sigcore
parent47428274a07bce9be5e62f82aeeb7e57aa21037f (diff)
downloadsigen-b3e1495f7a626bb4429ff5e4f3ad39ae9654f23b.tar.gz
sigen-b3e1495f7a626bb4429ff5e4f3ad39ae9654f23b.tar.xz
sigen-b3e1495f7a626bb4429ff5e4f3ad39ae9654f23b.zip
[FIX] Moved Hat, Fraction, Matrix, and Script to sigcore
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@281 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'sigcore')
-rw-r--r--sigcore/CMakeLists.txt51
-rw-r--r--sigcore/Fraction.cpp177
-rw-r--r--sigcore/Fraction.h131
-rw-r--r--sigcore/Global.h44
-rw-r--r--sigcore/Hat.h184
-rw-r--r--sigcore/Matrix.h348
-rw-r--r--sigcore/Script.cpp68
-rw-r--r--sigcore/Script.h94
8 files changed, 1097 insertions, 0 deletions
diff --git a/sigcore/CMakeLists.txt b/sigcore/CMakeLists.txt
new file mode 100644
index 00000000..6cee90ee
--- /dev/null
+++ b/sigcore/CMakeLists.txt
@@ -0,0 +1,51 @@
+PROJECT(sigcore)
+
+IF (NOT SIGEN_VERSION)
+ MESSAGE(FATAL_ERROR "Sigen version is not defined")
+ENDIF (NOT SIGEN_VERSION)
+
+SET(sigcore_HEADERS
+ Fraction.h
+ Global.h
+ Hat.h
+ Matrix.h
+ Script.h
+)
+SET(sigcore_SRCS
+ Fraction.cpp
+ Script.cpp
+)
+
+KDE4_ADD_LIBRARY(sigcore
+ SHARED
+ ${sigcore_SRCS}
+)
+SET_TARGET_PROPERTIES(sigcore
+ PROPERTIES
+ VERSION ${SIGEN_VERSION}
+ SOVERSION ${SIGEN_SOVERSION}
+ LINK_INTERFACE_LIBRARIES ""
+)
+TARGET_LINK_LIBRARIES(sigcore
+ ${QT_QTCORE_LIBRARY}
+)
+
+INCLUDE(../doxygen.cmake)
+
+INSTALL(
+ TARGETS
+ sigcore
+ DESTINATION
+ ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}
+ COMPONENT
+ runtime
+)
+
+INSTALL(
+ FILES
+ ${sigcore_HEADERS}
+ DESTINATION
+ ${CMAKE_INSTALL_PREFIX}/include/${CMAKE_PROJECT_NAME}/${PROJECT_NAME}
+ COMPONENT
+ development
+)
diff --git a/sigcore/Fraction.cpp b/sigcore/Fraction.cpp
new file mode 100644
index 00000000..f5e5e3a3
--- /dev/null
+++ b/sigcore/Fraction.cpp
@@ -0,0 +1,177 @@
+/*
+ * 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/>.
+ */
+
+/**
+ * \file sigcore/Fraction.cpp
+ */
+
+// Header include
+#include "Fraction.h"
+
+Sigcore::Fraction::Fraction(const int numerator, const int denominator)
+{
+ set(numerator, denominator);
+}
+
+Sigcore::Fraction::Fraction(const Fraction& fraction)
+{
+ set(fraction.numerator(), fraction.denominator());
+}
+
+void Sigcore::Fraction::set(const int numerator, const int denominator)
+{
+ m_numerator = numerator;
+ m_denominator = denominator;
+ normalize();
+}
+
+void Sigcore::Fraction::setNumerator(const int numerator)
+{
+ set(numerator, m_denominator);
+}
+
+void Sigcore::Fraction::setDenominator(const int denominator)
+{
+ set(m_numerator, denominator);
+}
+
+int Sigcore::Fraction::numerator() const
+{
+ return m_numerator;
+}
+
+int Sigcore::Fraction::denominator() const
+{
+ return m_denominator;
+}
+
+void Sigcore::Fraction::reduce()
+{
+ if (!m_numerator || !m_denominator)
+ return;
+ int i = m_numerator;
+ int j = m_denominator;
+ if (i < 0)
+ i = -i;
+ while (i - j)
+ (i > j) ? (i -= j) : (j -= i);
+ m_numerator /= i;
+ m_denominator /= i;
+}
+
+bool Sigcore::Fraction::poll() const
+{
+ return (qrand() % m_denominator) < m_numerator;
+}
+
+bool Sigcore::Fraction::poll(const int numerator, const int denominator)
+{
+ return (qrand() % denominator) < numerator;
+}
+
+Sigcore::Fraction& Sigcore::Fraction::operator=(const Fraction& rhs)
+{
+ if (this == &rhs)
+ return *this;
+ m_numerator = rhs.m_numerator;
+ m_denominator = rhs.m_denominator;
+ return *this;
+}
+
+Sigcore::Fraction::operator double() const
+{
+ return (double(m_numerator) / m_denominator);
+}
+
+Sigcore::Fraction Sigcore::Fraction::operator+(const Fraction& rhs) const
+{
+ return Fraction((m_numerator * rhs.m_denominator) + (m_denominator * rhs.m_numerator), m_denominator * rhs.m_denominator);
+}
+
+Sigcore::Fraction Sigcore::Fraction::operator-(const Fraction& rhs) const
+{
+ return Fraction((m_numerator * rhs.m_denominator) - (m_denominator * rhs.m_numerator), m_denominator * rhs.m_denominator);
+}
+
+Sigcore::Fraction Sigcore::Fraction::operator*(const Fraction& rhs) const
+{
+ return Fraction(m_numerator * rhs.m_numerator, m_denominator * rhs.m_denominator);
+}
+
+Sigcore::Fraction Sigcore::Fraction::operator/(const Fraction& rhs) const
+{
+ return Fraction(m_numerator * rhs.m_denominator, m_denominator * rhs.m_numerator);
+}
+
+Sigcore::Fraction& Sigcore::Fraction::operator+=(const Fraction& rhs)
+{
+ return *this = *this + rhs;
+}
+
+Sigcore::Fraction& Sigcore::Fraction::operator-=(const Fraction& rhs)
+{
+ return *this = *this - rhs;
+}
+
+Sigcore::Fraction& Sigcore::Fraction::operator*=(const Fraction& rhs)
+{
+ return *this = *this * rhs;
+}
+
+Sigcore::Fraction& Sigcore::Fraction::operator/=(const Fraction& rhs)
+{
+ return *this = *this / rhs;
+}
+
+bool Sigcore::Fraction::operator==(const Fraction& rhs) const
+{
+ return ((m_numerator * rhs.m_denominator) == (m_denominator * rhs.m_numerator));
+}
+
+bool Sigcore::Fraction::operator!=(const Fraction& rhs) const
+{
+ return !(*this == rhs);
+}
+
+bool Sigcore::Fraction::operator<(const Fraction& rhs) const
+{
+ return ((m_numerator * rhs.m_denominator) < (m_denominator * rhs.m_numerator));
+}
+
+bool Sigcore::Fraction::operator<=(const Fraction& rhs) const
+{
+ return ((m_numerator * rhs.m_denominator) <= (m_denominator * rhs.m_numerator));
+}
+
+bool Sigcore::Fraction::operator>(const Fraction& rhs) const
+{
+ return !(*this <= rhs);
+}
+
+bool Sigcore::Fraction::operator>=(const Fraction& rhs) const
+{
+ return !(*this < rhs);
+}
+
+void Sigcore::Fraction::normalize()
+{
+ if (m_denominator < 0)
+ {
+ m_denominator = -m_denominator;
+ m_numerator = -m_numerator;
+ }
+}
diff --git a/sigcore/Fraction.h b/sigcore/Fraction.h
new file mode 100644
index 00000000..1b171303
--- /dev/null
+++ b/sigcore/Fraction.h
@@ -0,0 +1,131 @@
+/*
+ * 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/>.
+ */
+
+/**
+ * \file sigcore/Fraction.h
+ */
+
+#ifndef SIGCORE_FRACTION
+#define SIGCORE_FRACTION
+
+// Sigcore includes
+#include "Global.h"
+
+// Qt includes
+#include <QtCore/QMetaType>
+
+namespace Sigcore
+{
+/**
+ * \class Sigcore::Fraction Fraction.h sigcore/Fraction.h
+ * \brief Class that represents a fractional quantity.
+ *
+ * This class should be used in place of \p double because of accuracy.
+ */
+class SIGCORE_EXPORT Fraction
+{
+ public:
+ /**
+ * Constructor.
+ *
+ * \param numerator The numerator of the fraction.
+ * \param denominator The denominator of the fraction.
+ */
+ explicit Fraction(const int numerator = 1, const int denominator = 1);
+ /**
+ * Copy constructor.
+ *
+ * \param fraction The value to copy.
+ */
+ Fraction(const Fraction& fraction);
+
+ /**
+ * Set the value of the fraction.
+ *
+ * \param numerator The numerator of the fraction.
+ * \param denominator The denominator of the fraction.
+ */
+ void set(const int numerator, const int denominator);
+ /**
+ * Sets the numerator of the fraction.
+ *
+ * \param numerator The numerator of the fraction.
+ */
+ void setNumerator(const int numerator);
+ /**
+ * Set the denominator of the fraciton.
+ *
+ * \param denominator The denominator of the fraction.
+ */
+ void setDenominator(const int denominator);
+
+ /**
+ * \return The numerator of the fraction.
+ */
+ int numerator() const;
+ /**
+ * \return The denominator of the fraction.
+ */
+ int denominator() const;
+
+ /**
+ * Reduces the fraction.
+ */
+ void reduce();
+ /**
+ * Uses the value of the fraction to return a weighted boolean.
+ *
+ * \return \p true with a weight of the fraction, \p false otherwise.
+ */
+ bool poll() const;
+ /**
+ * Convenience function to get a weighted boolean value.
+ *
+ * \param numerator The numerator of the chance that the function returns \p true.
+ * \param demoninator The denominator of the chance that the function returns \p true.
+ * \return \p true with a weight of the (\p numerator / \p denominator), \p false otherwise.
+ */
+ static bool poll(const int numerator, const int demoninator);
+
+ Fraction& operator=(const Fraction& rhs);
+ operator double() const;
+ Fraction operator+(const Fraction& rhs) const;
+ Fraction operator-(const Fraction& rhs) const;
+ Fraction operator*(const Fraction& rhs) const;
+ Fraction operator/(const Fraction& rhs) const;
+ Fraction operator%(const Fraction& rhs) const;
+ Fraction& operator+=(const Fraction& rhs);
+ Fraction& operator-=(const Fraction& rhs);
+ Fraction& operator*=(const Fraction& rhs);
+ Fraction& operator/=(const Fraction& rhs);
+ Fraction& operator%=(const Fraction& rhs);
+ bool operator==(const Fraction& rhs) const;
+ bool operator!=(const Fraction& rhs) const;
+ bool operator<(const Fraction& rhs) const;
+ bool operator<=(const Fraction& rhs) const;
+ bool operator>(const Fraction& rhs) const;
+ bool operator>=(const Fraction& rhs) const;
+ protected:
+ void normalize();
+ private:
+ int m_numerator;
+ int m_denominator;
+};
+}
+Q_DECLARE_METATYPE(Sigcore::Fraction)
+
+#endif
diff --git a/sigcore/Global.h b/sigcore/Global.h
new file mode 100644
index 00000000..db7ee0e0
--- /dev/null
+++ b/sigcore/Global.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright 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/>.
+ */
+
+/**
+ * \file sigcore/Global.h
+ */
+
+#ifndef SIGCORE_GLOBAL
+#define SIGCORE_GLOBAL
+
+// Qt includes
+#include <QtCore/QMetaType>
+#include <QtCore/QStringList>
+
+// KDE includes
+#include <kdemacros.h>
+
+#ifndef SIGCORE_EXPORT
+# ifdef MAKE_SIGCORE_LIB
+# define SIGCORE_EXPORT KDE_EXPORT /// Export the symbol if building the library.
+# else
+# define SIGCORE_EXPORT KDE_IMPORT /// Import the symbol if including the library.
+# endif
+#endif
+
+#ifndef SIGCORE_EXPORT_DEPRECATED
+# define SIGCORE_EXPORT_DEPRECATED KDE_DEPRECATED SIGCORE_EXPORT /// Mark as deprecated
+#endif
+
+#endif
diff --git a/sigcore/Hat.h b/sigcore/Hat.h
new file mode 100644
index 00000000..999dbbe9
--- /dev/null
+++ b/sigcore/Hat.h
@@ -0,0 +1,184 @@
+/*
+ * 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/>.
+ */
+
+/**
+ * \file sigcore/Hat.h
+ */
+
+#ifndef SIGCORE_HAT
+#define SIGCORE_HAT
+
+// Sigcore includes
+#include "Fraction.h"
+#include "Global.h"
+
+// Qt includes
+#include <QtCore/QtGlobal>
+#include <QtCore/QMap>
+
+namespace Sigcore
+{
+/**
+ * \class Sigcore::Hat Hat.h sigcore/Hat.h
+ * \brief Class to help choose items from a weighted set of items.
+ *
+ * Given a set of weighted items to choose from, Hat will pick out a random item from the set.
+ */
+template<class T> class SIGCORE_EXPORT Hat
+{
+ public:
+ /**
+ * Default constructor.
+ */
+ Hat();
+
+ /**
+ * Choose an item from the set without removal.
+ *
+ * \return The item chosen.
+ */
+ T pick() const;
+ /**
+ * Choose an item from the set with removal.
+ *
+ * \return The item chosen.
+ */
+ T take();
+ /**
+ * Choose an item from the set as well as all identical items.
+ *
+ * \return The item chosen.
+ */
+ T takeAndClear();
+ /**
+ * Set the weight of an item in the set.
+ *
+ * \param key The item to set.
+ * \param weight The weight of the item.
+ */
+ void setCount(const T& key, const int weight);
+ /**
+ * Add a number of items to the set.
+ *
+ * \param key The item to add to the set.
+ * \param weight How many of the item to add.
+ */
+ void add(const T& key, const int weight);
+ /**
+ * \return The number of distinct items in the set.
+ */
+ int distinctCount() const;
+ /**
+ * \return The number of total items in the set.
+ */
+ int count() const;
+ /**
+ * \param key The item to get the count of.
+ *
+ * \return The amount of \p key in the set.
+ */
+ int count(const T& key) const;
+ /**
+ * \param key The item to get the chance of.
+ *
+ * \return The chance of choosing \p key.
+ */
+ Fraction chance(const T& key) const;
+ private:
+ QMap<T, int> m_objects;
+ int m_count;
+};
+
+template<class T> inline Hat<T>::Hat() :
+ m_count(0)
+{
+}
+
+template<class T> inline T Hat<T>::pick() const
+{
+ int choice = qrand() % m_count;
+ foreach (const T& key, m_objects.keys())
+ {
+ choice -= m_objects[key];
+ if (choice < 0)
+ return key;
+ }
+ return T();
+}
+
+template<class T> inline T Hat<T>::take()
+{
+ T chosen = pick();
+ if (!(--m_objects[chosen]))
+ m_objects.remove(chosen);
+ --m_count;
+ return chosen;
+}
+
+template<class T> inline T Hat<T>::takeAndClear()
+{
+ T chosen = pick();
+ m_count -= m_objects[chosen];
+ m_objects.remove(chosen);
+ return chosen;
+}
+
+template<class T> inline void Hat<T>::setCount(const T& key, const int weight)
+{
+ if (m_objects.contains(key))
+ {
+ m_count -= m_objects[key];
+ if (!weight)
+ m_objects.remove(key);
+ }
+ add(key, weight);
+}
+
+template<class T> inline void Hat<T>::add(const T& key, const int weight)
+{
+ if (weight)
+ {
+ m_objects[key] += weight;
+ m_count += weight;
+ }
+}
+
+template<class T> inline int Hat<T>::distinctCount() const
+{
+ return m_objects.size();
+}
+
+template<class T> inline int Hat<T>::count() const
+{
+ return m_count;
+}
+
+template<class T> inline int Hat<T>::count(const T& key) const
+{
+ if (m_objects.contains(key))
+ return m_objects[key];
+ return 0;
+}
+
+template<class T> inline Fraction Hat<T>::chance(const T& key) const
+{
+ return Fraction(count(key), m_count);
+}
+
+}
+
+#endif
diff --git a/sigcore/Matrix.h b/sigcore/Matrix.h
new file mode 100644
index 00000000..e8f1f816
--- /dev/null
+++ b/sigcore/Matrix.h
@@ -0,0 +1,348 @@
+/*
+ * 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/>.
+ */
+
+/**
+ * \file sigcore/Matrix.h
+ */
+
+#ifndef SIGCORE_MATRIX
+#define SIGCORE_MATRIX
+
+// Sigmod includes
+#include "Global.h"
+
+// Qt includes
+#include <QtCore/QPoint>
+#include <QtCore/QVector>
+
+namespace Sigcore
+{
+/**
+ * \class Sigcore::Matrix Matrix.h sigcore/Matrix.h
+ * \brief Class for a two dimensional vector.
+ */
+template<class T> class SIGCORE_EXPORT Matrix
+{
+ public:
+ /**
+ * Default constructor.
+ */
+ Matrix();
+ /**
+ * Constructor.
+ *
+ * \param height The height of the matrix.
+ * \param width The width of the matrix.
+ * \param value The value to set all values to.
+ */
+ Matrix(const int height, const int width, const T& value = T());
+ /**
+ * Copy constructor.
+ *
+ * \param rhs The matrix to copy.
+ */
+ Matrix(const Matrix& rhs);
+
+ /**
+ * Add a row to the matrix.
+ *
+ * \param value The value to set the row to.
+ */
+ void addRow(const T& value = T());
+ /**
+ * Add a column to the matrix.
+ *
+ * \param value The value to set the column to.
+ */
+ void addColumn(const T& value = T());
+ /**
+ * Inserts a row into the matrix.
+ *
+ * \param row Where the new row will be placed.
+ * \param value The value to set the row to.
+ */
+ void insertRow(const int row, const T& value = T());
+ /**
+ * Inserts a column into the matrix.
+ *
+ * \param column Where the new column will be placed.
+ * \param value The value to set the column to.
+ */
+ void insertColumn(const int column, const T& value = T());
+ /**
+ * Removes a row from the matrix.
+ *
+ * \param row The row to remove from the matrix.
+ */
+ void deleteRow(const int row);
+ /**
+ * Removes a column from the matrix.
+ *
+ * \param column The column to remove from the matrix.
+ */
+ void deleteColumn(const int column);
+
+ /**
+ * Clears the matrix.
+ */
+ void clear();
+
+ /**
+ * Resizes the matrix to a new size. Rows and columns are removed from the end to shrink and added to the
+ * end to grow.
+ *
+ * \param newHeight The target height.
+ * \param newWidth The target width.
+ * \param value Value to set any additional rows and columns to.
+ */
+ void resize(const int newHeight, const int newWidth, const T& value = T());
+
+ /**
+ * Get a row from the matrix.
+ *
+ * \param row The row to retrieve.
+ * \return A row of the matrix.
+ */
+ QVector<T> row(const int row) const;
+ /**
+ * Get a column from the matrix.
+ *
+ * \param column The column to retrieve.
+ * \return A column of the matrix.
+ */
+ QVector<T> column(const int column) const;
+
+ /**
+ * Add a masked matrix to the matrix.
+ *
+ * \param top The top-most part of the matrix.
+ * \param left The left-most part of the matrix.
+ * \param mask The mask to add.
+ */
+ void addMask(const int top, const int left, const Matrix& mask);
+
+ /**
+ * \return The height of the matrix.
+ */
+ int height() const;
+ /**
+ * \return The width of the matrix.
+ */
+ int width() const;
+
+ /**
+ * Method for accessing values in the matrix.
+ *
+ * \param row The row of the cell.
+ * \param column The column of te cell.
+ * \return The value of the cell in the matrix.
+ */
+ T& operator()(const int row, const int column);
+ /**
+ * Convenience method.
+ *
+ * \param row The row of the cell.
+ * \param column The column of te cell.
+ * \return The value of the cell in the matrix.
+ */
+ T operator()(const int row, const int column) const;
+ Matrix<T>& operator=(const Matrix& rhs);
+ bool operator==(const Matrix& rhs) const;
+ bool operator!=(const Matrix& rhs) const;
+ private:
+ QVector< QVector<T> > m_matrix;
+};
+
+template<class T> Matrix<T>::Matrix()
+{
+}
+
+template<class T> Matrix<T>::Matrix(const int height, const int width, const T& value)
+{
+ resize(height, width, value);
+}
+
+template<class T> Matrix<T>::Matrix(const Matrix& rhs)
+{
+ *this = rhs;
+}
+
+template<class T> void Matrix<T>::addRow(const T& value)
+{
+ insertRow(height(), value);
+}
+
+template<class T> void Matrix<T>::addColumn(const T& value)
+{
+ insertColumn(width(), value);
+}
+
+template<class T> void Matrix<T>::insertRow(const int row, const T& value)
+{
+ Q_ASSERT(0 <= row);
+ Q_ASSERT(row <= height());
+ if (!height() || !width())
+ m_matrix.append(QVector<T>(1, value));
+ else
+ m_matrix.insert(row, QVector<T>(width(), value));
+}
+
+template<class T> void Matrix<T>::insertColumn(const int column, const T& value)
+{
+ Q_ASSERT(0 <= column);
+ Q_ASSERT(column <= width());
+ if (!height() || !width())
+ m_matrix.append(QVector<T>(1, value));
+ else
+ {
+ for (int i = 0; i < height(); ++i)
+ m_matrix[i].insert(column, value);
+ }
+}
+
+template<class T> void Matrix<T>::deleteRow(const int row)
+{
+ Q_ASSERT(0 <= row);
+ Q_ASSERT(row < height());
+ if (height() == 1)
+ m_matrix.clear();
+ else
+ m_matrix.remove(row);
+}
+
+template<class T> void Matrix<T>::deleteColumn(const int column)
+{
+ Q_ASSERT(0 <= column);
+ Q_ASSERT(column < width());
+ if (width() == 1)
+ m_matrix.clear();
+ else
+ {
+ for (int i = 0; i < height(); ++i)
+ m_matrix[i].remove(column);
+ }
+}
+
+template<class T> void Matrix<T>::clear()
+{
+ m_matrix.clear();
+}
+
+template<class T> void Matrix<T>::resize(const int newHeight, const int newWidth, const T& value)
+{
+ while (height() < newHeight)
+ addRow(value);
+ while (newHeight < height())
+ deleteRow(newHeight);
+ while (width() < newWidth)
+ addColumn(value);
+ while (newWidth < width())
+ deleteColumn(newWidth);
+}
+
+template<class T> QVector<T> Matrix<T>::row(const int row) const
+{
+ Q_ASSERT(0 <= row);
+ Q_ASSERT(row < height());
+ return m_matrix.at(row);
+}
+
+template<class T> QVector<T> Matrix<T>::column(const int column) const
+{
+ Q_ASSERT(0 <= column);
+ Q_ASSERT(column < width());
+ QVector<T> col;
+ foreach (QVector<T> row, m_matrix)
+ col.append(row.at(column));
+ return col;
+}
+
+template<class T> void Matrix<T>::addMask(const int top, const int left, const Matrix& mask)
+{
+ Q_ASSERT(0 <= top);
+ Q_ASSERT(top < height());
+ Q_ASSERT(0 <= left);
+ Q_ASSERT(left < width());
+ Q_ASSERT(0 <= mask.height());
+ Q_ASSERT(top + mask.height() <= height());
+ Q_ASSERT(0 <= mask.width());
+ Q_ASSERT(left + mask.width() <= width());
+ for (int i = 0; i < mask.height(); ++i)
+ {
+ for (int j = 0; j < mask.width(); ++j)
+ {
+ if (operator()(top + i, left + j) || mask(i, j))
+ operator()(top + i, left + j) = 1;
+ }
+ }
+}
+
+template<class T> int Matrix<T>::height() const
+{
+ return m_matrix.size();
+}
+
+template<class T> int Matrix<T>::width() const
+{
+ if (m_matrix.size())
+ return m_matrix[0].size();
+ return 0;
+}
+
+template<class T> T& Matrix<T>::operator()(const int row, const int column)
+{
+ Q_ASSERT(row < height());
+ Q_ASSERT(column < width());
+ return m_matrix[row][column];
+}
+
+template<class T> T Matrix<T>::operator()(const int row, const int column) const
+{
+ Q_ASSERT(row < height());
+ Q_ASSERT(column < width());
+ return m_matrix.at(row).at(column);
+}
+
+template<class T> Matrix<T>& Matrix<T>::operator=(const Matrix& rhs)
+{
+ if (this == &rhs)
+ return *this;
+ resize(rhs.height(), rhs.width());
+ for (int i = 0; i < height(); ++i)
+ {
+ for (int j = 0; j < width(); ++j)
+ m_matrix[i][j] = rhs.m_matrix[i][j];
+ }
+ return *this;
+}
+
+template<class T> bool Matrix<T>::operator==(const Matrix& rhs) const
+{
+ if (this == &rhs)
+ return true;
+ return m_matrix == rhs.m_matrix;
+ return true;
+}
+
+template<class T> bool Matrix<T>::operator!=(const Matrix& rhs) const
+{
+ return !(*this == rhs);
+}
+
+}
+
+#endif
diff --git a/sigcore/Script.cpp b/sigcore/Script.cpp
new file mode 100644
index 00000000..47ae55d2
--- /dev/null
+++ b/sigcore/Script.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright 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/>.
+ */
+
+/**
+ * \file sigcore/Script.cpp
+ */
+
+// Header include
+#include "Script.h"
+
+Sigcore::Script::Script(const QString& interpreter, const QString& script) :
+ m_interpreter(interpreter),
+ m_script(script)
+{
+}
+
+void Sigcore::Script::setInterpreter(const QString& interpreter)
+{
+ m_interpreter = interpreter;
+}
+
+void Sigcore::Script::setScript(const QString& script)
+{
+ m_script = script;
+}
+
+QString Sigcore::Script::interpreter() const
+{
+ return m_interpreter;
+}
+
+QString Sigcore::Script::script() const
+{
+ return m_script;
+}
+
+Sigcore::Script& Sigcore::Script::operator=(const Script& rhs)
+{
+ if (this == &rhs)
+ return *this;
+ m_interpreter = rhs.m_interpreter;
+ m_script = rhs.m_script;
+ return *this;
+}
+
+bool Sigcore::Script::operator==(const Script& rhs) const
+{
+ return ((m_interpreter == rhs.m_interpreter) && (m_script == rhs.m_script));
+}
+
+bool Sigcore::Script::operator!=(const Script& rhs) const
+{
+ return !(*this == rhs);
+}
diff --git a/sigcore/Script.h b/sigcore/Script.h
new file mode 100644
index 00000000..0cc51586
--- /dev/null
+++ b/sigcore/Script.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright 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/>.
+ */
+
+/**
+ * \file sigcore/Script.h
+ */
+
+#ifndef SIGCORE_SCRIPT
+#define SIGCORE_SCRIPT
+
+// Sigmod includes
+#include "Global.h"
+
+// Qt includes
+#include <QtCore/QString>
+
+namespace Sigcore
+{
+/**
+ * \class Sigcore::Script Script.h sigcore/Script.h
+ * \brief Class that describes a script for the game engine.
+ */
+class SIGCORE_EXPORT Script
+{
+ public:
+ /**
+ * Constructor.
+ *
+ * \param interpreter The language of the script.
+ * \param script The code for the script.
+ */
+ explicit Script(const QString& interpreter = "", const QString& script = "");
+
+ /**
+ * Set the language of the script. The default game engine uses Kross <http://kross.dipe.org/> to
+ * run the scripts. The following values are valid for Kross:
+ *
+ * - \b mono -- C# <http://www.mono-project.com/Main_Page>
+ * - \b falcon -- Falcon <http://www.falconpl.org/>
+ * - \b java -- Java <http://www.java.com/en/>
+ * - \b lua -- Lua <http://www.lua.org/>
+ * - \b php -- PHP <http://www.php.net/>
+ * - \b python -- Python <http://www.python.org/>
+ * - \b ruby -- Ruby <http://www.ruby-lang.org/en/>
+ *
+ * Other languages may be added in the future.
+ *
+ * \param interpreter The language of the script.
+ */
+ void setInterpreter(const QString& interpreter);
+ /**
+ *
+ * \param script The code for the script.
+ */
+ void setScript(const QString& script);
+
+ /**
+ * \sa setInterpreter
+ *
+ * \return The language of the script.
+ */
+ QString interpreter() const;
+ /**
+ * \sa setScript
+ *
+ * \return The code for the script.
+ */
+ QString script() const;
+
+ Script& operator=(const Script& rhs);
+ bool operator==(const Script& rhs) const;
+ bool operator!=(const Script& rhs) const;
+ private:
+ QString m_interpreter;
+ QString m_script;
+};
+}
+Q_DECLARE_METATYPE(Sigcore::Script)
+
+#endif