Class that creates a list which can keep item/value pairs, which you can walk. More...
#include <ai_list.hpp>
Public Types | |
enum | SorterType { SORT_BY_VALUE, SORT_BY_ITEM } |
Type of sorter. More... | |
typedef std::set< int32 > | AIItemList |
The list of items inside the bucket. | |
typedef std::map< int32, AIItemList > | AIListBucket |
The bucket list per value. | |
typedef std::map< int32, int32 > | AIListMap |
List per item. | |
Public Member Functions | |
void | AddItem (int32 item, int32 value=0) |
Add a single item to the list. | |
void | RemoveItem (int32 item) |
Remove a single item from the list. | |
void | Clear () |
Clear the list, making Count() returning 0 and IsEmpty() returning true. | |
bool | HasItem (int32 item) |
Check if an item is in the list. | |
int32 | Begin () |
Go to the beginning of the list. | |
int32 | Next () |
Go to the next item in the list. | |
bool | IsEmpty () |
Check if a list is empty. | |
bool | IsEnd () |
Check if there is a element left. | |
int32 | Count () |
Returns the amount of items in the list. | |
int32 | GetValue (int32 item) |
Get the value that belongs to this item. | |
bool | SetValue (int32 item, int32 value) |
Set a value of an item directly. | |
void | Sort (SorterType sorter, bool ascending) |
Sort this list by the given sorter and direction. | |
void | AddList (AIList *list) |
Add one list to another one. | |
void | RemoveAboveValue (int32 value) |
Removes all items with a higher value than 'value'. | |
void | RemoveBelowValue (int32 value) |
Removes all items with a lower value than 'value'. | |
void | RemoveBetweenValue (int32 start, int32 end) |
Removes all items with a value above start and below end. | |
void | RemoveValue (int32 value) |
Remove all items with this value. | |
void | RemoveTop (int32 count) |
Remove the first count items. | |
void | RemoveBottom (int32 count) |
Remove the last count items. | |
void | RemoveList (AIList *list) |
Remove everything that is in the given list from this list (same item index that is). | |
void | KeepAboveValue (int32 value) |
Keep all items with a higher value than 'value'. | |
void | KeepBelowValue (int32 value) |
Keep all items with a lower value than 'value'. | |
void | KeepBetweenValue (int32 start, int32 end) |
Keep all items with a value above start and below end. | |
void | KeepValue (int32 value) |
Keep all items with this value. | |
void | KeepTop (int32 count) |
Keep the first count items, i.e. | |
void | KeepBottom (int32 count) |
Keep the last count items, i.e. | |
void | KeepList (AIList *list) |
Keeps everything that is in the given list from this list (same item index that is). | |
SQInteger | _get (HSQUIRRELVM vm) |
Used for 'foreach()' and [] get from Squirrel. | |
SQInteger | _set (HSQUIRRELVM vm) |
Used for [] set from Squirrel. | |
SQInteger | _nexti (HSQUIRRELVM vm) |
Used for 'foreach()' from Squirrel. | |
SQInteger | Valuate (HSQUIRRELVM vm) |
The Valuate() wrapper from Squirrel. | |
Static Public Member Functions | |
static const char * | GetClassName () |
Get the name of this class to identify it towards squirrel. | |
Data Fields | |
AIListMap | items |
The items in the list. | |
AIListBucket | buckets |
The items in the list, sorted by value. | |
Static Public Attributes | |
static const bool | SORT_ASCENDING = true |
Sort ascending. | |
static const bool | SORT_DESCENDING = false |
Sort descnding. | |
Private Attributes | |
AIListSorter * | sorter |
Sorting algorithm. | |
SorterType | sorter_type |
Sorting type. | |
bool | sort_ascending |
Whether to sort ascending or descending. | |
bool | initialized |
Whether an iteration has been started. | |
int | modifications |
Number of modification that has been done. To prevent changing data while valuating. |
Class that creates a list which can keep item/value pairs, which you can walk.
Definition at line 25 of file ai_list.hpp.
enum AIList::SorterType |
Type of sorter.
SORT_BY_VALUE |
Sort the list based on the value of the item. |
SORT_BY_ITEM |
Sort the list based on the item itself. |
Definition at line 31 of file ai_list.hpp.
void AIList::AddItem | ( | int32 | item, | |
int32 | value = 0 | |||
) |
Add a single item to the list.
item | the item to add. Should be unique, otherwise it is ignored. | |
value | the value to assign. |
Definition at line 408 of file ai_list.cpp.
References buckets, HasItem(), items, modifications, and SetValue().
Referenced by _set(), AddList(), AITileList::AddRectangle(), AITileList::AddTile(), AIBridgeList_Length::AIBridgeList_Length(), AICargoList_IndustryAccepting::AICargoList_IndustryAccepting(), AICargoList_IndustryProducing::AICargoList_IndustryProducing(), AIDepotList::AIDepotList(), AIEngineList::AIEngineList(), AIIndustryList_CargoAccepting::AIIndustryList_CargoAccepting(), AIIndustryList_CargoProducing::AIIndustryList_CargoProducing(), AIStationList::AIStationList(), AIStationList_Vehicle::AIStationList_Vehicle(), AIVehicleList_DefaultGroup::AIVehicleList_DefaultGroup(), AIVehicleList_Depot::AIVehicleList_Depot(), AIVehicleList_Group::AIVehicleList_Group(), AIVehicleList_SharedOrders::AIVehicleList_SharedOrders(), AIVehicleList_Station::AIVehicleList_Station(), AIWaypointList::AIWaypointList(), AIWaypointList_Vehicle::AIWaypointList_Vehicle(), and KeepList().
void AIList::AddList | ( | AIList * | list | ) |
Add one list to another one.
list | The list that will be added to the caller. |
Definition at line 527 of file ai_list.cpp.
References AddItem(), items, and SetValue().
int32 AIList::Begin | ( | ) |
Go to the beginning of the list.
Definition at line 434 of file ai_list.cpp.
References AIListSorter::Begin(), initialized, and sorter.
Referenced by _nexti().
int32 AIList::Count | ( | ) |
Returns the amount of items in the list.
Definition at line 463 of file ai_list.cpp.
References items.
Referenced by KeepBottom(), and KeepTop().
static const char* AIList::GetClassName | ( | ) | [inline, static] |
Get the name of this class to identify it towards squirrel.
Reimplemented in AIBridgeList, AIBridgeList_Length, AICargoList, AICargoList_IndustryAccepting, AICargoList_IndustryProducing, AIDepotList, AIEngineList, AIGroupList, AIIndustryList, AIIndustryList_CargoAccepting, AIIndustryList_CargoProducing, AIIndustryTypeList, AIRailTypeList, AISignList, AIStationList, AIStationList_Vehicle, AISubsidyList, AITileList, AITileList_IndustryAccepting, AITileList_IndustryProducing, AITileList_StationType, AITownList, AIVehicleList, AIVehicleList_Station, AIVehicleList_Depot, AIVehicleList_SharedOrders, AIVehicleList_Group, AIVehicleList_DefaultGroup, AIWaypointList, and AIWaypointList_Vehicle.
Definition at line 28 of file ai_list.hpp.
int32 AIList::GetValue | ( | int32 | item | ) |
Get the value that belongs to this item.
item | the item to get the value from |
Definition at line 468 of file ai_list.cpp.
References HasItem(), and items.
Referenced by _get(), RemoveItem(), and SetValue().
bool AIList::HasItem | ( | int32 | item | ) |
Check if an item is in the list.
item | the item to check for. |
Definition at line 394 of file ai_list.cpp.
References items.
Referenced by _get(), _set(), AddItem(), GetValue(), RemoveItem(), and SetValue().
bool AIList::IsEmpty | ( | ) |
Check if a list is empty.
Definition at line 449 of file ai_list.cpp.
References items.
Referenced by _nexti().
bool AIList::IsEnd | ( | ) |
Check if there is a element left.
In other words, if this is false, the last call to Begin() or Next() returned a valid item.
Definition at line 454 of file ai_list.cpp.
References DEBUG, initialized, AIListSorter::IsEnd(), and sorter.
Referenced by _nexti().
void AIList::KeepAboveValue | ( | int32 | value | ) |
Keep all items with a higher value than 'value'.
value | the value above which all items are kept. |
Definition at line 659 of file ai_list.cpp.
References items, modifications, and RemoveItem().
void AIList::KeepBelowValue | ( | int32 | value | ) |
Keep all items with a lower value than 'value'.
value | the value below which all items are kept. |
Definition at line 669 of file ai_list.cpp.
References items, modifications, and RemoveItem().
void AIList::KeepBetweenValue | ( | int32 | start, | |
int32 | end | |||
) |
Keep all items with a value above start and below end.
start | the lower bound of the to be kept values (exclusive). | |
end | the upper bound of the to be kept values (exclusive). |
Definition at line 679 of file ai_list.cpp.
References items, modifications, and RemoveItem().
void AIList::KeepBottom | ( | int32 | count | ) |
Keep the last count items, i.e.
remove everything except the last count items.
count | the amount of items to keep. |
Definition at line 706 of file ai_list.cpp.
References Count(), modifications, and RemoveTop().
void AIList::KeepList | ( | AIList * | list | ) |
Keeps everything that is in the given list from this list (same item index that is).
list | the list of items to keep. |
Definition at line 713 of file ai_list.cpp.
References AddItem(), items, modifications, RemoveList(), and SetValue().
void AIList::KeepTop | ( | int32 | count | ) |
Keep the first count items, i.e.
remove everything except the first count items.
count | the amount of items to keep. |
Definition at line 699 of file ai_list.cpp.
References Count(), modifications, and RemoveBottom().
void AIList::KeepValue | ( | int32 | value | ) |
Keep all items with this value.
value | the value to keep. |
Definition at line 689 of file ai_list.cpp.
References items, modifications, and RemoveItem().
int32 AIList::Next | ( | ) |
Go to the next item in the list.
Definition at line 440 of file ai_list.cpp.
References DEBUG, initialized, AIListSorter::Next(), and sorter.
Referenced by _nexti().
void AIList::RemoveAboveValue | ( | int32 | value | ) |
Removes all items with a higher value than 'value'.
value | the value above which all items are removed. |
Definition at line 536 of file ai_list.cpp.
References items, modifications, and RemoveItem().
void AIList::RemoveBelowValue | ( | int32 | value | ) |
Removes all items with a lower value than 'value'.
value | the value below which all items are removed. |
Definition at line 546 of file ai_list.cpp.
References items, modifications, and RemoveItem().
void AIList::RemoveBetweenValue | ( | int32 | start, | |
int32 | end | |||
) |
Removes all items with a value above start and below end.
start | the lower bound of the to be removed values (exclusive). | |
end | the upper bound of the to be removed valuens (exclusive). |
Definition at line 556 of file ai_list.cpp.
References items, modifications, and RemoveItem().
void AIList::RemoveBottom | ( | int32 | count | ) |
Remove the last count items.
count | the amount of items to remove. |
Definition at line 613 of file ai_list.cpp.
References buckets, items, modifications, RemoveItem(), RemoveTop(), Sort(), sort_ascending, SORT_BY_ITEM, SORT_BY_VALUE, and sorter_type.
Referenced by KeepTop(), and RemoveTop().
void AIList::RemoveItem | ( | int32 | item | ) |
Remove a single item from the list.
item | the item to remove. If not existing, it is ignored. |
Definition at line 420 of file ai_list.cpp.
References buckets, GetValue(), HasItem(), items, modifications, AIListSorter::Remove(), and sorter.
Referenced by _set(), KeepAboveValue(), KeepBelowValue(), KeepBetweenValue(), KeepValue(), RemoveAboveValue(), RemoveBelowValue(), RemoveBetweenValue(), RemoveBottom(), RemoveList(), AITileList::RemoveRectangle(), AITileList::RemoveTile(), RemoveTop(), and RemoveValue().
void AIList::RemoveList | ( | AIList * | list | ) |
Remove everything that is in the given list from this list (same item index that is).
list | the list of items to remove. |
Definition at line 649 of file ai_list.cpp.
References items, modifications, and RemoveItem().
Referenced by KeepList().
void AIList::RemoveTop | ( | int32 | count | ) |
Remove the first count items.
count | the amount of items to remove. |
Definition at line 576 of file ai_list.cpp.
References buckets, items, modifications, RemoveBottom(), RemoveItem(), Sort(), sort_ascending, SORT_BY_ITEM, SORT_BY_VALUE, and sorter_type.
Referenced by KeepBottom(), and RemoveBottom().
void AIList::RemoveValue | ( | int32 | value | ) |
Remove all items with this value.
value | the value to remove. |
Definition at line 566 of file ai_list.cpp.
References items, modifications, and RemoveItem().
bool AIList::SetValue | ( | int32 | item, | |
int32 | value | |||
) |
Set a value of an item directly.
item | the item to set the value for. | |
value | the value to give to the item |
Definition at line 475 of file ai_list.cpp.
References buckets, GetValue(), HasItem(), items, modifications, AIListSorter::Remove(), and sorter.
Referenced by _set(), AddItem(), AddList(), KeepList(), and Valuate().
void AIList::Sort | ( | SorterType | sorter, | |
bool | ascending | |||
) |
Sort this list by the given sorter and direction.
sorter | the type of sorter to use | |
ascending | if true, lowest value is on top, else at bottom. |
Definition at line 493 of file ai_list.cpp.
References initialized, modifications, sort_ascending, SORT_BY_ITEM, SORT_BY_VALUE, and sorter_type.
Referenced by RemoveBottom(), and RemoveTop().