Changeset - r21611:0289944dc38c
[Not reviewed]
master
0 1 0
frosch - 10 years ago 2014-08-16 21:11:26
frosch@openttd.org
(svn r26743) -Codechange: Simplify ScriptList iterators.
1 file changed with 8 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_list.cpp
Show inline comments
 
@@ -166,31 +166,31 @@ public:
 
	ScriptListSorterValueDescending(ScriptList *list)
 
	{
 
		this->list = list;
 
		this->End();
 
	}
 

	
 
	int32 Begin()
 
	{
 
		if (this->list->buckets.empty()) return 0;
 
		this->has_no_more_items = false;
 

	
 
		/* Go to the end of the bucket-list */
 
		this->bucket_iter = this->list->buckets.begin();
 
		for (size_t i = this->list->buckets.size(); i > 1; i--) this->bucket_iter++;
 
		this->bucket_iter = this->list->buckets.end();
 
		--this->bucket_iter;
 
		this->bucket_list = &(*this->bucket_iter).second;
 

	
 
		/* Go to the end of the items in the bucket */
 
		this->bucket_list_iter = this->bucket_list->begin();
 
		for (size_t i = this->bucket_list->size(); i > 1; i--) this->bucket_list_iter++;
 
		this->bucket_list_iter = this->bucket_list->end();
 
		--this->bucket_list_iter;
 
		this->item_next = *this->bucket_list_iter;
 

	
 
		int32 item_current = this->item_next;
 
		FindNext();
 
		return item_current;
 
	}
 

	
 
	void End()
 
	{
 
		this->bucket_list = NULL;
 
		this->has_no_more_items = true;
 
		this->item_next = 0;
 
@@ -205,26 +205,26 @@ public:
 
			this->has_no_more_items = true;
 
			return;
 
		}
 

	
 
		if (this->bucket_list_iter == this->bucket_list->begin()) {
 
			if (this->bucket_iter == this->list->buckets.begin()) {
 
				this->bucket_list = NULL;
 
				return;
 
			}
 
			this->bucket_iter--;
 
			this->bucket_list = &(*this->bucket_iter).second;
 
			/* Go to the end of the items in the bucket */
 
			this->bucket_list_iter = this->bucket_list->begin();
 
			for (size_t i = this->bucket_list->size(); i > 1; i--) this->bucket_list_iter++;
 
			this->bucket_list_iter = this->bucket_list->end();
 
			--this->bucket_list_iter;
 
		} else {
 
			this->bucket_list_iter--;
 
		}
 
		this->item_next = *this->bucket_list_iter;
 
	}
 

	
 
	int32 Next()
 
	{
 
		if (this->IsEnd()) return 0;
 

	
 
		int32 item_current = this->item_next;
 
		FindNext();
 
@@ -330,26 +330,26 @@ public:
 
	 */
 
	ScriptListSorterItemDescending(ScriptList *list)
 
	{
 
		this->list = list;
 
		this->End();
 
	}
 

	
 
	int32 Begin()
 
	{
 
		if (this->list->items.empty()) return 0;
 
		this->has_no_more_items = false;
 

	
 
		this->item_iter = this->list->items.begin();
 
		for (size_t i = this->list->items.size(); i > 1; i--) this->item_iter++;
 
		this->item_iter = this->list->items.end();
 
		--this->item_iter;
 
		this->item_next = (*this->item_iter).first;
 

	
 
		int32 item_current = this->item_next;
 
		FindNext();
 
		return item_current;
 
	}
 

	
 
	void End()
 
	{
 
		this->has_no_more_items = true;
 
	}
 

	
0 comments (0 inline, 0 general)