summaryrefslogtreecommitdiffstats
path: root/sigmod
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-12-29 10:54:11 -0500
committerBen Boeckel <MathStuf@gmail.com>2008-12-29 10:54:11 -0500
commit3fa8f8764bae2e2fa4d558f6282f1237444147d9 (patch)
treef006e662eb27ac480b3164850759784985769d95 /sigmod
parent471658adb0a2df73eef065cce4e7550d6dd14b1e (diff)
downloadsigen-3fa8f8764bae2e2fa4d558f6282f1237444147d9.tar.gz
sigen-3fa8f8764bae2e2fa4d558f6282f1237444147d9.tar.xz
sigen-3fa8f8764bae2e2fa4d558f6282f1237444147d9.zip
Fixed up Sigmod and it now uses check macros
Diffstat (limited to 'sigmod')
-rw-r--r--sigmod/Macros.h13
-rw-r--r--sigmod/Sigmod.cpp117
-rw-r--r--sigmod/Sigmod.h8
3 files changed, 59 insertions, 79 deletions
diff --git a/sigmod/Macros.h b/sigmod/Macros.h
index 34a31af4..06c258cc 100644
--- a/sigmod/Macros.h
+++ b/sigmod/Macros.h
@@ -35,7 +35,6 @@
#define LOAD_ARRAY(variable) loadArray(xml.firstChildElement(#variable), &m_##variable)
#define LOAD_LIST(variable) loadList(xml.firstChildElement(#variable), &m_##variable)
#define LOAD_MATRIX(variable) loadMatrix(xml.firstChildElement(#variable), &m_##variable)
-// #define LOAD_Rules() m_rules->load(xml.firstChildElement("Rules"))
#define LOAD_SUB(setter, class) \
QDomElement xml_##class = xml.firstChildElement(#class); \
while (!xml_##class.isNull()) \
@@ -112,6 +111,12 @@
m_##variable[index - offset] = value; \
emit(changed()); \
}
+#define TS_MATRIX(variable, row, column, value) \
+ if (variable##Check(value) && (m_##variable(row, column) != value)) \
+ { \
+ m_##variable(row, column) = value; \
+ emit(changed()); \
+ }
#define TS_LIST_BEGIN(variable) \
if (variable##Check(variable) && state && !m_##variable.contains(variable)) \
{
@@ -175,6 +180,11 @@ void Sigmod::class::set##capital(const indexType indexName, const type valueName
{ \
TS_ARRAY(variable, indexName, offset, valueName); \
}
+#define SETTER_MATRIX(class, type, capital, variable, valueName) \
+void Sigmod::class::set##capital(const int row, const int column, const type valueName) \
+{ \
+ TS_MATRIX(variable, row, column, valueName); \
+}
#define SETTER_LIST(class, capital, variable) \
void Sigmod::class::set##capital(const int variable, const bool state) \
{ \
@@ -209,7 +219,6 @@ QList<int> Sigmod::class::variable() const \
return m_##variable; \
}
-
#define CHECK_BEGIN(class, type, variable) \
bool Sigmod::class::variable##Check(const type variable) const \
{
diff --git a/sigmod/Sigmod.cpp b/sigmod/Sigmod.cpp
index 576eec0b..a916e39c 100644
--- a/sigmod/Sigmod.cpp
+++ b/sigmod/Sigmod.cpp
@@ -285,7 +285,7 @@ void Sigmod::Sigmod::load(const QDomElement& xml)
LOAD(singlePlayer);
LOAD(startMap);
LOAD(startWarp);
- LOAD_Rules();
+ m_rules->load(xml.firstChildElement("Rules"));
LOAD_SUB(newAbility, Ability);
LOAD_SUB(newAuthor, Author);
LOAD_SUB(newBadge, Badge);
@@ -348,53 +348,13 @@ QDomElement Sigmod::Sigmod::save() const
return xml;
}
-void Sigmod::Sigmod::setTitle(const QString& title)
-{
- CHECK(title);
-}
-
-void Sigmod::Sigmod::setVersion(const QString& version)
-{
- CHECK(version);
-}
-
-void Sigmod::Sigmod::setDescription(const QString& description)
-{
- CHECK(description);
-}
-
-void Sigmod::Sigmod::setSinglePlayer(const bool singlePlayer)
-{
- CHECK(singlePlayer);
-}
-
-void Sigmod::Sigmod::setStartMap(const int startMap)
-{
- if (!m_singlePlayer)
- emit(error(unused("startMap")));
- if (!mapById(startMap))
- emit(error(bounds("startMap", startMap)));
- else
- CHECK(startMap);
-}
-
-void Sigmod::Sigmod::setStartWarp(const int startWarp)
-{
- if (!m_singlePlayer)
- emit(error(unused("startWarp")));
- const Map* map = mapById(m_startMap);
- if (!map)
- emit(error(bounds("startMap", m_startMap)));
- else if (!map->warpById(startWarp))
- emit(error(bounds("startWarp", startWarp)));
- else
- CHECK(startWarp);
-}
-
-void Sigmod::Sigmod::setTypechart(const int attack, const int defense, const Sigcore::Fraction& multiplier)
-{
- CHECK_ARRAY(typechart(attack, defense), multiplier);
-}
+SETTER(Sigmod, QString&, Title, title)
+SETTER(Sigmod, QString&, Version, version)
+SETTER(Sigmod, QString&, Description, description)
+SETTER(Sigmod, bool, SinglePlayer, singlePlayer)
+SETTER(Sigmod, int, StartMap, startMap)
+SETTER(Sigmod, int, StartWarp, startWarp)
+SETTER_MATRIX(Sigmod, Sigcore::Fraction&, Typechart, typechart, multiplier)
void Sigmod::Sigmod::setRules(const Rules& rules)
{
@@ -406,35 +366,12 @@ void Sigmod::Sigmod::setRules(const QDomElement& xml)
m_rules->load(xml);
}
-QString Sigmod::Sigmod::title() const
-{
- return m_title;
-}
-
-QString Sigmod::Sigmod::version() const
-{
- return m_version;
-}
-
-QString Sigmod::Sigmod::description() const
-{
- return m_description;
-}
-
-bool Sigmod::Sigmod::singlePlayer() const
-{
- return m_singlePlayer;
-}
-
-int Sigmod::Sigmod::startMap() const
-{
- return m_startMap;
-}
-
-int Sigmod::Sigmod::startWarp() const
-{
- return m_startWarp;
-}
+GETTER(Sigmod, QString, title)
+GETTER(Sigmod, QString, version)
+GETTER(Sigmod, QString, description)
+GETTER(Sigmod, bool, singlePlayer)
+GETTER(Sigmod, int, startMap)
+GETTER(Sigmod, int, startWarp)
const Sigcore::Matrix<Sigcore::Fraction>* Sigmod::Sigmod::typechart() const
{
@@ -461,6 +398,32 @@ Sigmod::Rules* Sigmod::Sigmod::rules()
return m_rules;
}
+CHECK(Sigmod, QString&, title)
+CHECK(Sigmod, QString&, version)
+CHECK(Sigmod, QString&, description)
+CHECK(Sigmod, bool, singlePlayer)
+CHECK_BEGIN(Sigmod, int, startMap)
+ if (!m_singlePlayer)
+ {
+ emit(error(unused("startMap")));
+ return false;
+ }
+ if (!mapById(startMap))
+ EBOUNDS_IDX(startMap);
+CHECK_END()
+CHECK_BEGIN(Sigmod, int, startWarp)
+ if (!m_singlePlayer)
+ {
+ emit(error(unused("startWarp")));
+ return false;
+ }
+ const Map* map = mapById(m_startMap);
+ if (!map)
+ EBOUNDS_IDX(m_startMap);
+ IBOUNDS(startWarp, map, warp);
+CHECK_END()
+CHECK_BOUNDS(Sigmod, Sigcore::Fraction&, typechart, 0, INT_MAX)
+
const Sigmod::Ability* Sigmod::Sigmod::ability(const int index) const
{
if (index < abilityCount())
diff --git a/sigmod/Sigmod.h b/sigmod/Sigmod.h
index 043c4df1..0ccad22d 100644
--- a/sigmod/Sigmod.h
+++ b/sigmod/Sigmod.h
@@ -134,6 +134,14 @@ class SIGMOD_EXPORT Sigmod : public Object
const Rules* rules() const;
Rules* rules();
+ bool titleCheck(const QString& title) const;
+ bool versionCheck(const QString& version) const;
+ bool descriptionCheck(const QString& description) const;
+ bool singlePlayerCheck(const bool singlePlayer) const;
+ bool startMapCheck(const int startMap) const;
+ bool startWarpCheck(const int startWarp) const;
+ bool typechartCheck(const Sigcore::Fraction& multiplier) const;
+
const Ability* ability(const int index) const;
Ability* ability(const int index);
const Ability* abilityById(const int id) const;