OpenTTD
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
GUIList< T, F > Class Template Reference

List template of 'things' T to sort in a GUI. More...

#include <sortlist_type.h>

Inheritance diagram for GUIList< T, F >:
SmallVector< T, 32 >

Public Types

typedef int CDECL SortFunction(const T *, const T *)
 Signature of sort function.
 
typedef bool CDECL FilterFunction(const T *, F)
 Signature of filter function.
 

Public Member Functions

uint8 SortType () const
 Get the sorttype of the list. More...
 
void SetSortType (uint8 n_type)
 Set the sorttype of the list. More...
 
Listing GetListing () const
 Export current sort conditions. More...
 
void SetListing (Listing l)
 Import sort conditions. More...
 
uint8 FilterType () const
 Get the filtertype of the list. More...
 
void SetFilterType (uint8 n_type)
 Set the filtertype of the list. More...
 
Filtering GetFiltering () const
 Export current filter conditions. More...
 
void SetFiltering (Filtering f)
 Import filter conditions. More...
 
bool NeedResort ()
 Check if a resort is needed next loop If used the resort timer will decrease every call till 0. More...
 
void ForceResort ()
 Force a resort next Sort call Reset the resort timer if used too.
 
bool IsDescSortOrder () const
 Check if the sort order is descending. More...
 
void ToggleSortOrder ()
 Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
 
bool Sort (SortFunction *compare)
 Sort the list. More...
 
void SetSortFuncs (SortFunction *const *n_funcs)
 Hand the array of sort function pointers to the sort list. More...
 
bool Sort ()
 Overload of Sort(SortFunction *compare) Overloaded to reduce external code. More...
 
bool IsFilterEnabled () const
 Check if the filter is enabled. More...
 
void SetFilterState (bool state)
 Enable or disable the filter. More...
 
bool Filter (FilterFunction *decide, F filter_data)
 Filter the list. More...
 
void SetFilterFuncs (FilterFunction *const *n_funcs)
 Hand the array of filter function pointers to the sort list. More...
 
bool Filter (F filter_data)
 Filter the data with the currently selected filter. More...
 
bool NeedRebuild () const
 Check if a rebuild is needed. More...
 
void ForceRebuild ()
 Force that a rebuild is needed.
 
void RebuildDone ()
 Notify the sortlist that the rebuild is done. More...
 
- Public Member Functions inherited from SmallVector< T, 32 >
 SmallVector (const SmallVector &other)
 Copy constructor. More...
 
 SmallVector (const SmallVector< T, X > &other)
 Generic copy constructor. More...
 
SmallVectoroperator= (const SmallVector &other)
 Assignment. More...
 
SmallVectoroperator= (const SmallVector< T, X > &other)
 Generic assignment. More...
 
void Assign (const SmallVector< T, X > &other)
 Assign items from other vector.
 
void Clear ()
 Remove all items from the list.
 
void Reset ()
 Remove all items from the list and free allocated memory.
 
void Compact ()
 Compact the list down to the smallest block size boundary.
 
T * Append (uint to_add=1)
 Append an item and return it. More...
 
void Resize (uint num_items)
 Set the size of the vector, effectively truncating items from the end or appending uninitialised ones. More...
 
const T * Find (const T &item) const
 Search for the first occurrence of an item. More...
 
T * Find (const T &item)
 Search for the first occurrence of an item. More...
 
int FindIndex (const T &item) const
 Search for the first occurrence of an item. More...
 
bool Contains (const T &item) const
 Tests whether a item is present in the vector. More...
 
void Erase (T *item)
 Removes given item from this vector. More...
 
void ErasePreservingOrder (uint pos, uint count=1)
 Remove items from the vector while preserving the order of other items. More...
 
bool Include (const T &item)
 Tests whether a item is present in the vector, and appends it to the end if not. More...
 
uint Length () const
 Get the number of items in the list. More...
 
const T * Begin () const
 Get the pointer to the first item (const) More...
 
T * Begin ()
 Get the pointer to the first item. More...
 
const T * End () const
 Get the pointer behind the last valid item (const) More...
 
T * End ()
 Get the pointer behind the last valid item. More...
 
const T * Get (uint index) const
 Get the pointer to item "number" (const) More...
 
