diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2008-04-19 18:12:17 +0000 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2008-04-19 18:12:17 +0000 |
commit | fe31331e2807634ae659e372358bac5781de9130 (patch) | |
tree | 6b208974e3f141e9b22152526e2d42e967bfd4ec /pokemod/Object.h | |
parent | 6679f5cffa9d35a23b76605ddfbf3257f882b6ee (diff) | |
download | sigen-fe31331e2807634ae659e372358bac5781de9130.tar.gz sigen-fe31331e2807634ae659e372358bac5781de9130.tar.xz sigen-fe31331e2807634ae659e372358bac5781de9130.zip |
[FIX] IndexException is more explicit
[FIX] Added SizeException for image validation
[FIX] QPixmaps are now verified
[FIX] Classes now use error and warning rather than throwing
[FIX] Deleted Object.cpp
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@100 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Object.h')
-rw-r--r-- | pokemod/Object.h | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/pokemod/Object.h b/pokemod/Object.h index 8dd29da9..c3234dc8 100644 --- a/pokemod/Object.h +++ b/pokemod/Object.h @@ -19,6 +19,7 @@ #define __POKEMOD_OBJECT__ // Qt includes +#include <QDomDocument> #include <QDomElement> // General includes @@ -30,13 +31,13 @@ class Pokemod; class Object { public: - Object(const Object& object) : + inline Object(const Object& object) : m_id(object.id()), m_className(object.className()), m_pokemod(object.pokemod()) { } - Object(const QString& className, const Pokemod* pokemod, const int id) : + inline Object(const QString& className, const Pokemod* pokemod, const int id) : m_id(id), m_className(className), m_pokemod(pokemod) @@ -46,7 +47,7 @@ class Object { } virtual void load(const QDomElement& xml, int id = INT_MAX) = 0; - virtual QDomElement save() const; + virtual QDomElement save() const = 0; inline const Pokemod* pokemod() const { @@ -78,8 +79,15 @@ class Object m_id = id; } virtual bool validate() const = 0; - template<class T> void warning(const QString& msg) const throw(Exception); - template<class T> void error(const QString& msg) const throw(Exception); + template<class T> inline void warning(const QString& message) const throw(T) + { + throw(T(m_className, message)); + } + template<class T> inline void error(const QString& message) throw(T) + { + m_valid = false; + warning<T>(message); + } virtual void clear() = 0; private: int m_id; @@ -89,7 +97,7 @@ class Object }; #define LOAD_NODE(variable) xml.firstChildElement(variable) -#define LOAD_DATA(node) node.nodeValue() +#define LOAD_DATA(node) node.firstChild().toText().data() #define LOAD_ID() \ if (id == INT_MAX) \ id = xml.attribute("id", "-1").toInt(); \ @@ -147,17 +155,16 @@ class Object } #define SAVE_CREATE() \ - QDomElement xml; \ - xml.setTagName(className()); \ + QDomElement xml = QDomDocument().createElement(className()); \ xml.setAttribute("id", id()) +#define SAVE_VALUE(element, value) element.appendChild(QDomDocument().createTextNode(value)) #define SAVE(type, variable) \ - QDomElement xml_##variable; \ - xml_##variable.setTagName(#variable); \ + QDomElement xml_##variable = QDomDocument().createElement(#variable); \ SAVE_##type(variable, variable()); \ xml.appendChild(xml_##variable) -#define SAVE_bool(variable, value) xml_##variable.setNodeValue(value ? "true" : "false") -#define SAVE_int(variable, value) xml_##variable.setNodeValue(QString::number(value)) -#define SAVE_QString(variable, value) xml_##variable.setNodeValue(value) +#define SAVE_bool(variable, value) SAVE_VALUE(xml_##variable, value ? "true" : "false") +#define SAVE_int(variable, value) SAVE_VALUE(xml_##variable, QString::number(value)) +#define SAVE_QString(variable, value) SAVE_VALUE(xml_##variable, value) #define SAVE_Fraction(variable, value) \ Fraction frac_##variable = value; \ xml_##variable.setAttribute("numerator", frac_##variable.numerator()); \ @@ -171,46 +178,40 @@ class Object xml_##variable.setAttribute("x", point_##variable.x()); \ xml_##variable.setAttribute("y", point_##variable.y()) #define SAVE_QPixmap(variable, value) \ - QPixmap pixmap_##variable; \ QByteArray bytes_##variable; \ QBuffer buffer_##variable(&bytes_##variable); \ buffer_##variable.open(QIODevice::WriteOnly); \ - value.save(&buffer_##variable, "PNG") + value.save(&buffer_##variable, "PNG"); \ + SAVE_VALUE(xml_##variable, bytes_##variable.toBase64()) #define SAVE_ARRAY(type, variable, size) \ - QDomElement xml_array_##variable; \ - xml_array_##variable.setTagName(#variable); \ + QDomElement xml_array_##variable = QDomDocument().createElement(#variable); \ for (int i = 0; i < size; ++i) \ { \ - QDomElement xml_##variable; \ - xml_##variable.setTagName("element"); \ + QDomElement xml_##variable = QDomDocument().createElement("element"); \ xml_##variable.setAttribute("index", QString::number(i)); \ SAVE_##type(variable, variable(i)); \ xml_array_##variable.appendChild(xml_##variable); \ } \ xml.appendChild(xml_array_##variable) #define SAVE_LIST(type, variable) \ - QDomElement xml_list_##variable; \ - xml_list_##variable.setTagName(#variable); \ + QDomElement xml_list_##variable = QDomDocument().createElement(#variable); \ xml_list_##variable.setAttribute("size", m_##variable.size()); \ for (int i = 0; i < m_##variable.size(); ++i) \ { \ - QDomElement xml_##variable; \ - xml_##variable.setTagName("element"); \ + QDomElement xml_##variable = QDomDocument().createElement("element"); \ SAVE_##type(variable, m_##variable[i]); \ xml_list_##variable.appendChild(xml_##variable); \ } \ xml.appendChild(xml_list_##variable) #define SAVE_MATRIX(type, variable) \ - QDomElement xml_matrix_##variable; \ - xml_matrix_##variable.setTagName(#variable); \ + QDomElement xml_matrix_##variable = QDomDocument().createElement(#variable); \ xml_matrix_##variable.setAttribute("height", m_##variable.height()); \ xml_matrix_##variable.setAttribute("width", m_##variable.width()); \ for (int i = 0; i < m_##variable.height(); ++i) \ { \ for (int j = 0; j < m_##variable.width(); ++j) \ { \ - QDomElement xml_##variable; \ - xml_##variable.setTagName("element"); \ + QDomElement xml_##variable = QDomDocument().createElement("element"); \ xml_##variable.setAttribute("row", QString::number(i)); \ xml_##variable.setAttribute("column", QString::number(j)); \ SAVE_##type(variable, variable(i, j)); \ |