summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sigmod/CoinList.cpp23
-rw-r--r--sigmod/CoinList.h3
-rw-r--r--sigmod/CoinListItem.cpp62
-rw-r--r--sigmod/CoinListItem.h4
-rw-r--r--sigmod/EggGroup.cpp12
-rw-r--r--sigmod/EggGroup.h2
-rw-r--r--sigmod/GlobalScript.cpp23
-rw-r--r--sigmod/GlobalScript.h3
-rw-r--r--sigmod/Item.cpp133
-rw-r--r--sigmod/Item.h9
-rw-r--r--sigmod/ItemType.cpp87
-rw-r--r--sigmod/ItemType.h6
-rw-r--r--sigmod/Map.cpp91
-rw-r--r--sigmod/Map.h6
-rw-r--r--sigmod/MapTile.cpp51
-rw-r--r--sigmod/MapTile.h4
16 files changed, 184 insertions, 335 deletions
diff --git a/sigmod/CoinList.cpp b/sigmod/CoinList.cpp
index d2b3e3a7..92a8a16f 100644
--- a/sigmod/CoinList.cpp
+++ b/sigmod/CoinList.cpp
@@ -102,25 +102,14 @@ QDomElement Sigmod::CoinList::save() const
return xml;
}
-void Sigmod::CoinList::setName(const QString& name)
-{
- CHECK(name);
-}
+SETTER(CoinList, QString&, Name, name)
+SETTER(CoinList, Sigcore::Script&, Script, script)
-void Sigmod::CoinList::setScript(const Sigcore::Script& script)
-{
- CHECK(script);
-}
+GETTER(CoinList, QString, name)
+GETTER(CoinList, Sigcore::Script, script)
-QString Sigmod::CoinList::name() const
-{
- return m_name;
-}
-
-Sigcore::Script Sigmod::CoinList::script() const
-{
- return m_script;
-}
+CHECK_DEFAULT(CoinList, QString&, name)
+CHECK_DEFAULT(CoinList, Sigcore::Script&, script)
const Sigmod::CoinListItem* Sigmod::CoinList::item(const int index) const
{
diff --git a/sigmod/CoinList.h b/sigmod/CoinList.h
index 7807271f..f4c74669 100644
--- a/sigmod/CoinList.h
+++ b/sigmod/CoinList.h
@@ -184,6 +184,9 @@ class SIGMOD_EXPORT CoinList : public Object
*/
void deleteItemById(const int id);
+ bool nameCheck(const QString& name) const;
+ bool scriptCheck(const Sigcore::Script& script) const;
+
CoinList& operator=(const CoinList& rhs);
private:
int itemId() const;
diff --git a/sigmod/CoinListItem.cpp b/sigmod/CoinListItem.cpp
index c015b6f9..642fb013 100644
--- a/sigmod/CoinListItem.cpp
+++ b/sigmod/CoinListItem.cpp
@@ -59,8 +59,8 @@ Sigmod::CoinListItem::CoinListItem(const QDomElement& xml, const CoinList* paren
void Sigmod::CoinListItem::validate()
{
TEST_BEGIN();
- TEST(setObject, object);
- TEST(setCost, cost);
+ TEST(object);
+ TEST(cost);
TEST_END();
}
@@ -81,41 +81,29 @@ QDomElement Sigmod::CoinListItem::save() const
return xml;
}
-void Sigmod::CoinListItem::setType(const Type type)
-{
- CHECK(type);
-}
-
-void Sigmod::CoinListItem::setObject(const int object)
-{
- if (((Item == m_type) && !sigmod()->itemById(object)) || ((Species == m_type) && !sigmod()->speciesById(object)))
- emit(error(bounds("object", object)));
- else
- CHECK(object);
-}
-
-void Sigmod::CoinListItem::setCost(const int cost)
-{
- if (cost <= 0)
- emit(error(bounds("cost", 1, INT_MAX, cost)));
- else
- CHECK(cost);
-}
-
-Sigmod::CoinListItem::Type Sigmod::CoinListItem::type() const
-{
- return m_type;
-}
-
-int Sigmod::CoinListItem::object() const
-{
- return m_object;
-}
-
-int Sigmod::CoinListItem::cost() const
-{
- return m_cost;
-}
+SETTER(CoinListItem, Type, Type, type)
+SETTER(CoinListItem, int, Object, object)
+SETTER(CoinListItem, int, Cost, cost)
+
+GETTER(CoinListItem, Sigmod::CoinListItem::Type, type)
+GETTER(CoinListItem, int, object)
+GETTER(CoinListItem, int, cost)
+
+CHECK_DEFAULT(CoinListItem, Type, type)
+CHECK_BEGIN(CoinListItem, int, object)
+ switch (m_type)
+ {
+ case Item:
+ IBOUNDS(object, sigmod(), type)
+ break;
+ case Species:
+ IBOUNDS(object, sigmod(), species)
+ break;
+ }
+CHECK_END()
+CHECK_BEGIN(CoinListItem, int, cost)
+ TBOUNDS(cost, 1, INT_MAX)
+CHECK_END()
Sigmod::CoinListItem& Sigmod::CoinListItem::operator=(const CoinListItem& rhs)
{
diff --git a/sigmod/CoinListItem.h b/sigmod/CoinListItem.h
index 237d6317..c38a7b4b 100644
--- a/sigmod/CoinListItem.h
+++ b/sigmod/CoinListItem.h
@@ -141,6 +141,10 @@ class SIGMOD_EXPORT CoinListItem : public Object
*/
int cost() const;
+ bool typeCheck(const Type type) const;
+ bool objectCheck(const int object) const;
+ bool costCheck(const int cost) const;
+
CoinListItem& operator=(const CoinListItem& rhs);
private:
Type m_type;
diff --git a/sigmod/EggGroup.cpp b/sigmod/EggGroup.cpp
index 139c646a..c3eed032 100644
--- a/sigmod/EggGroup.cpp
+++ b/sigmod/EggGroup.cpp
@@ -72,15 +72,11 @@ QDomElement Sigmod::EggGroup::save() const
return xml;
}
-void Sigmod::EggGroup::setName(const QString& name)
-{
- CHECK(name);
-}
+SETTER(EggGroup, QString&, Name, name)
-QString Sigmod::EggGroup::name() const
-{
- return m_name;
-}
+GETTER(EggGroup, QString, name)
+
+CHECK_DEFAULT(EggGroup, QString&, name)
Sigmod::EggGroup& Sigmod::EggGroup::operator=(const EggGroup& rhs)
{
diff --git a/sigmod/EggGroup.h b/sigmod/EggGroup.h
index 89e6a754..b259025a 100644
--- a/sigmod/EggGroup.h
+++ b/sigmod/EggGroup.h
@@ -101,6 +101,8 @@ class SIGMOD_EXPORT EggGroup : public Object
*/
QString name() const;
+ bool nameCheck(const QString& name) const;
+
EggGroup& operator=(const EggGroup& rhs);
private:
QString m_name;
diff --git a/sigmod/GlobalScript.cpp b/sigmod/GlobalScript.cpp
index fc5e7d62..2b99f82a 100644
--- a/sigmod/GlobalScript.cpp
+++ b/sigmod/GlobalScript.cpp
@@ -75,25 +75,14 @@ QDomElement Sigmod::GlobalScript::save() const
return xml;
}
-void Sigmod::GlobalScript::setName(const QString& name)
-{
- CHECK(name);
-}
+SETTER(GlobalScript, QString&, Name, name)
+SETTER(GlobalScript, Sigcore::Script&, Script, script)
-void Sigmod::GlobalScript::setScript(const Sigcore::Script& script)
-{
- CHECK(script);
-}
+GETTER(GlobalScript, QString, name)
+GETTER(GlobalScript, Sigcore::Script, script)
-QString Sigmod::GlobalScript::name() const
-{
- return m_name;
-}
-
-Sigcore::Script Sigmod::GlobalScript::script() const
-{
- return m_script;
-}
+CHECK_DEFAULT(GlobalScript, QString&, name)
+CHECK_DEFAULT(GlobalScript, Sigcore::Script&, script)
Sigmod::GlobalScript& Sigmod::GlobalScript::operator=(const GlobalScript& rhs)
{
diff --git a/sigmod/GlobalScript.h b/sigmod/GlobalScript.h
index 0f1684b8..0c82a945 100644
--- a/sigmod/GlobalScript.h
+++ b/sigmod/GlobalScript.h
@@ -123,6 +123,9 @@ class SIGMOD_EXPORT GlobalScript : public Object
*/
Sigcore::Script script() const;
+ bool nameCheck(const QString& name) const;
+ bool scriptCheck(const Sigcore::Script& script) const;
+
GlobalScript& operator=(const GlobalScript& rhs);
private:
QString m_name;
diff --git a/sigmod/Item.cpp b/sigmod/Item.cpp
index e6f521dd..98a2e274 100644
--- a/sigmod/Item.cpp
+++ b/sigmod/Item.cpp
@@ -68,11 +68,11 @@ void Sigmod::Item::validate()
TEST_BEGIN();
if (m_name.isEmpty())
emit(error("Name is empty"));
- TEST(setType, type);
- TEST(setPrice, price);
+ TEST(type);
+ TEST(price);
if (m_sellable)
- TEST(setSellPrice, sellPrice);
- TEST(setWeight, weight);
+ TEST(sellPrice);
+ TEST(weight);
TEST_END();
}
@@ -103,101 +103,40 @@ QDomElement Sigmod::Item::save() const
return xml;
}
-void Sigmod::Item::setName(const QString& name)
-{
- CHECK(name);
-}
-
-void Sigmod::Item::setSellable(const bool sellable)
-{
- CHECK(sellable);
-}
-
-void Sigmod::Item::setType(const int type)
-{
- if (!sigmod()->itemTypeById(type))
- emit(error(bounds("type", type)));
- else
- CHECK(type);
-}
-
-void Sigmod::Item::setPrice(const int price)
-{
- if ((price <= 0) || (sigmod()->rules()->maxMoney() < price))
- emit(error(bounds("price", 1, sigmod()->rules()->maxMoney(), price)));
- else
- CHECK(price);
-}
-
-void Sigmod::Item::setSellPrice(const int sellPrice)
-{
- if ((sellPrice < 0) || (m_price < sellPrice))
- emit(error(bounds("sellPrice", 0, m_price, sellPrice)));
- else
- CHECK(sellPrice);
-}
-
-void Sigmod::Item::setWeight(const int weight)
-{
+SETTER(Item, QString&, Name, name)
+SETTER(Item, bool, Sellable, sellable)
+SETTER(Item, int, Type, type)
+SETTER(Item, int, Price, price)
+SETTER(Item, int, SellPrice, sellPrice)
+SETTER(Item, int, Weight, weight)
+SETTER(Item, QString&, Description, description)
+SETTER(Item, Sigcore::Script&, Script, script)
+
+GETTER(Item, QString, name)
+GETTER(Item, bool, sellable)
+GETTER(Item, int, type)
+GETTER(Item, int, price)
+GETTER(Item, int, sellPrice)
+GETTER(Item, int, weight)
+GETTER(Item, QString, description)
+GETTER(Item, Sigcore::Script, script)
+
+CHECK_DEFAULT(Item, QString&, name)
+CHECK_DEFAULT(Item, bool, sellable)
+CHECK_INDEX(Item, int, type, sigmod(), type)
+CHECK_BEGIN(Item, int, price)
+ TBOUNDS(price, 1, sigmod()->rules()->maxMoney())
+CHECK_END()
+CHECK_BEGIN(Item, int, sellPrice)
+ TBOUNDS(sellPrice, 0, m_price)
+CHECK_END()
+CHECK_BEGIN(Item, int, weight)
const ItemType* type = sigmod()->itemTypeById(m_type);
if (type)
- {
- if ((weight < 0) || (type->maxWeight() < weight))
- emit(error(bounds("weight", 0, type->maxWeight(), weight)));
- else
- CHECK(weight);
- }
-}
-
-void Sigmod::Item::setDescription(const QString& description)
-{
- CHECK(description);
-}
-
-void Sigmod::Item::setScript(const Sigcore::Script& script)
-{
- CHECK(script);
-}
-
-QString Sigmod::Item::name() const
-{
- return m_name;
-}
-
-bool Sigmod::Item::sellable() const
-{
- return m_sellable;
-}
-
-int Sigmod::Item::type() const
-{
- return m_type;
-}
-
-int Sigmod::Item::price() const
-{
- return m_price;
-}
-
-int Sigmod::Item::sellPrice() const
-{
- return m_sellPrice;
-}
-
-int Sigmod::Item::weight() const
-{
- return m_weight;
-}
-
-QString Sigmod::Item::description() const
-{
- return m_description;
-}
-
-Sigcore::Script Sigmod::Item::script() const
-{
- return m_script;
-}
+ TBOUNDS(weight, 0, type->maxWeight())
+CHECK_END()
+CHECK_DEFAULT(Item, QString&, description)
+CHECK_DEFAULT(Item, Sigcore::Script&, script)
Sigmod::Item& Sigmod::Item::operator=(const Item& rhs)
{
diff --git a/sigmod/Item.h b/sigmod/Item.h
index 59f04675..120b6166 100644
--- a/sigmod/Item.h
+++ b/sigmod/Item.h
@@ -200,6 +200,15 @@ class SIGMOD_EXPORT Item : public Object
*/
Sigcore::Script script() const;
+ bool nameCheck(const QString& name) const;
+ bool sellableCheck(const bool sellable) const;
+ bool typeCheck(const int type) const;
+ bool priceCheck(const int price) const;
+ bool sellPriceCheck(const int sellPrice) const;
+ bool weightCheck(const int weight) const;
+ bool descriptionCheck(const QString& description) const;
+ bool scriptCheck(const Sigcore::Script& script) const;
+
Item& operator=(const Item& rhs);
private:
QString m_name;
diff --git a/sigmod/ItemType.cpp b/sigmod/ItemType.cpp
index e3bc2b4d..35585659 100644
--- a/sigmod/ItemType.cpp
+++ b/sigmod/ItemType.cpp
@@ -63,9 +63,9 @@ void Sigmod::ItemType::validate()
TEST_BEGIN();
if (m_name.isEmpty())
emit(error("Name is empty"));
- TEST(setComputer, computer);
- TEST(setPlayer, player);
- TEST(setMaxWeight, maxWeight);
+ TEST(computer);
+ TEST(player);
+ TEST(maxWeight);
TEST_END();
}
@@ -90,64 +90,29 @@ QDomElement Sigmod::ItemType::save() const
return xml;
}
-void Sigmod::ItemType::setName(const QString& name)
-{
- CHECK(name);
-}
-
-void Sigmod::ItemType::setComputer(const int computer)
-{
- if (computer < -1)
- emit(error(bounds("computer", -1, INT_MAX, computer)));
- else
- CHECK(computer);
-}
-
-void Sigmod::ItemType::setPlayer(const int player)
-{
- if (player < 0)
- emit(error(bounds("player", 0, INT_MAX, player)));
- else
- CHECK(player);
-}
-
-void Sigmod::ItemType::setMaxWeight(const int maxWeight)
-{
- if ((maxWeight < -1) || ((sigmod()->rules()->maxTotalWeight() != -1) && (sigmod()->rules()->maxTotalWeight() < maxWeight)))
- emit(error(bounds("maxWeight", -1, (sigmod()->rules()->maxTotalWeight() == -1) ? INT_MAX : sigmod()->rules()->maxTotalWeight(), maxWeight)));
- else
- CHECK(maxWeight);
-}
-
-void Sigmod::ItemType::setCount(const Count count)
-{
- CHECK(count);
-}
-
-QString Sigmod::ItemType::name() const
-{
- return m_name;
-}
-
-int Sigmod::ItemType::computer() const
-{
- return m_computer;
-}
-
-int Sigmod::ItemType::player() const
-{
- return m_player;
-}
-
-int Sigmod::ItemType::maxWeight() const
-{
- return m_maxWeight;
-}
-
-Sigmod::ItemType::Count Sigmod::ItemType::count() const
-{
- return m_count;
-}
+SETTER(ItemType, QString&, Name, name)
+SETTER(ItemType, int, Computer, computer)
+SETTER(ItemType, int, Player, player)
+SETTER(ItemType, int, MaxWeight, maxWeight)
+SETTER(ItemType, Count, Count, count)
+
+GETTER(ItemType, QString, name)
+GETTER(ItemType, int, computer)
+GETTER(ItemType, int, player)
+GETTER(ItemType, int, maxWeight)
+GETTER(ItemType, Sigmod::ItemType::Count, count)
+
+CHECK_DEFAULT(ItemType, QString&, name)
+CHECK_BEGIN(ItemType, int, computer)
+ TBOUNDS(computer, -1, INT_MAX)
+CHECK_END()
+CHECK_BEGIN(ItemType, int, player)
+ TBOUNDS(player, 0, INT_MAX)
+CHECK_END()
+CHECK_BEGIN(ItemType, int, maxWeight)
+ TBOUNDS(maxWeight, -1, (sigmod()->rules()->maxTotalWeight() == -1) ? INT_MAX : sigmod()->rules()->maxTotalWeight())
+CHECK_END()
+CHECK_DEFAULT(ItemType, Count, count)
Sigmod::ItemType& Sigmod::ItemType::operator=(const ItemType& rhs)
{
diff --git a/sigmod/ItemType.h b/sigmod/ItemType.h
index 10a71530..28ec6a97 100644
--- a/sigmod/ItemType.h
+++ b/sigmod/ItemType.h
@@ -166,6 +166,12 @@ class SIGMOD_EXPORT ItemType : public Object
*/
Count count() const;
+ bool nameCheck(const QString& name) const;
+ bool computerCheck(const int computer) const;
+ bool playerCheck(const int player) const;
+ bool maxWeightCheck(const int maxWeight) const;
+ bool countCheck(const Count count) const;
+
ItemType& operator=(const ItemType& rhs);
private:
QString m_name;
diff --git a/sigmod/Map.cpp b/sigmod/Map.cpp
index 667b5524..0ab6e0ab 100644
--- a/sigmod/Map.cpp
+++ b/sigmod/Map.cpp
@@ -71,12 +71,10 @@ void Sigmod::Map::validate()
TEST_BEGIN();
if (m_name.isEmpty())
emit(error("Name is empty"));
- TEST(setFlyWarp, flyWarp);
- TEST(setType, type);
- if (!m_width)
- emit(error("Map has no width"));
- if (!m_height)
- emit(error("Map has no height"));
+ TEST(flyWarp);
+ TEST(type);
+ TEST(width);
+ TEST(height);
QSet<int> idChecker;
QSet<QString> nameChecker;
if (!effectCount())
@@ -147,64 +145,33 @@ QDomElement Sigmod::Map::save() const
return xml;
}
-void Sigmod::Map::setName(const QString& name)
-{
- CHECK(name);
-}
-
-void Sigmod::Map::setFlyWarp(const int flyWarp)
-{
- if ((flyWarp != -1) && !warpById(flyWarp))
- emit(error(bounds("flyWarp", flyWarp)));
- else
- CHECK(flyWarp);
-}
-
-void Sigmod::Map::setType(const Type type)
-{
- CHECK(type);
-}
-
-void Sigmod::Map::setWidth(const int width)
-{
- if (width <= 0)
- emit(error(bounds("width", 1, INT_MAX, width)));
- else
- CHECK(width);
-}
+SETTER(Map, QString&, Name, name)
+SETTER(Map, int, FlyWarp, flyWarp)
+SETTER(Map, Type, Type, type)
+SETTER(Map, int, Width, width)
+SETTER(Map, int, Height, height)
-void Sigmod::Map::setHeight(const int height)
-{
- if (height <= 0)
- emit(error(bounds("height", 1, INT_MAX, height)));
- else
- CHECK(height);
-}
+GETTER(Map, QString, name)
+GETTER(Map, int, flyWarp)
+GETTER(Map, Sigmod::Map::Type, type)
+GETTER(Map, int, width)
+GETTER(Map, int, height)
-QString Sigmod::Map::name() const
-{
- return m_name;
-}
-
-int Sigmod::Map::flyWarp() const
-{
- return m_flyWarp;
-}
-
-Sigmod::Map::Type Sigmod::Map::type() const
-{
- return m_type;
-}
-
-int Sigmod::Map::width() const
-{
- return m_width;
-}
-
-int Sigmod::Map::height() const
-{
- return m_height;
-}
+CHECK_DEFAULT(Map, QString&, name)
+CHECK_BEGIN(Map, int, flyWarp)
+ if ((flyWarp != -1) && !warpById(flyWarp))
+ {
+ EBOUNDS_IDX(flyWarp);
+ return false;
+ }
+CHECK_END()
+CHECK_DEFAULT(Map, Type, type)
+CHECK_BEGIN(Map, int, width)
+ TBOUNDS(width, 1, INT_MAX)
+CHECK_END()
+CHECK_BEGIN(Map, int, height)
+ TBOUNDS(height, 1, INT_MAX)
+CHECK_END()
const Sigmod::MapEffect* Sigmod::Map::effect(const int index) const
{
diff --git a/sigmod/Map.h b/sigmod/Map.h
index 8a62e2ba..1fc7108e 100644
--- a/sigmod/Map.h
+++ b/sigmod/Map.h
@@ -74,6 +74,12 @@ class SIGMOD_EXPORT Map : public Object
int width() const;
int height() const;
+ bool nameCheck(const QString& name) const;
+ bool flyWarpCheck(const int flyWarp) const;
+ bool typeCheck(const Type type) const;
+ bool widthCheck(const int width) const;
+ bool heightCheck(const int height) const;
+
const MapEffect* effect(const int index) const;
MapEffect* effect(const int index);
const MapEffect* effectById(const int id) const;
diff --git a/sigmod/MapTile.cpp b/sigmod/MapTile.cpp
index c407c5e2..d09f03db 100644
--- a/sigmod/MapTile.cpp
+++ b/sigmod/MapTile.cpp
@@ -58,8 +58,8 @@ Sigmod::MapTile::~MapTile()
void Sigmod::MapTile::validate()
{
TEST_BEGIN();
- TEST(setTile, tile);
- TEST(setPosition, position);
+ TEST(tile);
+ TEST(position);
TEST_END();
}
@@ -80,42 +80,21 @@ QDomElement Sigmod::MapTile::save() const
return xml;
}
-void Sigmod::MapTile::setTile(const int tile)
-{
- if (!sigmod()->tileById(tile))
- emit(error(bounds("tile", tile)));
- else
- CHECK(tile);
-}
+SETTER(MapTile, int, Tile, tile)
+SETTER(MapTile, QPoint&, Position, position)
+SETTER(MapTile, int, ZIndex, zIndex)
-void Sigmod::MapTile::setPosition(const QPoint& position)
-{
- const Map* map = qobject_cast<const Map*>(parent());
- if ((position.x() < 0) || (position.y() < 0) || (map->width() <= position.x()) || (map->height() <= position.y()))
- emit(error(bounds("position", QPoint(0, 0), QPoint(map->width(), map->height()), position)));
- else
- CHECK(position);
-}
+GETTER(MapTile, int, tile)
+GETTER(MapTile, QPoint, position)
+GETTER(MapTile, int, zIndex)
-void Sigmod::MapTile::setZIndex(const int zIndex)
-{
- CHECK(zIndex);
-}
-
-int Sigmod::MapTile::tile() const
-{
- return m_tile;
-}
-
-QPoint Sigmod::MapTile::position() const
-{
- return m_position;
-}
-
-int Sigmod::MapTile::zIndex() const
-{
- return m_zIndex;
-}
+CHECK_INDEX(MapTile, int, tile, sigmod(), tile)
+CHECK_BEGIN(MapTile, QPoint&, position)
+ const Map* map = qobject_cast<const Map*>(parent());
+ TBOUNDS_MOD(position, 0, map->width(), position.x())
+ TBOUNDS_MOD(position, 0, map->height(), position.y())
+CHECK_END()
+CHECK_DEFAULT(MapTile, int, zIndex)
Sigmod::MapTile& Sigmod::MapTile::operator=(const MapTile& rhs)
{
diff --git a/sigmod/MapTile.h b/sigmod/MapTile.h
index d7d51e93..4cf5af6c 100644
--- a/sigmod/MapTile.h
+++ b/sigmod/MapTile.h
@@ -47,6 +47,10 @@ class SIGMOD_EXPORT MapTile : public Object
QPoint position() const;
int zIndex() const;
+ bool tileCheck(const int tile) const;
+ bool positionCheck(const QPoint& position) const;
+ bool zIndexCheck(const int zIndex) const;
+
MapTile& operator=(const MapTile& rhs);
private:
int m_tile;