T * Get (uint index)
 Get the pointer to item "number". More...
 
const T & operator[] (uint index) const
 Get item "number" (const) More...
 
T & operator[] (uint index)
 Get item "number". More...
 

Protected Member Functions

bool IsSortable () const
 Check if the list is sortable. More...
 
void ResetResortTimer ()
 Reset the resort timer.
 

Protected Attributes

SortFunction *const * sort_func_list
 the sort criteria functions
 
FilterFunction *const * filter_func_list
 the filter criteria functions
 
SortListFlags flags
 used to control sorting/resorting/etc.
 
uint8 sort_type
 what criteria to sort on
 
uint8 filter_type
 what criteria to filter on
 
uint16 resort_timer
 resort list after a given amount of ticks if set
 
- Protected Attributes inherited from SmallVector< T, 32 >
T * data
 The pointer to the first item.
 
uint items
 The number of items stored.
 
uint capacity
 The available space for storing items.
 

Detailed Description

template<typename T, typename F = const char*>
class GUIList< T, F >

List template of 'things' T to sort in a GUI.

Template Parameters
TType of data stored in the list to represent each item.
FType of data fed as additional value to the filter function.
See also
FilterFunction

Definition at line 50 of file sortlist_type.h.

Member Function Documentation

◆ Filter() [1/2]

template<typename T, typename F = const char*>
bool GUIList< T, F >::Filter ( FilterFunction decide,
filter_data 
)
inline

Filter the list.

Parameters
decideThe function to decide about an item
filter_dataAdditional data passed to the filter function
Returns
true if the list has been altered by filtering

Definition at line 334 of file sortlist_type.h.

Referenced by NetworkGameWindow::BuildGUINetworkGameList(), NetworkContentListWindow::FilterContentList(), BuildVehicleWindow::FilterEngineList(), SignList::FilterSignList(), and NewGRFWindow::TagNameFilter().

◆ Filter() [2/2]

template<typename T, typename F = const char*>
bool GUIList< T, F >::Filter ( filter_data)
inline

Filter the data with the currently selected filter.

Parameters
filter_dataAdditional data passed to the filter function.
Returns
true if the list has been altered by filtering

Definition at line 369 of file sortlist_type.h.

◆ FilterType()

template<typename T, typename F = const char*>
uint8 GUIList< T, F >::FilterType ( ) const
inline

Get the filtertype of the list.

Returns
The current filtertype

Definition at line 151 of file sortlist_type.h.

◆ GetFiltering()

template<typename T, typename F = const char*>
Filtering GUIList< T, F >::GetFiltering ( ) const
inline

Export current filter conditions.

Returns
the current filter conditions

Definition at line 173 of file sortlist_type.h.

Referenced by NetworkContentListWindow::UpdateFilterState().

◆ GetListing()

template<typename T, typename F = const char*>
Listing GUIList< T, F >::GetListing ( ) const
inline

◆ IsDescSortOrder()

template<typename T, typename F = const char*>
bool GUIList< T, F >::IsDescSortOrder ( ) const
inline

◆ IsFilterEnabled()

template<typename T, typename F = const char*>
bool GUIList< T, F >::IsFilterEnabled ( ) const
inline

Check if the filter is enabled.

Returns
true if the filter is enabled

Definition at line 308 of file sortlist_type.h.

◆ IsSortable()

template<typename T, typename F = const char*>
bool GUIList< T, F >::IsSortable ( ) const
inlineprotected

Check if the list is sortable.

Returns
true if we can sort the list

Definition at line 68 of file sortlist_type.h.

◆ NeedRebuild()

template<typename T, typename F = const char*>
bool GUIList< T, F >::NeedRebuild ( ) const
inline

◆ NeedResort()

template<typename T, typename F = const char*>
bool GUIList< T, F >::NeedResort ( )
inline

Check if a resort is needed next loop If used the resort timer will decrease every call till 0.

If 0 reached the resort bit will be set and the timer will be reset.

Returns
true if resort bit is set for next loop

Definition at line 205 of file sortlist_type.h.

