10 #ifndef SORTLIST_TYPE_H 11 #define SORTLIST_TYPE_H 46 template <
typename T,
typename F = const
char*>
67 return std::vector<T>::size() >= 2;
81 sort_func_list(
nullptr),
82 filter_func_list(
nullptr),
96 return this->sort_type;
106 if (this->sort_type != n_type) {
108 this->sort_type = n_type;
150 return this->filter_type;
160 if (this->filter_type != n_type) {
161 this->filter_type = n_type;
204 if (--this->resort_timer == 0) {
206 this->ResetResortTimer();
228 return (this->flags &
VL_DESC) != 0;
240 if (this->IsSortable())
MemReverseT(std::vector<T>::data(), std::vector<T>::size());
253 template <
typename Comp>
257 if (!(this->flags &
VL_RESORT))
return false;
259 CLRBITS(this->flags, VL_RESORT);
261 this->ResetResortTimer();
264 if (!this->IsSortable())
return false;
266 const bool desc = (this->flags &
VL_DESC) != 0;
269 CLRBITS(this->flags, VL_FIRST_SORT);
271 std::sort(std::vector<T>::begin(), std::vector<T>::end(), [&](
const T &a,
const T &b) {
return desc ? compare(b, a) : compare(a, b); });
275 std::sort(std::vector<T>::begin(), std::vector<T>::end(), [&](
const T &a,
const T &b) {
return desc ? compare(b, a) : compare(a, b); });
286 this->sort_func_list = n_funcs;
297 assert(this->sort_func_list !=
nullptr);
298 return this->Sort(this->sort_func_list[this->sort_type]);
332 bool Filter(FilterFunction *decide, F filter_data)
335 if (!(this->flags &
VL_FILTER))
return false;
337 bool changed =
false;
338 for (
auto it = std::vector<T>::begin(); it != std::vector<T>::end(); ) {
339 if (!decide(&*it, filter_data)) {
340 it = std::vector<T>::erase(it);
357 this->filter_func_list = n_funcs;
368 if (this->filter_func_list ==
nullptr)
return false;
369 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.
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.
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
bool Sort(Comp compare)
Sort the list.
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.
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.
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.
bool SortFunction(const T &, const T &)
Signature of sort function.
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.