# HG changeset patch # User glx22 # Date 2023-03-04 14:51:01 # Node ID 2bcc83b9befeb9f997ccbd5f90bc71443c854543 # Parent 131f5c8aa3cb3b619296c41ee7f5c723f4e63190 Codechange: Use SQInteger for generic numbers in script_list diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp --- a/src/script/api/script_list.cpp +++ b/src/script/api/script_list.cpp @@ -22,7 +22,7 @@ class ScriptListSorter { protected: ScriptList *list; ///< The list that's being sorted. bool has_no_more_items; ///< Whether we have more items to iterate over. - int64 item_next; ///< The next item we will show. + SQInteger item_next; ///< The next item we will show. public: /** @@ -33,7 +33,7 @@ public: /** * Get the first item of the sorter. */ - virtual int64 Begin() = 0; + virtual SQInteger Begin() = 0; /** * Stop iterating a sorter. @@ -43,7 +43,7 @@ public: /** * Get the next item of the sorter. */ - virtual int64 Next() = 0; + virtual SQInteger Next() = 0; /** * See if the sorter has reached the end. @@ -56,7 +56,7 @@ public: /** * Callback from the list if an item gets removed. */ - virtual void Remove(int item) = 0; + virtual void Remove(SQInteger item) = 0; /** * Attach the sorter to a new list. This assumes the content of the old list has been moved to @@ -90,7 +90,7 @@ public: this->End(); } - int64 Begin() + SQInteger Begin() { if (this->list->buckets.empty()) return 0; this->has_no_more_items = false; @@ -100,7 +100,7 @@ public: this->bucket_list_iter = this->bucket_list->begin(); this->item_next = *this->bucket_list_iter; - int64 item_current = this->item_next; + SQInteger item_current = this->item_next; FindNext(); return item_current; } @@ -135,16 +135,16 @@ public: this->item_next = *this->bucket_list_iter; } - int64 Next() + SQInteger Next() { if (this->IsEnd()) return 0; - int64 item_current = this->item_next; + SQInteger item_current = this->item_next; FindNext(); return item_current; } - void Remove(int item) + void Remove(SQInteger item) { if (this->IsEnd()) return; @@ -179,7 +179,7 @@ public: this->End(); } - int64 Begin() + SQInteger Begin() { if (this->list->buckets.empty()) return 0; this->has_no_more_items = false; @@ -194,7 +194,7 @@ public: --this->bucket_list_iter; this->item_next = *this->bucket_list_iter; - int64 item_current = this->item_next; + SQInteger item_current = this->item_next; FindNext(); return item_current; } @@ -232,16 +232,16 @@ public: this->item_next = *this->bucket_list_iter; } - int64 Next() + SQInteger Next() { if (this->IsEnd()) return 0; - int64 item_current = this->item_next; + SQInteger item_current = this->item_next; FindNext(); return item_current; } - void Remove(int item) + void Remove(SQInteger item) { if (this->IsEnd()) return; @@ -271,7 +271,7 @@ public: this->End(); } - int64 Begin() + SQInteger Begin() { if (this->list->items.empty()) return 0; this->has_no_more_items = false; @@ -279,7 +279,7 @@ public: this->item_iter = this->list->items.begin(); this->item_next = (*this->item_iter).first; - int64 item_current = this->item_next; + SQInteger item_current = this->item_next; FindNext(); return item_current; } @@ -302,16 +302,16 @@ public: if (this->item_iter != this->list->items.end()) item_next = (*this->item_iter).first; } - int64 Next() + SQInteger Next() { if (this->IsEnd()) return 0; - int64 item_current = this->item_next; + SQInteger item_current = this->item_next; FindNext(); return item_current; } - void Remove(int item) + void Remove(SQInteger item) { if (this->IsEnd()) return; @@ -344,7 +344,7 @@ public: this->End(); } - int64 Begin() + SQInteger Begin() { if (this->list->items.empty()) return 0; this->has_no_more_items = false; @@ -353,7 +353,7 @@ public: --this->item_iter; this->item_next = (*this->item_iter).first; - int64 item_current = this->item_next; + SQInteger item_current = this->item_next; FindNext(); return item_current; } @@ -381,16 +381,16 @@ public: if (this->item_iter != this->list->items.end()) item_next = (*this->item_iter).first; } - int64 Next() + SQInteger Next() { if (this->IsEnd()) return 0; - int64 item_current = this->item_next; + SQInteger item_current = this->item_next; FindNext(); return item_current; } - void Remove(int item) + void Remove(SQInteger item) { if (this->IsEnd()) return; @@ -419,7 +419,7 @@ ScriptList::~ScriptList() delete this->sorter; } -bool ScriptList::HasItem(int64 item) +bool ScriptList::HasItem(SQInteger item) { return this->items.count(item) == 1; } @@ -433,7 +433,7 @@ void ScriptList::Clear() this->sorter->End(); } -void ScriptList::AddItem(int64 item, int64 value) +void ScriptList::AddItem(SQInteger item, SQInteger value) { this->modifications++; @@ -443,14 +443,14 @@ void ScriptList::AddItem(int64 item, int this->buckets[value].insert(item); } -void ScriptList::RemoveItem(int64 item) +void ScriptList::RemoveItem(SQInteger item) { this->modifications++; ScriptListMap::iterator item_iter = this->items.find(item); if (item_iter == this->items.end()) return; - int64 value = item_iter->second; + SQInteger value = item_iter->second; this->sorter->Remove(item); ScriptListBucket::iterator bucket_iter = this->buckets.find(value); @@ -460,13 +460,13 @@ void ScriptList::RemoveItem(int64 item) this->items.erase(item_iter); } -int64 ScriptList::Begin() +SQInteger ScriptList::Begin() { this->initialized = true; return this->sorter->Begin(); } -int64 ScriptList::Next() +SQInteger ScriptList::Next() { if (!this->initialized) { Debug(script, 0, "Next() is invalid as Begin() is never called"); @@ -489,25 +489,25 @@ bool ScriptList::IsEnd() return this->sorter->IsEnd(); } -int32 ScriptList::Count() +SQInteger ScriptList::Count() { - return (int32)this->items.size(); + return this->items.size(); } -int64 ScriptList::GetValue(int64 item) +SQInteger ScriptList::GetValue(SQInteger item) { ScriptListMap::const_iterator item_iter = this->items.find(item); return item_iter == this->items.end() ? 0 : item_iter->second; } -bool ScriptList::SetValue(int64 item, int64 value) +bool ScriptList::SetValue(SQInteger item, SQInteger value) { this->modifications++; ScriptListMap::iterator item_iter = this->items.find(item); if (item_iter == this->items.end()) return false; - int64 value_old = item_iter->second; + SQInteger value_old = item_iter->second; if (value_old == value) return true; this->sorter->Remove(item); @@ -586,7 +586,7 @@ void ScriptList::SwapList(ScriptList *li list->sorter->Retarget(list); } -void ScriptList::RemoveAboveValue(int64 value) +void ScriptList::RemoveAboveValue(SQInteger value) { this->modifications++; @@ -596,7 +596,7 @@ void ScriptList::RemoveAboveValue(int64 } } -void ScriptList::RemoveBelowValue(int64 value) +void ScriptList::RemoveBelowValue(SQInteger value) { this->modifications++; @@ -606,7 +606,7 @@ void ScriptList::RemoveBelowValue(int64 } } -void ScriptList::RemoveBetweenValue(int64 start, int64 end) +void ScriptList::RemoveBetweenValue(SQInteger start, SQInteger end) { this->modifications++; @@ -616,7 +616,7 @@ void ScriptList::RemoveBetweenValue(int6 } } -void ScriptList::RemoveValue(int64 value) +void ScriptList::RemoveValue(SQInteger value) { this->modifications++; @@ -626,7 +626,7 @@ void ScriptList::RemoveValue(int64 value } } -void ScriptList::RemoveTop(int32 count) +void ScriptList::RemoveTop(SQInteger count) { this->modifications++; @@ -663,7 +663,7 @@ void ScriptList::RemoveTop(int32 count) } } -void ScriptList::RemoveBottom(int32 count) +void ScriptList::RemoveBottom(SQInteger count) { this->modifications++; @@ -714,7 +714,7 @@ void ScriptList::RemoveList(ScriptList * } } -void ScriptList::KeepAboveValue(int64 value) +void ScriptList::KeepAboveValue(SQInteger value) { this->modifications++; @@ -724,7 +724,7 @@ void ScriptList::KeepAboveValue(int64 va } } -void ScriptList::KeepBelowValue(int64 value) +void ScriptList::KeepBelowValue(SQInteger value) { this->modifications++; @@ -734,7 +734,7 @@ void ScriptList::KeepBelowValue(int64 va } } -void ScriptList::KeepBetweenValue(int64 start, int64 end) +void ScriptList::KeepBetweenValue(SQInteger start, SQInteger end) { this->modifications++; @@ -744,7 +744,7 @@ void ScriptList::KeepBetweenValue(int64 } } -void ScriptList::KeepValue(int64 value) +void ScriptList::KeepValue(SQInteger value) { this->modifications++; @@ -754,14 +754,14 @@ void ScriptList::KeepValue(int64 value) } } -void ScriptList::KeepTop(int32 count) +void ScriptList::KeepTop(SQInteger count) { this->modifications++; this->RemoveBottom(this->Count() - count); } -void ScriptList::KeepBottom(int32 count) +void ScriptList::KeepBottom(SQInteger count) { this->modifications++; diff --git a/src/script/api/script_list.hpp b/src/script/api/script_list.hpp --- a/src/script/api/script_list.hpp +++ b/src/script/api/script_list.hpp @@ -42,9 +42,9 @@ private: int modifications; ///< Number of modification that has been done. To prevent changing data while valuating. public: - typedef std::set ScriptItemList; ///< The list of items inside the bucket - typedef std::map ScriptListBucket; ///< The bucket list per value - typedef std::map ScriptListMap; ///< List per item + typedef std::set ScriptItemList; ///< The list of items inside the bucket + typedef std::map ScriptListBucket; ///< The bucket list per value + typedef std::map ScriptListMap; ///< List per item ScriptListMap items; ///< The items in the list ScriptListBucket buckets; ///< The items in the list, sorted by value @@ -58,16 +58,16 @@ public: * @param item the item to add. Should be unique, otherwise it is ignored. * @param value the value to assign. */ - void AddItem(int64 item, int64 value); + void AddItem(SQInteger item, SQInteger value); #else - void AddItem(int64 item, int64 value = 0); + void AddItem(SQInteger item, SQInteger value = 0); #endif /* DOXYGEN_API */ /** * Remove a single item from the list. * @param item the item to remove. If not existing, it is ignored. */ - void RemoveItem(int64 item); + void RemoveItem(SQInteger item); /** * Clear the list, making Count() returning 0 and IsEmpty() returning true. @@ -79,21 +79,21 @@ public: * @param item the item to check for. * @return true if the item is in the list. */ - bool HasItem(int64 item); + bool HasItem(SQInteger item); /** * Go to the beginning of the list and return the item. To get the value use list.GetValue(list.Begin()). * @return the first item. * @note returns 0 if beyond end-of-list. Use IsEnd() to check for end-of-list. */ - int64 Begin(); + SQInteger Begin(); /** * Go to the next item in the list and return the item. To get the value use list.GetValue(list.Next()). * @return the next item. * @note returns 0 if beyond end-of-list. Use IsEnd() to check for end-of-list. */ - int64 Next(); + SQInteger Next(); /** * Check if a list is empty. @@ -112,14 +112,14 @@ public: * Returns the amount of items in the list. * @return amount of items in the list. */ - int32 Count(); + SQInteger Count(); /** * Get the value that belongs to this item. * @param item the item to get the value from * @return the value that belongs to this item. */ - int64 GetValue(int64 item); + SQInteger GetValue(SQInteger item); /** * Set a value of an item directly. @@ -129,7 +129,7 @@ public: * @note Changing values of items while looping through a list might cause * entries to be skipped. Be very careful with such operations. */ - bool SetValue(int64 item, int64 value); + bool SetValue(SQInteger item, SQInteger value); /** * Sort this list by the given sorter and direction. @@ -160,38 +160,38 @@ public: * Removes all items with a higher value than 'value'. * @param value the value above which all items are removed. */ - void RemoveAboveValue(int64 value); + void RemoveAboveValue(SQInteger value); /** * Removes all items with a lower value than 'value'. * @param value the value below which all items are removed. */ - void RemoveBelowValue(int64 value); + void RemoveBelowValue(SQInteger value); /** * Removes all items with a value above start and below end. * @param start the lower bound of the to be removed values (exclusive). * @param end the upper bound of the to be removed values (exclusive). */ - void RemoveBetweenValue(int64 start, int64 end); + void RemoveBetweenValue(SQInteger start, SQInteger end); /** * Remove all items with this value. * @param value the value to remove. */ - void RemoveValue(int64 value); + void RemoveValue(SQInteger value); /** * Remove the first count items. * @param count the amount of items to remove. */ - void RemoveTop(int32 count); + void RemoveTop(SQInteger count); /** * Remove the last count items. * @param count the amount of items to remove. */ - void RemoveBottom(int32 count); + void RemoveBottom(SQInteger count); /** * Remove everything that is in the given list from this list (same item index that is). @@ -204,38 +204,38 @@ public: * Keep all items with a higher value than 'value'. * @param value the value above which all items are kept. */ - void KeepAboveValue(int64 value); + void KeepAboveValue(SQInteger value); /** * Keep all items with a lower value than 'value'. * @param value the value below which all items are kept. */ - void KeepBelowValue(int64 value); + void KeepBelowValue(SQInteger value); /** * Keep all items with a value above start and below end. * @param start the lower bound of the to be kept values (exclusive). * @param end the upper bound of the to be kept values (exclusive). */ - void KeepBetweenValue(int64 start, int64 end); + void KeepBetweenValue(SQInteger start, SQInteger end); /** * Keep all items with this value. * @param value the value to keep. */ - void KeepValue(int64 value); + void KeepValue(SQInteger value); /** * Keep the first count items, i.e. remove everything except the first count items. * @param count the amount of items to keep. */ - void KeepTop(int32 count); + void KeepTop(SQInteger count); /** * Keep the last count items, i.e. remove everything except the last count items. * @param count the amount of items to keep. */ - void KeepBottom(int32 count); + void KeepBottom(SQInteger count); /** * Keeps everything that is in the given list from this list (same item index that is).