diff options
author | frosch <frosch@openttd.org> | 2014-08-16 20:37:33 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2014-08-16 20:37:33 +0000 |
commit | c775ffe530c285862826377b83d85c8b959804e0 (patch) | |
tree | 717306bc12ce54a33df2b770e8e0250c77e6fe25 /src/script/api | |
parent | fcb9d433f5e81f9f1d1ea2a9db2a1d51eae49acb (diff) | |
download | openttd-c775ffe530c285862826377b83d85c8b959804e0.tar.xz |
(svn r26741) -Revert (r26736): reverse_iterators are invalidated when the element next to them is erased (not the element they are pointing to), which makes them unsuitable for ScriptList.
Diffstat (limited to 'src/script/api')
-rw-r--r-- | src/script/api/script_list.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp index f60db2c04..7add90c74 100644 --- a/src/script/api/script_list.cpp +++ b/src/script/api/script_list.cpp @@ -151,9 +151,9 @@ public: */ class ScriptListSorterValueDescending : public ScriptListSorter { private: - ScriptList::ScriptListBucket::reverse_iterator bucket_iter; ///< The iterator over the list to find the buckets. - ScriptList::ScriptItemList *bucket_list; ///< The current bucket list we're iterator over. - ScriptList::ScriptItemList::reverse_iterator bucket_list_iter; ///< The iterator over the bucket list. + ScriptList::ScriptListBucket::iterator bucket_iter; ///< The iterator over the list to find the buckets. + ScriptList::ScriptItemList *bucket_list; ///< The current bucket list we're iterator over. + ScriptList::ScriptItemList::iterator bucket_list_iter; ///< The iterator over the bucket list. public: /** @@ -172,11 +172,13 @@ public: this->has_no_more_items = false; /* Go to the end of the bucket-list */ - this->bucket_iter = this->list->buckets.rbegin(); + this->bucket_iter = this->list->buckets.begin(); + for (size_t i = this->list->buckets.size(); i > 1; i--) 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->rbegin(); + this->bucket_list_iter = this->bucket_list->begin(); + for (size_t i = this->bucket_list->size(); i > 1; i--) this->bucket_list_iter++; this->item_next = *this->bucket_list_iter; int32 item_current = this->item_next; @@ -201,15 +203,18 @@ public: return; } - this->bucket_list_iter++; - if (this->bucket_list_iter == this->bucket_list->rend()) { - this->bucket_iter++; - if (this->bucket_iter == this->list->buckets.rend()) { + 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; - this->bucket_list_iter = this->bucket_list->rbegin(); + /* 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++; + } else { + this->bucket_list_iter--; } this->item_next = *this->bucket_list_iter; } @@ -310,7 +315,7 @@ public: */ class ScriptListSorterItemDescending : public ScriptListSorter { private: - ScriptList::ScriptListMap::reverse_iterator item_iter; ///< The iterator over the items in the map. + ScriptList::ScriptListMap::iterator item_iter; ///< The iterator over the items in the map. public: /** @@ -328,7 +333,8 @@ public: if (this->list->items.empty()) return 0; this->has_no_more_items = false; - this->item_iter = this->list->items.rbegin(); + this->item_iter = this->list->items.begin(); + for (size_t i = this->list->items.size(); i > 1; i--) this->item_iter++; this->item_next = (*this->item_iter).first; int32 item_current = this->item_next; @@ -346,12 +352,12 @@ public: */ void FindNext() { - if (this->item_iter == this->list->items.rend()) { + if (this->item_iter == this->list->items.end()) { this->has_no_more_items = true; return; } - this->item_iter++; - if (this->item_iter != this->list->items.rend()) item_next = (*this->item_iter).first; + this->item_iter--; + if (this->item_iter != this->list->items.end()) item_next = (*this->item_iter).first; } int32 Next() |