Files
@ r9464:ce84e83c962a
Branch filter:
Location: cpp/openttd-patchpack/source/src/sortlist_type.h - annotation
r9464:ce84e83c962a
6.0 KiB
text/x-c
(svn r13384) -Update: WebTranslator2 update to 2008-06-05 08:15:43
brazilian_portuguese - 9 fixed, 6 changed by tucalipe (15)
catalan - 9 fixed by arnaullv (9)
croatian - 13 fixed by knovak (13)
czech - 33 fixed by Hadez (33)
danish - 47 fixed by ThomasA (47)
dutch - 9 fixed by habell (9)
estonian - 42 fixed, 5 changed by kristjans (47)
finnish - 5 fixed, 1 changed by kerba (6)
french - 9 fixed, 2 changed by glx (8), belugas (3)
icelandic - 75 fixed by scrooge (75)
italian - 9 fixed, 12 changed by lorenzodv (21)
korean - 76 fixed, 15 changed by leejaeuk5 (91)
portuguese - 7 fixed by izhirahider (7)
romanian - 97 fixed, 302 changed by CrystyB (399)
russian - 12 fixed by Smoky555 (12)
spanish - 12 fixed by eusebio (12)
swedish - 13 fixed by ChrillDeVille (6), daishan (7)
turkish - 39 fixed, 1 changed by jnmbk (40)
ukrainian - 10 fixed by mad (10)
brazilian_portuguese - 9 fixed, 6 changed by tucalipe (15)
catalan - 9 fixed by arnaullv (9)
croatian - 13 fixed by knovak (13)
czech - 33 fixed by Hadez (33)
danish - 47 fixed by ThomasA (47)
dutch - 9 fixed by habell (9)
estonian - 42 fixed, 5 changed by kristjans (47)
finnish - 5 fixed, 1 changed by kerba (6)
french - 9 fixed, 2 changed by glx (8), belugas (3)
icelandic - 75 fixed by scrooge (75)
italian - 9 fixed, 12 changed by lorenzodv (21)
korean - 76 fixed, 15 changed by leejaeuk5 (91)
portuguese - 7 fixed by izhirahider (7)
romanian - 97 fixed, 302 changed by CrystyB (399)
russian - 12 fixed by Smoky555 (12)
spanish - 12 fixed by eusebio (12)
swedish - 13 fixed by ChrillDeVille (6), daishan (7)
turkish - 39 fixed, 1 changed by jnmbk (40)
ukrainian - 10 fixed by mad (10)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | r9274:76c4320046fb r9274:76c4320046fb r9274:76c4320046fb r9274:76c4320046fb r9274:76c4320046fb r9274:76c4320046fb r9274:76c4320046fb r9427:177da75469a5 r9427:177da75469a5 r9365:9bd51de92a64 r9366:1f0aaef04f68 r9365:9bd51de92a64 r9274:76c4320046fb r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9274:76c4320046fb r9274:76c4320046fb r9274:76c4320046fb r9274:76c4320046fb r9274:76c4320046fb r9274:76c4320046fb r9274:76c4320046fb r9274:76c4320046fb r9274:76c4320046fb r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9376:cdce66704b01 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9371:012afa66f9f0 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9375:bddb60776a57 r9372:206a22a85661 r9372:206a22a85661 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9372:206a22a85661 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9372:206a22a85661 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9372:206a22a85661 r9372:206a22a85661 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9372:206a22a85661 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9379:3132587150b4 r9366:1f0aaef04f68 r9379:3132587150b4 r9366:1f0aaef04f68 r9371:012afa66f9f0 r9379:3132587150b4 r9371:012afa66f9f0 r9371:012afa66f9f0 r9371:012afa66f9f0 r9371:012afa66f9f0 r9371:012afa66f9f0 r9366:1f0aaef04f68 r9379:3132587150b4 r9366:1f0aaef04f68 r9372:206a22a85661 r9372:206a22a85661 r9372:206a22a85661 r9386:2ccb6c5a3aae r9376:cdce66704b01 r9372:206a22a85661 r9372:206a22a85661 r9379:3132587150b4 r9372:206a22a85661 r9372:206a22a85661 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9379:3132587150b4 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9379:3132587150b4 r9379:3132587150b4 r9366:1f0aaef04f68 r9379:3132587150b4 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9379:3132587150b4 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9366:1f0aaef04f68 r9274:76c4320046fb r9274:76c4320046fb r9274:76c4320046fb | /* $Id$ */
/** @file sortlist_type.h Base types for having sorted lists in GUIs. */
#ifndef SORTLIST_TYPE_H
#define SORTLIST_TYPE_H
#include "core/enum_type.hpp"
#include "core/bitmath_func.hpp"
#include "misc/smallvec.h"
#include "date_type.h"
enum SortListFlags {
VL_NONE = 0, ///< no sort
VL_DESC = 1 << 0, ///< sort descending or ascending
VL_RESORT = 1 << 1, ///< instruct the code to resort the list in the next loop
VL_REBUILD = 1 << 2, ///< rebuild the sort list
VL_FIRST_SORT = 1 << 3, ///< sort with qsort first
VL_END = 1 << 4,
};
DECLARE_ENUM_AS_BIT_SET(SortListFlags);
struct Listing {
bool order; ///< Ascending/descending
byte criteria; ///< Sorting criteria
};
template <typename T>
class GUIList : public SmallVector<T, 32> {
public:
typedef int CDECL SortFunction(const T*, const T*);
public: // Temporary: public for conversion only
SortFunction* const *func_list; ///< The sort criteria functions
SortListFlags flags; ///< used to control sorting/resorting/etc.
uint8 sort_type; ///< what criteria to sort on
uint16 resort_timer; ///< resort list after a given amount of ticks if set
/**
* Check if the list is sortable
*
* @return true if we can sort the list
*/
bool IsSortable() const
{
return (this->data != NULL && this->items >= 2);
}
/**
* Reset the resort timer
*/
void ResetResortTimer()
{
/* Resort every 10 days */
this->resort_timer = DAY_TICKS * 10;
}
/**
* Reverse the list
*/
void Reverse()
{
assert(this->IsSortable());
T *a = this->data;
T *b = a + (this->items - 1);
do {
Swap(*a, *b);
} while (++a < --b);
}
public:
GUIList() :
func_list(NULL),
flags(VL_FIRST_SORT),
sort_type(0),
resort_timer(1)
{};
/**
* Get the sorttype of the list
*
* @return The current sorttype
*/
uint8 SortType() const
{
return this->sort_type;
}
/**
* Set the sorttype of the list
*
* @param n_type the new sort type
*/
void SetSortType(uint8 n_type)
{
if (this->sort_type != n_type) {
SETBITS(this->flags, VL_RESORT | VL_FIRST_SORT);
this->sort_type = n_type;
}
}
/**
* Export current sort conditions
*
* @return the current sort conditions
*/
Listing GetListing() const
{
Listing l;
l.order = HASBITS(this->flags, VL_DESC);
l.criteria = this->sort_type;
return l;
}
/**
* Import sort conditions
*
* @param l The sport conditions we want to use
*/
void SetListing(Listing l)
{
if (l.order) {
SETBITS(this->flags, VL_DESC);
} else {
CLRBITS(this->flags, VL_DESC);
}
this->sort_type = l.criteria;
SETBITS(this->flags, VL_FIRST_SORT);
}
/**
* 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.
*
* @return true if resort bit is set for next loop
*/
bool NeedResort()
{
if (--this->resort_timer == 0) {
SETBITS(this->flags, VL_RESORT);
this->ResetResortTimer();
return true;
}
return false;
}
/**
* Force a resort next Sort call
* Reset the resort timer if used too.
*/
void ForceResort()
{
SETBITS(this->flags, VL_RESORT);
}
/**
* Check if the sort order is descending
*
* @return true if the sort order is descending
*/
bool IsDescSortOrder() const
{
return HASBITS(this->flags, VL_DESC);
}
/**
* Toogle the sort order
* Since that is the worst condition for the sort function
* reverse the list here.
*/
FORCEINLINE void ToggleSortOrder()
{
this->flags ^= VL_DESC;
if (this->IsSortable()) this->Reverse();
}
/**
* GnomeSort algorithm
* This sorting uses a slightly modifyied Gnome search.
* The basic Gnome search trys to sort already sorted
* list parts. The modification skips these. For the first
* sorting we use qsort since it is faster for irregular
* sorted data.
*
* @param compare The function to compare two list items
* @return true if the list sequence has been altered
* */
FORCEINLINE bool Sort(SortFunction *compare)
{
/* Do not sort if the resort bit is not set */
if (!HASBITS(this->flags, VL_RESORT)) return false;
CLRBITS(this->flags, VL_RESORT);
this->ResetResortTimer();
/* Do not sort when the list is not sortable */
if (!this->IsSortable()) return false;
const bool desc = HASBITS(this->flags, VL_DESC);
if (HASBITS(this->flags, VL_FIRST_SORT)) {
CLRBITS(this->flags, VL_FIRST_SORT);
qsort(this->data, this->items, sizeof(T), (int (CDECL *)(const void *, const void *))compare);
if (desc) this->Reverse();
return true;
}
T *a = this->data;
T *b = a + 1;
uint length = this->items;
uint offset = 0; // Jump variable
while (length > 1) {
const int diff = compare(a, b);
if ((!desc && diff <= 0) || (desc && diff >= 0)) {
if (offset != 0) {
/* Jump back to the last direction switch point */
a += offset;
b += offset;
offset = 0;
continue;
}
a++;
b++;
length--;
} else {
Swap(*a, *b);
if (a != this->data) {
offset++;
a--;
b--;
}
}
}
return true;
}
/**
* Hand the array of sort function pointers to the sort list
*
* @param n_funcs The pointer to the first sort func
*/
void SetSortFuncs(SortFunction* const* n_funcs)
{
this->func_list = n_funcs;
}
/**
* Overload of Sort()
* Overloaded to reduce external code
*
* @return true if the list sequence has been altered
*/
bool Sort()
{
assert(this->func_list != NULL);
return this->Sort(this->func_list[this->sort_type]);
}
/**
* Check if a rebuild is needed
* @return true if a rebuild is needed
*/
bool NeedRebuild() const
{
return HASBITS(this->flags, VL_REBUILD);
}
/**
* Force that a rebuild is needed
*/
void ForceRebuild()
{
SETBITS(this->flags, VL_REBUILD);
}
/**
* Notify the sortlist that the rebuild is done
*
* @note This forces a resort
*/
void RebuildDone()
{
CLRBITS(this->flags, VL_REBUILD);
SETBITS(this->flags, VL_RESORT);
}
};
#endif /* SORTLIST_TYPE_H */
|