summaryrefslogtreecommitdiffstats
path: root/sigmod/Item.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-12-29 12:09:27 -0500
committerBen Boeckel <MathStuf@gmail.com>2008-12-29 12:09:27 -0500
commit8e278873d4bd35a7cd7f3b6d9d7852fa422370b8 (patch)
tree9e97b71d30779c07c79ca166e1d704a3de4d5e4f /sigmod/Item.cpp
parente801b73a2f9cb845913cf546002c8f50eefc473c (diff)
Merged CHECK macro branch
Diffstat (limited to 'sigmod/Item.cpp')
-rw-r--r--sigmod/Item.cpp129
1 files changed, 32 insertions, 97 deletions
diff --git a/sigmod/Item.cpp b/sigmod/Item.cpp
index e6f521dd..0ac9f360 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,36 @@ 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(Item, QString&, name)
+CHECK(Item, bool, sellable)
+CHECK_INDEX(Item, int, type, sigmod(), itemType)
+CHECK_BOUNDS(Item, int, price, 1, sigmod()->rules()->maxMoney())
+CHECK_BOUNDS(Item, int, sellPrice, 0, m_price)
+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(Item, QString&, description)
+CHECK(Item, Sigcore::Script&, script)
Sigmod::Item& Sigmod::Item::operator=(const Item& rhs)
{