summaryrefslogtreecommitdiff
path: root/src/script/api/script_list.cpp
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2014-09-21 16:25:15 +0000
committerfonsinchen <fonsinchen@openttd.org>2014-09-21 16:25:15 +0000
commit1a5b2f0e17c5e694401e4d3730ed348e9f6d5f76 (patch)
tree5da4da1b8ae7c4c5b201583a93b55adc63174905 /src/script/api/script_list.cpp
parent2128f1e92906563fc7237b8a43f6fa723de70e7c (diff)
downloadopenttd-1a5b2f0e17c5e694401e4d3730ed348e9f6d5f76.tar.xz
(svn r26894) -Feature: Swap method for script lists
Diffstat (limited to 'src/script/api/script_list.cpp')
-rw-r--r--src/script/api/script_list.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp
index cd605a509..22da0abf2 100644
--- a/src/script/api/script_list.cpp
+++ b/src/script/api/script_list.cpp
@@ -58,6 +58,17 @@ public:
* Callback from the list if an item gets removed.
*/
virtual void Remove(int item) = 0;
+
+ /**
+ * Attach the sorter to a new list. This assumes the content of the old list has been moved to
+ * the new list, too, so that we don't have to invalidate any iterators. Note that std::swap
+ * doesn't invalidate iterators on lists and maps, so that should be safe.
+ * @param target New list to attach to.
+ */
+ virtual void Retarget(ScriptList *new_list)
+ {
+ this->list = new_list;
+ }
};
/**
@@ -549,6 +560,19 @@ void ScriptList::AddList(ScriptList *list)
}
}
+void ScriptList::SwapList(ScriptList *list)
+{
+ this->items.swap(list->items);
+ this->buckets.swap(list->buckets);
+ Swap(this->sorter, list->sorter);
+ Swap(this->sorter_type, list->sorter_type);
+ Swap(this->sort_ascending, list->sort_ascending);
+ Swap(this->initialized, list->initialized);
+ Swap(this->modifications, list->modifications);
+ this->sorter->Retarget(this);
+ list->sorter->Retarget(list);
+}
+
void ScriptList::RemoveAboveValue(int32 value)
{
this->modifications++;