Referenced by NetworkGameWindow::OnPaint(), CompanyStationsWindow::OnTick(), VehicleGroupWindow::OnTick(), CompanyLeagueWindow::OnTick(), VehicleListWindow::OnTick(), BuildBridgeWindow::SortBridgeList(), and CompanyStationsWindow::SortStationsList().

◆ RebuildDone()

template<typename T, typename F = const char*>
void GUIList< T, F >::RebuildDone ( )
inline

Notify the sortlist that the rebuild is done.

Note
This forces a resort

Definition at line 397 of file sortlist_type.h.

Referenced by NetworkContentListWindow::BuildContentList(), NetworkGameWindow::BuildGUINetworkGameList(), ReplaceVehicleWindow::GenerateLists(), GetUnitNumberDigits(), and NewGRFWindow::TagNameFilter().

◆ SetFilterFuncs()

template<typename T, typename F = const char*>
void GUIList< T, F >::SetFilterFuncs ( FilterFunction *const *  n_funcs)
inline

Hand the array of filter function pointers to the sort list.

Parameters
n_funcsThe pointer to the first filter func

Definition at line 358 of file sortlist_type.h.

Referenced by BuildVehicleWindow::SetCargoFilterArray().

◆ SetFiltering()

template<typename T, typename F = const char*>
void GUIList< T, F >::SetFiltering ( Filtering  f)
inline

Import filter conditions.

Parameters
fThe filter conditions we want to use

Definition at line 187 of file sortlist_type.h.

◆ SetFilterState()

template<typename T, typename F = const char*>
void GUIList< T, F >::SetFilterState ( bool  state)
inline

Enable or disable the filter.

Parameters
stateIf filtering should be enabled or disabled

Definition at line 318 of file sortlist_type.h.

Referenced by NetworkGameWindow::BuildGUINetworkGameList(), BuildVehicleWindow::OnDropdownSelect(), NewGRFWindow::OnEditboxChanged(), and NetworkContentListWindow::UpdateFilterState().

◆ SetFilterType()

template<typename T, typename F = const char*>
void GUIList< T, F >::SetFilterType ( uint8  n_type)
inline

Set the filtertype of the list.

Parameters
n_typethe new filter type

Definition at line 161 of file sortlist_type.h.

Referenced by NetworkContentListWindow::FilterContentList().

◆ SetListing()

template<typename T, typename F = const char*>
void GUIList< T, F >::SetListing ( Listing  l)
inline

◆ SetSortFuncs()

template<typename T, typename F = const char*>
void GUIList< T, F >::SetSortFuncs ( SortFunction *const *  n_funcs)
inline

Hand the array of sort function pointers to the sort list.

Parameters
n_funcsThe pointer to the first sort func

Definition at line 286 of file sortlist_type.h.

Referenced by IndustryDirectoryWindow::GetIndustryString(), BuildBridgeWindow::SortBridgeList(), CompanyStationsWindow::SortStationsList(), and TownDirectoryWindow::TownRatingSorter().

◆ SetSortType()

template<typename T, typename F = const char*>
void GUIList< T, F >::SetSortType ( uint8  n_type)
inline

◆ Sort() [1/2]

template<typename T, typename F = const char*>
bool GUIList< T, F >::Sort ( SortFunction compare)
inline

Sort the list.

For the first sorting we use quick sort since it is faster for irregular sorted data. After that we use gsort.

Parameters
compareThe function to compare two list items
Returns
true if the list sequence has been altered

Definition at line 256 of file sortlist_type.h.

Referenced by NetworkGameWindow::BuildGUINetworkGameList(), TownDirectoryWindow::OnClick(), CompanyLeagueWindow::OnPaint(), BuildBridgeWindow::SortBridgeList(), NetworkContentListWindow::SortContentList(), NetworkGameWindow::SortNetworkGameList(), CompanyStationsWindow::SortStationsList(), and NewGRFWindow::TagNameFilter().

◆ Sort() [2/2]

template<typename T, typename F = const char*>
bool GUIList< T, F >::Sort ( )
inline

Overload of Sort(SortFunction *compare) Overloaded to reduce external code.

Returns
true if the list sequence has been altered

Definition at line 297 of file sortlist_type.h.

◆ SortType()

template<typename T, typename F = const char*>
uint8 GUIList< T, F >::SortType ( ) const
inline

The documentation for this class was generated from the following file: