summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-02-28 20:25:03 +0000
committerfrosch <frosch@openttd.org>2010-02-28 20:25:03 +0000
commit333249ce501085405afabac8eb61a2c3ed599c0f (patch)
tree1892303233cef8b6bf22b985f142c9ef3d2bfbe6 /src
parentac1a08ef4ad2414491b050b374714d7313373c1f (diff)
downloadopenttd-333249ce501085405afabac8eb61a2c3ed599c0f.tar.xz
(svn r19294) -Change: [NoAI] Remove HasNext() from all lists/iterators and add IsEnd() instead.
Diffstat (limited to 'src')
-rw-r--r--src/ai/api/ai_abstractlist.cpp46
-rw-r--r--src/ai/api/ai_abstractlist.hpp11
-rw-r--r--src/ai/api/ai_abstractlist.hpp.sq2
-rw-r--r--src/ai/api/ai_changelog.hpp6
4 files changed, 36 insertions, 29 deletions
diff --git a/src/ai/api/ai_abstractlist.cpp b/src/ai/api/ai_abstractlist.cpp
index 9aeff4fc4..e169f5ef6 100644
--- a/src/ai/api/ai_abstractlist.cpp
+++ b/src/ai/api/ai_abstractlist.cpp
@@ -42,9 +42,9 @@ public:
virtual int32 Next() = 0;
/**
- * See if there is a next item of the sorter.
+ * See if the sorter has reached the end.
*/
- virtual bool HasNext() = 0;
+ virtual bool IsEnd() = 0;
/**
* Callback from the list if an item gets removed.
@@ -114,7 +114,7 @@ public:
int32 Next()
{
- if (!this->HasNext()) return 0;
+ if (this->IsEnd()) return 0;
int32 item_current = this->item_next;
FindNext();
@@ -123,7 +123,7 @@ public:
void Remove(int item)
{
- if (!this->HasNext()) return;
+ if (this->IsEnd()) return;
/* If we remove the 'next' item, skip to the next */
if (item == this->item_next) {
@@ -132,9 +132,9 @@ public:
}
}
- bool HasNext()
+ bool IsEnd()
{
- return !(this->list->buckets.empty() || this->has_no_more_items);
+ return this->list->buckets.empty() || this->has_no_more_items;
}
};
@@ -208,7 +208,7 @@ public:
int32 Next()
{
- if (!this->HasNext()) return 0;
+ if (this->IsEnd()) return 0;
int32 item_current = this->item_next;
FindNext();
@@ -217,7 +217,7 @@ public:
void Remove(int item)
{
- if (!this->HasNext()) return;
+ if (this->IsEnd()) return;
/* If we remove the 'next' item, skip to the next */
if (item == this->item_next) {
@@ -226,9 +226,9 @@ public:
}
}
- bool HasNext()
+ bool IsEnd()
{
- return !(this->list->buckets.empty() || this->has_no_more_items);
+ return this->list->buckets.empty() || this->has_no_more_items;
}
};
@@ -278,7 +278,7 @@ public:
int32 Next()
{
- if (!this->HasNext()) return 0;
+ if (this->IsEnd()) return 0;
int32 item_current = this->item_next;
FindNext();
@@ -287,7 +287,7 @@ public:
void Remove(int item)
{
- if (!this->HasNext()) return;
+ if (this->IsEnd()) return;
/* If we remove the 'next' item, skip to the next */
if (item == this->item_next) {
@@ -296,9 +296,9 @@ public:
}
}
- bool HasNext()
+ bool IsEnd()
{
- return !(this->list->items.empty() || this->has_no_more_items);
+ return this->list->items.empty() || this->has_no_more_items;
}
};
@@ -349,7 +349,7 @@ public:
int32 Next()
{
- if (!this->HasNext()) return 0;
+ if (this->IsEnd()) return 0;
int32 item_current = this->item_next;
FindNext();
@@ -358,7 +358,7 @@ public:
void Remove(int item)
{
- if (!this->HasNext()) return;
+ if (this->IsEnd()) return;
/* If we remove the 'next' item, skip to the next */
if (item == this->item_next) {
@@ -367,9 +367,9 @@ public:
}
}
- bool HasNext()
+ bool IsEnd()
{
- return !(this->list->items.empty() || this->has_no_more_items);
+ return this->list->items.empty() || this->has_no_more_items;
}
};
@@ -448,13 +448,13 @@ bool AIAbstractList::IsEmpty()
return this->items.empty();
}
-bool AIAbstractList::HasNext()
+bool AIAbstractList::IsEnd()
{
if (this->initialized == false) {
- DEBUG(ai, 0, "HasNext() is invalid as Begin() is never called");
- return false;
+ DEBUG(ai, 0, "IsEnd() is invalid as Begin() is never called");
+ return true;
}
- return this->sorter->HasNext();
+ return this->sorter->IsEnd();
}
int32 AIAbstractList::Count()
@@ -748,7 +748,7 @@ SQInteger AIAbstractList::_nexti(HSQUIRRELVM vm)
sq_getinteger(vm, 2, &idx);
int val = this->Next();
- if (!this->HasNext()) {
+ if (this->IsEnd()) {
sq_pushnull(vm);
return 1;
}
diff --git a/src/ai/api/ai_abstractlist.hpp b/src/ai/api/ai_abstractlist.hpp
index bf4c9897d..ab3b4925a 100644
--- a/src/ai/api/ai_abstractlist.hpp
+++ b/src/ai/api/ai_abstractlist.hpp
@@ -86,13 +86,14 @@ public:
/**
* Go to the beginning of the list.
* @return the item value of the first item.
+ * @note returns 0 if beyond end-of-list. Use IsEnd() to check for end-of-list.
*/
int32 Begin();
/**
* Go to the next item in the list.
* @return the item value of the next item.
- * @note returns 0 if beyond end-of-list. Use HasNext() to check for end-of-list.
+ * @note returns 0 if beyond end-of-list. Use IsEnd() to check for end-of-list.
*/
int32 Next();
@@ -103,11 +104,11 @@ public:
bool IsEmpty();
/**
- * Check if there is a next element. In other words, if this is true,
- * Next() will return a valid item.
- * @return true if there is a next item.
+ * Check if there is a element left. In other words, if this is false,
+ * the last call to Begin() or Next() returned a valid item.
+ * @return true if the current item is beyond end-of-list.
*/
- bool HasNext();
+ bool IsEnd();
/**
* Returns the amount of items in the list.
diff --git a/src/ai/api/ai_abstractlist.hpp.sq b/src/ai/api/ai_abstractlist.hpp.sq
index 22b8977c7..aaa8503a1 100644
--- a/src/ai/api/ai_abstractlist.hpp.sq
+++ b/src/ai/api/ai_abstractlist.hpp.sq
@@ -41,7 +41,7 @@ void SQAIAbstractList_Register(Squirrel *engine)
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::Begin, "Begin", 1, "x");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::Next, "Next", 1, "x");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::IsEmpty, "IsEmpty", 1, "x");
- SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::HasNext, "HasNext", 1, "x");
+ SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::IsEnd, "IsEnd", 1, "x");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::Count, "Count", 1, "x");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::GetValue, "GetValue", 2, "xi");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::SetValue, "SetValue", 3, "xii");
diff --git a/src/ai/api/ai_changelog.hpp b/src/ai/api/ai_changelog.hpp
index 16b9505b7..4c0f7f876 100644
--- a/src/ai/api/ai_changelog.hpp
+++ b/src/ai/api/ai_changelog.hpp
@@ -18,6 +18,12 @@
*
* 1.1.0 is not yet released. The following changes are not set in stone yet.
*
+ * API additions:
+ * \li IsEnd for all lists.
+ *
+ * API removals:
+ * \li HasNext for all lists.
+ *
* Other changes:
* \li AIRoad::BuildRoadStation now allows overbuilding
* \li AIRoad::BuildDriveThroughRoadStation now allows overbuilding