Go to the documentation of this file.
10 #ifndef SORTLIST_TYPE_H
11 #define SORTLIST_TYPE_H
45 template <
typename T,
typename F = const
char*>
66 return std::vector<T>::size() >= 2;
105 if (this->sort_type != n_type) {
107 this->sort_type = n_type;
157 if (this->filter_type != n_type) {
158 this->filter_type = n_type;
201 if (--this->resort_timer == 0) {
225 return (this->flags &
VL_DESC) != 0;
246 template <
typename Comp>
250 if (!(this->flags &
VL_RESORT))
return false;
259 const bool desc = (this->flags &
VL_DESC) != 0;
261 std::sort(std::vector<T>::begin(), std::vector<T>::end(), [&](
const T &a,
const T &b) {
return desc ? compare(b, a) : compare(a, b); });
272 this->sort_func_list = n_funcs;
283 assert(this->sort_func_list !=
nullptr);
284 return this->
Sort(this->sort_func_list[this->sort_type]);
321 if (!(this->flags &
VL_FILTER))
return false;
323 bool changed =
false;
324 for (
auto it = std::vector<T>::begin(); it != std::vector<T>::end(); ) {
325 if (!decide(&*it, filter_data)) {
326 it = std::vector<T>::erase(it);
343 this->filter_func_list = n_funcs;
354 if (this->filter_func_list ==
nullptr)
return false;
355 return this->
Filter(this->filter_func_list[this->filter_type], filter_data);
uint8 SortType() const
Get the sorttype of the list.
bool Sort(Comp compare)
Sort the list.
void SetFilterType(uint8 n_type)
Set the filtertype of the list.
List template of 'things' T to sort in a GUI.
@ VL_RESORT
instruct the code to resort the list in the next loop
SortListFlags
Flags of the sort list.
static void MemReverseT(T *ptr1, T *ptr2)
Type safe memory reverse operation.
bool IsSortable() const
Check if the list is sortable.
void SetSortType(uint8 n_type)
Set the sorttype of the list.
#define SETBITS(x, y)
Sets several bits in a variable.
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
FilterFunction *const * filter_func_list
the filter criteria functions
void ResetResortTimer()
Reset the resort timer.
bool Filter(F filter_data)
Filter the data with the currently selected filter.
byte criteria
Filtering criteria.
@ VL_FILTER
filter disabled/enabled
bool IsDescSortOrder() const
Check if the sort order is descending.
Data structure describing how to show the list (what sort direction and criteria).
void SetFilterState(bool state)
Enable or disable the filter.
bool SortFunction(const T &, const T &)
Signature of sort function.
void SetListing(Listing l)
Import sort conditions.
uint8 filter_type
what criteria to filter on
bool order
Ascending/descending.
uint8 sort_type
what criteria to sort on
SortListFlags flags
used to control sorting/resorting/etc.
Data structure describing what to show in the list (filter criteria).
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
bool NeedRebuild() const
Check if a rebuild is needed.
@ VL_DESC
sort descending or ascending
uint16 resort_timer
resort list after a given amount of ticks if set
bool CDECL FilterFunction(const T *, F)
Signature of filter function.
Listing GetListing() const
Export current sort conditions.
void SetFiltering(Filtering f)
Import filter conditions.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
uint8 FilterType() const
Get the filtertype of the list.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
void ForceRebuild()
Force that a rebuild is needed.
bool IsFilterEnabled() const
Check if the filter is enabled.
bool Sort()
Overload of #Sort(SortFunction *compare) Overloaded to reduce external code.
SortFunction *const * sort_func_list
the sort criteria functions
Filtering GetFiltering() const
Export current filter conditions.
void RebuildDone()
Notify the sortlist that the rebuild is done.
byte criteria
Sorting criteria.
@ VL_REBUILD
rebuild the sort list
#define CLRBITS(x, y)
Clears several bits in a variable.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.