12 #ifndef SORTLIST_TYPE_H 13 #define SORTLIST_TYPE_H 49 template <
typename T,
typename F = const
char*>
70 return (this->data != NULL && this->items >= 2);
85 filter_func_list(NULL),
99 return this->sort_type;
109 if (this->sort_type != n_type) {
111 this->sort_type = n_type;
153 return this->filter_type;
163 if (this->filter_type != n_type) {
164 this->filter_type = n_type;
207 if (--this->resort_timer == 0) {
209 this->ResetResortTimer();
231 return (this->flags &
VL_DESC) != 0;
243 if (this->IsSortable())
MemReverseT(this->data, this->items);
256 bool Sort(SortFunction *compare)
259 if (!(this->flags &
VL_RESORT))
return false;
261 CLRBITS(this->flags, VL_RESORT);
263 this->ResetResortTimer();
266 if (!this->IsSortable())
return false;
268 const bool desc = (this->flags &
VL_DESC) != 0;
271 CLRBITS(this->flags, VL_FIRST_SORT);
273 QSortT(this->data, this->items, compare, desc);
277 GSortT(this->data, this->items, compare, desc);
288 this->sort_func_list = n_funcs;
299 assert(this->sort_func_list != NULL);
300 return this->Sort(this->sort_func_list[this->sort_type]);
334 bool Filter(FilterFunction *decide, F filter_data)
337 if (!(this->flags &
VL_FILTER))
return false;
339 bool changed =
false;
340 for (uint iter = 0; iter < this->items;) {
341 T *item = &this->data[iter];
342 if (!decide(item, filter_data)) {
360 this->filter_func_list = n_funcs;
371 if (this->filter_func_list == NULL)
return false;
372 return this->Filter(this->filter_func_list[this->filter_type], filter_data);
List template of 'things' T to sort in a GUI.
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
void RebuildDone()
Notify the sortlist that the rebuild is done.
static void GSortT(T *base, uint num, int(CDECL *comparator)(const T *, const T *), bool desc=false)
Type safe Gnome Sort.
Simple vector class that allows allocating an item without the need to copy this->data needlessly...
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
uint8 filter_type
what criteria to filter on
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
uint16 resort_timer
resort list after a given amount of ticks if set
#define SETBITS(x, y)
Sets several bits in a variable.
void SetFilterType(uint8 n_type)
Set the filtertype of the list.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
bool Filter(F filter_data)
Filter the data with the currently selected filter.
Functions related to bit mathematics.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0...
SortListFlags flags
used to control sorting/resorting/etc.
Simple vector template class.
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
#define CLRBITS(x, y)
Clears several bits in a variable.
static void MemReverseT(T *ptr1, T *ptr2)
Type safe memory reverse operation.
void SetListing(Listing l)
Import sort conditions.
Type (helpers) for enums.
Data structure describing what to show in the list (filter criteria).
bool NeedRebuild() const
Check if a rebuild is needed.
sort descending or ascending
void ForceRebuild()
Force that a rebuild is needed.
bool IsSortable() const
Check if the list is sortable.
byte criteria
Filtering criteria.
SortFunction *const * sort_func_list
the sort criteria functions
void ResetResortTimer()
Reset the resort timer.
Listing GetListing() const
Export current sort conditions.
bool order
Ascending/descending.
sort with quick sort first
instruct the code to resort the list in the next loop
SortListFlags
Flags of the sort list.
void SetSortType(uint8 n_type)
Set the sorttype of the list.
bool Sort(SortFunction *compare)
Sort the list.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
uint8 sort_type
what criteria to sort on
void SetFilterState(bool state)
Enable or disable the filter.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here...
bool CDECL FilterFunction(const T *, F)
Signature of filter function.
int CDECL SortFunction(const T *, const T *)
Signature of sort function.
Functions related to sorting operations.
Data structure describing how to show the list (what sort direction and criteria).
Types related to the dates in OpenTTD.
bool IsFilterEnabled() const
Check if the filter is enabled.
void SetFiltering(Filtering f)
Import filter conditions.
bool IsDescSortOrder() const
Check if the sort order is descending.
byte criteria
Sorting criteria.
Filtering GetFiltering() const
Export current filter conditions.
uint8 FilterType() const
Get the filtertype of the list.
static void QSortT(T *base, uint num, int(CDECL *comparator)(const T *, const T *), bool desc=false)
Type safe qsort()
bool Sort()
Overload of Sort(SortFunction *compare) Overloaded to reduce external code.
FilterFunction *const * filter_func_list
the filter criteria functions
uint8 SortType() const
Get the sorttype of the list.