diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2007-05-11 01:33:42 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2007-05-11 01:33:42 +0000 |
| commit | fafbdab97afb5ec6498ea0ab66b693b9e335f6f1 (patch) | |
| tree | 2f8ad1e735f3b15b123ea2353fedec8affd22790 /pokemod/Matrix.cpp | |
| parent | 0d2d8121cbb6a45180d88021fe2e5ac86b3532e3 (diff) | |
Starting INI migration
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@9 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Matrix.cpp')
| -rw-r--r-- | pokemod/Matrix.cpp | 171 |
1 files changed, 97 insertions, 74 deletions
diff --git a/pokemod/Matrix.cpp b/pokemod/Matrix.cpp index d2c917c0..9fb32398 100644 --- a/pokemod/Matrix.cpp +++ b/pokemod/Matrix.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////
-// Name: pokemod/Matrix.cpp
+// Name: pokemod/Map.cpp
// Purpose: A 2D vector class
// Author: Ben Boeckel
// Modified by: Ben Boeckel
@@ -24,7 +24,7 @@ #include "Matrix.h"
template<class T>
-PokeGen::PokeMod::Matrix<T>::Matrix(unsigned w, unsigned h, T &d)
+PokeGen::PokeMod::Matrix<T>::Matrix(unsigned w, unsigned h, const T &d)
{
matrix.resize(w, std::vector<T>(h, d));
width = w;
@@ -32,112 +32,135 @@ PokeGen::PokeMod::Matrix<T>::Matrix(unsigned w, unsigned h, T &d) }
template<class T>
-PokeGen::PokeMod::Matrix<T>::Matrix(XmlElement &x)
+PokeGen::PokeMod::Matrix<T>::Matrix(Ini &ini)
{
- ImportXml(xml);
+ width = 0;
+ height = 0;
+ matrix.clear();
}
-template<class T>
-void PokeGen::PokeMod::Matrix<T>::AddRow(T &d)
+template<>
+PokeGen::PokeMod::Matrix<PokeGen::PokeMod::Point>::Matrix(Ini &ini)
{
- for (std::vector<T> *i = matrix.begin(); i != matrix.end(); ++i)
- i->push_back(d);
- ++height;
+ ImportIni(ini);
+}
+
+template<>
+PokeGen::PokeMod::Matrix<PokeGen::PokeMod::Frac>::Matrix(Ini &ini)
+{
+ ImportIni(ini);
}
template<class T>
-void PokeGen::PokeMod::Matrix<T>::ImportXml(XmlElement &xml)
+void PokeGen::PokeMod::Matrix<T>::ImportIni(Ini &ini)
+{
+}
+
+template<>
+void PokeGen::PokeMod::Matrix<PokeGen::PokeMod::Point>::ImportIni(Ini &ini)
{
LogImportStart("Matrix");
- String curName;
- width = 0;
- height = 0;
- bool haveHeight = false;
- bool haveWidth = false;
- xml.ClearCounter();
- for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
+ ini.GetValue("width", width, 0);
+ ini.GetValue("height", height, 0);
+ if (!(width && height))
+ return;
+ matrix.resize(width, std::vector<Point>(height, Point(0, 0)));
+ for (unsigned i = 0; i < width; ++i)
{
- curName = child->GetName();
- if (curName == "height")
+ for (unsigned j = 0; j < height; ++j)
{
- child->GetValue(height);
- if (height)
- haveHeight = true;
+ int k;
+ int l;
+ ini.GetValue(String("Element-%d-%d-x", i, j), k, 0);
+ ini.GetValue(String("Element-%d-%d-y", i, j), l, 0);
+ matrix[i][j].Set(k, l);
}
- else if (curName == "width")
+ }
+ LogImportOver("Matrix");
+}
+
+template<>
+void PokeGen::PokeMod::Matrix<PokeGen::PokeMod::Frac>::ImportIni(Ini &ini)
+{
+ LogImportStart("Matrix");
+ ini.GetValue("width", width, 0);
+ ini.GetValue("height", height, 0);
+ if (!(width && height))
+ return;
+ matrix.resize(width, std::vector<Frac>(height, Frac(1, 1)));
+ for (unsigned i = 0; i < width; ++i)
+ {
+ for (unsigned j = 0; j < height; ++j)
{
- if (haveHeight)
- {
- child->GetValue(width);
- if (width)
- haveWidth = true;
- matrix.resize(w, std::vector<T>(h, T()));
- }
- else
- Log("Matrix Import: Elements out of order", PM_DEBUG_ERROR);
+ unsigned k;
+ unsigned l;
+ bool m;
+ ini.GetValue(String("Element-%d-%d-n", i, j), k, 0);
+ ini.GetValue(String("Element-%d-%d-d", i, j), l, 0);
+ ini.GetValue(String("Element-%d-%d-i", i, j), m, 0);
+ matrix[i][j].Set(k, l, m);
}
- else if (curName == "col")
+ }
+ LogImportOver("Matrix");
+}
+
+template<>
+void PokeGen::PokeMod::Matrix<PokeGen::PokeMod::Point>::ExportIni(const String &val)
+{
+ Log(String("Matrix Export: Starting %s", val.c_str()), PM_DEBUG_INFO);
+ // Declare the elements
+ Ini exMatrix(val);
+ exMatrix.AddField("height", height);
+ exMatrix.AddField("width", width);
+ for (int i = 0; i < width; ++i)
+ {
+ for (unsigned j = 0; j < height; ++j)
{
- if (height && width)
- {
- unsigned colNum;
- unsigned rowNum;
- child->GetValue(colNum);
- if (colNum < width)
- {
- child->ClearCounter();
- for (XmlElement *item = child->NextElement(); item; item = child->NextElement())
- {
- item->GetValue(rowNum);
- if ((item->GetName() == "item") && (rowNum < height))
- matrix[colNum][rowNum].ImportXml(*item);
- else
- Log("Matrix Import: Item out of bounds", PM_DEBUG_ERROR);
- }
- }
- else
- Log("Matrix Import: Column out of bounds", PM_DEBUG_ERROR);
- }
- else
- Log("Matrix Import: Elements out of order", PM_DEBUG_ERROR);
+ exMatrix.AddField(String("Element-%d-%d-x", i, j), matrix[i][j].GetX());
+ exMatrix.AddField(String("Element-%d-%d-y", i, j), matrix[i][j].GetY());
}
- else
- LogUnknownXml("Matrix", curName);
}
- LogImportOver("Matrix", id, name);
+ Log(String("Matrix Export: Finished %s", val.c_str()), PM_DEBUG_INFO);
}
-template<class T>
-PokeGen::PokeMod::XmlElement PokeGen::PokeMod::Matrix<T>::ExportXml(const String &val)
+template<>
+void PokeGen::PokeMod::Matrix<PokeGen::PokeMod::Frac>::ExportIni(std::ofstream &fout, const String &val)
{
Log(String("Matrix Export: Starting %s", val.c_str()), PM_DEBUG_INFO);
// Declare the elements
- XmlElement exMatrix(val, 0, true);
- exMatrix.AddElement("height", height);
- exMatrix.AddElement("width", width);
- for (int i = 0; i < width; ++i)
+ Ini exMatrix(val);
+ exMatrix.AddField("height", height);
+ exMatrix.AddField("width", width);
+ for (unsigned i = 0; i < width; ++i)
{
- XmlElement col("column", i, true);
- for (int j = 0; j < height; ++j)
+ for (unsigned j = 0; j < height; ++j)
{
- XmlElement item("item", j, true);
- item.AddElement(matrix[i][j].ExportXml());
+ exMatrix.AddField(String("Element-%d-%d-i", i, j), matrix[i][j].GetImproper());
+ exMatrix.AddField(String("Element-%d-%d-n", i, j), matrix[i][j].GetNum());
+ exMatrix.AddField(String("Element-%d-%d-d", i, j), matrix[i][j].GetDenom());
}
- exMatrix.AddElement(col);
}
+ exMatrix.Export(fout);
Log(String("Matrix Export: Finished %s", val.c_str()), PM_DEBUG_INFO);
- return exMatrix;
}
template<class T>
-void PokeGen::PokeMod::Matrix<T>::AddCol(T &d)
+void PokeGen::PokeMod::Matrix<T>::AddRow(const T &d)
+{
+ for (std::vector<T> *i = matrix.begin(); i != matrix.end(); ++i)
+ i->push_back(d);
+ ++height;
+}
+
+template<class T>
+void PokeGen::PokeMod::Matrix<T>::AddCol(const T &d)
{
matrix.push_back(std::vector<T>(GetHeight(), d));
++width;
}
template<class T>
-bool PokeGen::PokeMod::Matrix<T>::InsertRow(unsigned pos, T &d)
+bool PokeGen::PokeMod::Matrix<T>::InsertRow(unsigned pos, const T &d)
{
if (height < pos)
return false;
@@ -148,7 +171,7 @@ bool PokeGen::PokeMod::Matrix<T>::InsertRow(unsigned pos, T &d) }
template<class T>
-bool PokeGen::PokeMod::Matrix<T>::InsertCol(unsigned pos, T &d)
+bool PokeGen::PokeMod::Matrix<T>::InsertCol(unsigned pos, const T &d)
{
if (width < pos)
return false;
@@ -179,7 +202,7 @@ bool PokeGen::PokeMod::Matrix<T>::DeleteCol(unsigned pos) }
template<class T>
-bool PokeGen::PokeMod::Matrix<T>::Set(unsigned row, unsigned col, T &s)
+bool PokeGen::PokeMod::Matrix<T>::Set(unsigned row, unsigned col, const T &s)
{
if ((width <= col) || (height <= col))
return false;
|
