(svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too noai
authortruebrain
Mon, 23 Jun 2008 16:23:36 +0000
branchnoai
changeset 11059 b1751c5973cc
parent 11058 3305a425f55b
child 11063 bd71d932973e
(svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
src/ai/api/ai_abstractlist.cpp
--- a/src/ai/api/ai_abstractlist.cpp	Mon Jun 23 13:52:21 2008 +0000
+++ b/src/ai/api/ai_abstractlist.cpp	Mon Jun 23 16:23:36 2008 +0000
@@ -26,6 +26,11 @@
 	virtual int32 Begin() = 0;
 
 	/**
+	 * Stop iterating a sorter.
+	 */
+	virtual void End() = 0;
+
+	/**
 	 * Get the next item of the sorter.
 	 */
 	virtual int32 Next() = 0;
@@ -56,10 +61,7 @@
 	AIAbstractListSorterValueAscending(AIAbstractList *list)
 	{
 		this->list = list;
-		this->bucket_list = NULL;
-		this->has_no_more_items = true;
-
-		this->item_next = 0;
+		this->End();
 	}
 
 	int32 Begin()
@@ -77,6 +79,13 @@
 		return item_current;
 	}
 
+	void End()
+	{
+		this->bucket_list = NULL;
+		this->has_no_more_items = true;
+		this->item_next = 0;
+	}
+
 	void FindNext()
 	{
 		if (this->bucket_list == NULL) {
@@ -138,10 +147,7 @@
 	AIAbstractListSorterValueDescending(AIAbstractList *list)
 	{
 		this->list = list;
-		this->bucket_list = NULL;
-		this->has_no_more_items = true;
-
-		this->item_next = 0;
+		this->End();
 	}
 
 	int32 Begin()
@@ -164,6 +170,12 @@
 		return item_current;
 	}
 
+	void End() {
+		this->bucket_list = NULL;
+		this->has_no_more_items = true;
+		this->item_next = 0;
+	}
+
 	void FindNext()
 	{
 		if (this->bucket_list == NULL) {
@@ -226,7 +238,7 @@
 	AIAbstractListSorterItemAscending(AIAbstractList *list)
 	{
 		this->list = list;
-		this->has_no_more_items = true;
+		this->End();
 	}
 
 	int32 Begin()
@@ -242,6 +254,11 @@
 		return item_current;
 	}
 
+	void End()
+	{
+		this->has_no_more_items = true;
+	}
+
 	void FindNext()
 	{
 		if (this->item_iter == this->list->items.end()) {
@@ -290,7 +307,7 @@
 	AIAbstractListSorterItemDescending(AIAbstractList *list)
 	{
 		this->list = list;
-		this->has_no_more_items = true;
+		this->End();
 	}
 
 	int32 Begin()
@@ -306,6 +323,11 @@
 		return item_current;
 	}
 
+	void End()
+	{
+		this->has_no_more_items = true;
+	}
+
 	void FindNext()
 	{
 		if (this->item_iter == this->list->items.rend()) {
@@ -367,6 +389,7 @@
 {
 	this->items.clear();
 	this->buckets.clear();
+	this->sorter->End();
 }
 
 void AIAbstractList::AddItem(int32 item)