summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-12-26 12:20:08 -0500
committerBen Boeckel <MathStuf@gmail.com>2008-12-26 12:20:08 -0500
commitb7d4eb0356e9a1037a1599177cedefd4b2614e1d (patch)
tree16fe20f3b8cddb6a285d83f61474b824d5f773a6
parentd88d93e1e0d0d80b7c4f741a03bfe5b1976e930a (diff)
Added convenience macro for simple bounds checking
-rw-r--r--sigmod/Badge.cpp4
-rw-r--r--sigmod/CoinListItem.cpp4
-rw-r--r--sigmod/Item.cpp8
-rw-r--r--sigmod/ItemType.cpp12
-rw-r--r--sigmod/Macros.h4
-rw-r--r--sigmod/Map.cpp8
6 files changed, 13 insertions, 27 deletions
diff --git a/sigmod/Badge.cpp b/sigmod/Badge.cpp
index 23214bc9..d6cd3e16 100644
--- a/sigmod/Badge.cpp
+++ b/sigmod/Badge.cpp
@@ -121,9 +121,7 @@ GETTER_ARRAY_OFF(Badge, Sigcore::Fraction, stat, multiplier, Stat, stat, ST_Atta
CHECK(Badge, QString&, name)
CHECK_INDEX(Badge, int, face, sigmod(), sprite)
CHECK_INDEX(Badge, int, badge, sigmod(), sprite)
-CHECK_BEGIN(Badge, int, obey)
- TBOUNDS(obey, INT_MIN, sigmod()->rules()->maxLevel())
-CHECK_END()
+CHECK_BOUNDS(Badge, int, obey, INT_MIN, sigmod()->rules()->maxLevel())
CHECK_BEGIN_ARRAY(Badge, Sigcore::Fraction&, stat, multiplier, Stat, stat)
switch (stat)
{
diff --git a/sigmod/CoinListItem.cpp b/sigmod/CoinListItem.cpp
index f12bfc75..b631cb57 100644
--- a/sigmod/CoinListItem.cpp
+++ b/sigmod/CoinListItem.cpp
@@ -101,9 +101,7 @@ CHECK_BEGIN(CoinListItem, int, object)
break;
}
CHECK_END()
-CHECK_BEGIN(CoinListItem, int, cost)
- TBOUNDS(cost, 1, INT_MAX)
-CHECK_END()
+CHECK_BOUNDS(CoinListItem, int, cost, 1, INT_MAX)
Sigmod::CoinListItem& Sigmod::CoinListItem::operator=(const CoinListItem& rhs)
{
diff --git a/sigmod/Item.cpp b/sigmod/Item.cpp
index 4f426bfe..172660a8 100644
--- a/sigmod/Item.cpp
+++ b/sigmod/Item.cpp
@@ -124,12 +124,8 @@ GETTER(Item, Sigcore::Script, script)
CHECK(Item, QString&, name)
CHECK(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_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)
diff --git a/sigmod/ItemType.cpp b/sigmod/ItemType.cpp
index a1b26266..1a0b43f7 100644
--- a/sigmod/ItemType.cpp
+++ b/sigmod/ItemType.cpp
@@ -103,15 +103,9 @@ GETTER(ItemType, int, maxWeight)
GETTER(ItemType, Sigmod::ItemType::Count, count)
CHECK(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_BOUNDS(ItemType, int, computer, -1, INT_MAX)
+CHECK_BOUNDS(ItemType, int, player, 0, INT_MAX)
+CHECK_BOUNDS(ItemType, int, maxWeight, -1, (sigmod()->rules()->maxTotalWeight() == -1) ? INT_MAX : sigmod()->rules()->maxTotalWeight())
CHECK(ItemType, Count, count)
Sigmod::ItemType& Sigmod::ItemType::operator=(const ItemType& rhs)
diff --git a/sigmod/Macros.h b/sigmod/Macros.h
index 4be4f84c..435b236c 100644
--- a/sigmod/Macros.h
+++ b/sigmod/Macros.h
@@ -195,6 +195,10 @@ CHECK_END()
CHECK_BEGIN(class, type, variable) \
IBOUNDS(variable, pointer, subclass) \
CHECK_END()
+#define CHECK_BOUNDS(class, type, variable, min, max) \
+CHECK_BEGIN(class, type, variable) \
+ TBOUNDS(variable, (min), (max)) \
+CHECK_END()
#endif
diff --git a/sigmod/Map.cpp b/sigmod/Map.cpp
index 0f5ad1d9..c71bf552 100644
--- a/sigmod/Map.cpp
+++ b/sigmod/Map.cpp
@@ -166,12 +166,8 @@ CHECK_BEGIN(Map, int, flyWarp)
}
CHECK_END()
CHECK(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()
+CHECK_BOUNDS(Map, int, width, 1, INT_MAX)
+CHECK_BOUNDS(Map, int, height, 1, INT_MAX)
const Sigmod::MapEffect* Sigmod::Map::effect(const int index) const
{