Freeciv-3.1
|
Go to the source code of this file.
Data Structures | |
struct | genlist |
struct | genlist_link |
Typedefs | |
typedef void(* | genlist_free_fn_t) (void *) |
typedef void *(* | genlist_copy_fn_t) (const void *) |
typedef bool(* | genlist_cond_fn_t) (const void *) |
typedef bool(* | genlist_comp_fn_t) (const void *, const void *) |
Functions | |
struct genlist * | genlist_new (void) fc__warn_unused_result |
struct genlist * | genlist_new_full (genlist_free_fn_t free_data_func) fc__warn_unused_result |
void | genlist_destroy (struct genlist *pgenlist) |
struct genlist * | genlist_copy (const struct genlist *pgenlist) fc__warn_unused_result |
struct genlist * | genlist_copy_full (const struct genlist *pgenlist, genlist_copy_fn_t copy_data_func, genlist_free_fn_t free_data_func) fc__warn_unused_result |
void | genlist_clear (struct genlist *pgenlist) |
void | genlist_unique (struct genlist *pgenlist) |
void | genlist_unique_full (struct genlist *pgenlist, genlist_comp_fn_t comp_data_func) |
void | genlist_append (struct genlist *pgenlist, void *data) |
void | genlist_prepend (struct genlist *pgenlist, void *data) |
void | genlist_insert (struct genlist *pgenlist, void *data, int idx) |
void | genlist_insert_after (struct genlist *pgenlist, void *data, struct genlist_link *plink) |
void | genlist_insert_before (struct genlist *pgenlist, void *data, struct genlist_link *plink) |
bool | genlist_remove (struct genlist *pgenlist, const void *data) |
bool | genlist_remove_if (struct genlist *pgenlist, genlist_cond_fn_t cond_data_func) |
int | genlist_remove_all (struct genlist *pgenlist, const void *data) |
int | genlist_remove_all_if (struct genlist *pgenlist, genlist_cond_fn_t cond_data_func) |
void | genlist_erase (struct genlist *pgenlist, struct genlist_link *plink) |
void | genlist_pop_front (struct genlist *pgenlist) |
void | genlist_pop_back (struct genlist *pgenlist) |
int | genlist_size (const struct genlist *pgenlist) |
void * | genlist_get (const struct genlist *pgenlist, int idx) |
void * | genlist_front (const struct genlist *pgenlist) |
void * | genlist_back (const struct genlist *pgenlist) |
struct genlist_link * | genlist_link_get (const struct genlist *pgenlist, int idx) |
static struct genlist_link * | genlist_head (const struct genlist *pgenlist) |
struct genlist_link * | genlist_tail (const struct genlist *pgenlist) |
struct genlist_link * | genlist_search (const struct genlist *pgenlist, const void *data) |
struct genlist_link * | genlist_search_if (const struct genlist *pgenlist, genlist_cond_fn_t cond_data_func) |
void | genlist_sort (struct genlist *pgenlist, int(*compar)(const void *, const void *)) |
void | genlist_shuffle (struct genlist *pgenlist) |
void | genlist_reverse (struct genlist *pgenlist) |
void | genlist_allocate_mutex (struct genlist *pgenlist) |
void | genlist_release_mutex (struct genlist *pgenlist) |
static void * | genlist_link_data (const struct genlist_link *plink) |
static fc__warn_unused_result struct genlist_link * | genlist_link_prev (const struct genlist_link *plink) |
static fc__warn_unused_result struct genlist_link * | genlist_link_next (const struct genlist_link *plink) |
typedef bool(* genlist_comp_fn_t) (const void *, const void *) |
void genlist_allocate_mutex | ( | struct genlist * | pgenlist | ) |
Allocates list mutex
Definition at line 682 of file genlist.c.
Referenced by _list_allocate_mutex().
void genlist_append | ( | struct genlist * | pgenlist, |
void * | data | ||
) |
Insert an item at the end of the list.
Definition at line 536 of file genlist.c.
Referenced by _list_append().
void * genlist_back | ( | const struct genlist * | pgenlist | ) |
Returns the user-data pointer stored in the last element of the genlist.
Definition at line 240 of file genlist.c.
Referenced by _list_back().
void genlist_clear | ( | struct genlist * | pgenlist | ) |
Frees all the internal data used by the genlist (but doesn't touch the user-data). At the end the state of the genlist will be the same as when genlist_init() is called on a new genlist.
Definition at line 250 of file genlist.c.
Referenced by _list_clear(), and genlist_destroy().
Returns a new genlist that's a copy of the existing one.
Definition at line 157 of file genlist.c.
Referenced by _list_copy().
struct genlist * genlist_copy_full | ( | const struct genlist * | pgenlist, |
genlist_copy_fn_t | copy_data_func, | ||
genlist_free_fn_t | free_data_func | ||
) |
Returns a new genlist that's a copy of the existing one.
Definition at line 165 of file genlist.c.
Referenced by _list_copy_full(), and genlist_copy().
void genlist_destroy | ( | struct genlist * | pgenlist | ) |
Destroys the genlist.
Definition at line 57 of file genlist.c.
Referenced by _list_destroy(), and luaconsole_dialog_done().
void genlist_erase | ( | struct genlist * | pgenlist, |
struct genlist_link * | plink | ||
) |
Remove the element pointed to plink.
NB: After calling this function 'plink' is no more usable. You should have saved the next or previous link before.
Definition at line 436 of file genlist.c.
Referenced by _list_erase().
void * genlist_front | ( | const struct genlist * | pgenlist | ) |
Returns the user-data pointer stored in the first element of the genlist.
Definition at line 232 of file genlist.c.
Referenced by _list_front().
void * genlist_get | ( | const struct genlist * | pgenlist, |
int | idx | ||
) |
Returns the user-data pointer stored in the genlist at the position given by 'idx'. For idx out of range (including an empty list), returns NULL. Recall 'idx' can be -1 meaning the last element.
Definition at line 224 of file genlist.c.
Referenced by _list_get(), inputline_handler(), inputline_handler(), inputline_return(), luaconsole_input_handler(), luaconsole_input_handler(), and luaconsole_input_return().
|
inlinestatic |
Definition at line 108 of file genlist.h.
Referenced by _list_head(), genlist_front(), genlist_shuffle(), and genlist_sort().
void genlist_insert | ( | struct genlist * | pgenlist, |
void * | data, | ||
int | pos | ||
) |
Insert a new element in the list, at position 'pos', with the specified user-data pointer 'data'. Existing elements at >= pos are moved one space to the "right". Recall 'pos' can be -1 meaning add at the end of the list. For an empty list pos has no effect. A bad 'pos' value for a non-empty list is treated as -1 (is this a good idea?)
Definition at line 477 of file genlist.c.
Referenced by _list_insert().
void genlist_insert_after | ( | struct genlist * | pgenlist, |
void * | data, | ||
struct genlist_link * | plink | ||
) |
Insert an item after the link. If plink is NULL, prepend to the list.
Definition at line 502 of file genlist.c.
Referenced by _list_insert_after().
void genlist_insert_before | ( | struct genlist * | pgenlist, |
void * | data, | ||
struct genlist_link * | plink | ||
) |
Insert an item before the link.
Definition at line 514 of file genlist.c.
Referenced by _list_insert_before().
|
inlinestatic |
Get data pointer of the genlist link
plink | Link to get data for |
Definition at line 140 of file genlist.h.
Referenced by _list_link_data(), genlist_back(), genlist_front(), and genlist_get().
struct genlist_link * genlist_link_get | ( | const struct genlist * | pgenlist, |
int | idx | ||
) |
Returns the link in the genlist at the position given by 'idx'. For idx out of range (including an empty list), returns NULL. Recall 'idx' can be -1 meaning the last element.
Definition at line 203 of file genlist.c.
Referenced by _list_link_get(), and genlist_get().
|
inlinestatic |
Get next link in genlist
plink | Link to start from |
Definition at line 162 of file genlist.h.
Referenced by _list_link_next().
|
inlinestatic |
Get previous link in genlist
plink | Link to start from |
Definition at line 151 of file genlist.h.
Referenced by _list_link_prev().
struct genlist * genlist_new | ( | void | ) |
Create a new empty genlist.
Definition at line 31 of file genlist.c.
Referenced by _list_new(), chatline_init(), and luaconsole_dialog_init().
struct genlist * genlist_new_full | ( | genlist_free_fn_t | free_data_func | ) |
Create a new empty genlist with a free data function.
Definition at line 39 of file genlist.c.
Referenced by _list_new_full(), genlist_copy_full(), and genlist_new().
void genlist_pop_back | ( | struct genlist * | pgenlist | ) |
Remove the last element of the genlist.
Definition at line 460 of file genlist.c.
Referenced by _list_pop_back().
void genlist_pop_front | ( | struct genlist * | pgenlist | ) |
Remove the first element of the genlist.
Definition at line 448 of file genlist.c.
Referenced by _list_pop_front().
void genlist_prepend | ( | struct genlist * | pgenlist, |
void * | data | ||
) |
Insert an item at the start of the list.
Definition at line 526 of file genlist.c.
Referenced by _list_prepend(), inputline_return(), and luaconsole_input_return().
void genlist_release_mutex | ( | struct genlist * | pgenlist | ) |
Remove an element of the genlist with the specified user-data pointer given by 'punlink'. If there is no such element, does nothing. If there are multiple such elements, removes the first one. Return TRUE if one element has been removed. See also, genlist_remove_all(), genlist_remove_if() and genlist_remove_all_if().
Definition at line 329 of file genlist.c.
Referenced by _list_remove(), inputline_return(), and luaconsole_input_return().
int genlist_remove_all | ( | struct genlist * | pgenlist, |
const void * | punlink | ||
) |
Remove all elements of the genlist with the specified user-data pointer given by 'punlink'. Return the number of removed elements. See also, genlist_remove(), genlist_remove_if() and genlist_remove_all_if().
Definition at line 351 of file genlist.c.
Referenced by _list_remove_all().
int genlist_remove_all_if | ( | struct genlist * | pgenlist, |
genlist_cond_fn_t | cond_data_func | ||
) |
Remove all elements of the genlist which fit the function (the function return TRUE). Return the number of removed elements. See also, genlist_remove(), genlist_remove_all(), and genlist_remove_if().
Definition at line 404 of file genlist.c.
Referenced by _list_remove_all_if().
bool genlist_remove_if | ( | struct genlist * | pgenlist, |
genlist_cond_fn_t | cond_data_func | ||
) |
Remove the first element of the genlist which fit the function (the function return TRUE). Return TRUE if one element has been removed. See also, genlist_remove(), genlist_remove_all(), and genlist_remove_all_if().
Definition at line 379 of file genlist.c.
Referenced by _list_remove_if().
void genlist_reverse | ( | struct genlist * | pgenlist | ) |
Reverse the order of the elements in the genlist.
Definition at line 659 of file genlist.c.
Referenced by _list_reverse().
struct genlist_link * genlist_search | ( | const struct genlist * | pgenlist, |
const void * | data | ||
) |
Return the link where data is equal to 'data'. Returns NULL if not found.
This is an O(n) operation. Hence, "search".
Definition at line 548 of file genlist.c.
Referenced by _list_search().
struct genlist_link * genlist_search_if | ( | const struct genlist * | pgenlist, |
genlist_cond_fn_t | cond_data_func | ||
) |
Return the link which fit the conditional function. Returns NULL if no match.
Definition at line 568 of file genlist.c.
Referenced by _list_search_if().
void genlist_shuffle | ( | struct genlist * | pgenlist | ) |
Randomize the elements of a genlist using the Fisher-Yates shuffle.
see: genlist_sort() and shared.c:array_shuffle()
Definition at line 629 of file genlist.c.
Referenced by _list_shuffle().
int genlist_size | ( | const struct genlist * | pgenlist | ) |
Returns the number of elements stored in the genlist.
Definition at line 192 of file genlist.c.
Referenced by _list_size(), genlist_shuffle(), genlist_sort(), inputline_handler(), inputline_handler(), inputline_return(), luaconsole_input_handler(), luaconsole_input_handler(), and luaconsole_input_return().
void genlist_sort | ( | struct genlist * | pgenlist, |
int(*)(const void *, const void *) | compar | ||
) |
Sort the elements of a genlist.
The comparison function should be a function usable by qsort; note that the const void * arguments to compar should really be "pointers to void*", where the void* being pointed to are the genlist dataptrs. That is, there are two levels of indirection. To do the sort we first construct an array of pointers corresponding to the genlist dataptrs, then sort those and put them back into the genlist.
Definition at line 597 of file genlist.c.
Referenced by _list_sort().
struct genlist_link * genlist_tail | ( | const struct genlist * | pgenlist | ) |
Returns the tail link of the genlist.
Definition at line 213 of file genlist.c.
Referenced by _list_tail(), and genlist_back().
void genlist_unique | ( | struct genlist * | pgenlist | ) |
Remove all duplicates of element from every consecutive group of equal elements in the list.
Definition at line 282 of file genlist.c.
Referenced by _list_unique().
void genlist_unique_full | ( | struct genlist * | pgenlist, |
genlist_comp_fn_t | comp_data_func | ||
) |
Remove all duplicates of element from every consecutive group of equal elements in the list (equality is assumed from if the compare function return TRUE).
Definition at line 292 of file genlist.c.
Referenced by _list_unique_full(), and genlist_unique().