mirror of https://github.com/OpenTTD/OpenTTD
(svn r26894) -Feature: Swap method for script lists
parent
2128f1e929
commit
1a5b2f0e17
|
@ -40,6 +40,7 @@ void SQAIList_Register(Squirrel *engine)
|
|||
SQAIList.DefSQMethod(engine, &ScriptList::SetValue, "SetValue", 3, "xii");
|
||||
SQAIList.DefSQMethod(engine, &ScriptList::Sort, "Sort", 3, "xib");
|
||||
SQAIList.DefSQMethod(engine, &ScriptList::AddList, "AddList", 2, "xx");
|
||||
SQAIList.DefSQMethod(engine, &ScriptList::SwapList, "SwapList", 2, "xx");
|
||||
SQAIList.DefSQMethod(engine, &ScriptList::RemoveAboveValue, "RemoveAboveValue", 2, "xi");
|
||||
SQAIList.DefSQMethod(engine, &ScriptList::RemoveBelowValue, "RemoveBelowValue", 2, "xi");
|
||||
SQAIList.DefSQMethod(engine, &ScriptList::RemoveBetweenValue, "RemoveBetweenValue", 3, "xii");
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
* 1.5.0 is not yet released. The following changes are not set in stone yet.
|
||||
*
|
||||
* API additions:
|
||||
* \li AIList::SwapList
|
||||
* \li AIStation::GetCargoPlanned
|
||||
* \li AIStation::GetCargoPlannedFrom
|
||||
* \li AIStation::GetCargoPlannedFromVia
|
||||
|
|
|
@ -40,6 +40,7 @@ void SQGSList_Register(Squirrel *engine)
|
|||
SQGSList.DefSQMethod(engine, &ScriptList::SetValue, "SetValue", 3, "xii");
|
||||
SQGSList.DefSQMethod(engine, &ScriptList::Sort, "Sort", 3, "xib");
|
||||
SQGSList.DefSQMethod(engine, &ScriptList::AddList, "AddList", 2, "xx");
|
||||
SQGSList.DefSQMethod(engine, &ScriptList::SwapList, "SwapList", 2, "xx");
|
||||
SQGSList.DefSQMethod(engine, &ScriptList::RemoveAboveValue, "RemoveAboveValue", 2, "xi");
|
||||
SQGSList.DefSQMethod(engine, &ScriptList::RemoveBelowValue, "RemoveBelowValue", 2, "xi");
|
||||
SQGSList.DefSQMethod(engine, &ScriptList::RemoveBetweenValue, "RemoveBetweenValue", 3, "xii");
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
* 1.5.0 is not yet released. The following changes are not set in stone yet.
|
||||
*
|
||||
* API additions:
|
||||
* \li GSList::SwapList
|
||||
* \li GSStation::GetCargoPlanned
|
||||
* \li GSStation::GetCargoPlannedFrom
|
||||
* \li GSStation::GetCargoPlannedFromVia
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -152,6 +152,12 @@ public:
|
|||
*/
|
||||
void AddList(ScriptList *list);
|
||||
|
||||
/**
|
||||
* Swap the contents of two lists.
|
||||
* @param list The list that will be swapped with.
|
||||
*/
|
||||
void SwapList(ScriptList *list);
|
||||
|
||||
/**
|
||||
* Removes all items with a higher value than 'value'.
|
||||
* @param value the value above which all items are removed.
|
||||
|
|
Loading…
Reference in New Issue