Freeciv-3.3
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
genlist.h File Reference
#include "fcthread.h"
#include "support.h"

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 genlistgenlist_new (void) fc__warn_unused_result
 
struct genlistgenlist_new_full (genlist_free_fn_t free_data_func) fc__warn_unused_result
 
void genlist_destroy (struct genlist *pgenlist)
 
struct genlistgenlist_copy (const struct genlist *pgenlist) fc__warn_unused_result
 
struct genlistgenlist_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) fc__attribute((nonnull(1)))
 
void genlist_unique (struct genlist *pgenlist)
 
void genlist_unique_full (struct genlist *pgenlist, genlist_comp_fn_t comp_data_func) fc__attribute((nonnull(1)))
 
void genlist_append (struct genlist *pgenlist, void *data) fc__attribute((nonnull(1)))
 
void genlist_prepend (struct genlist *pgenlist, void *data) fc__attribute((nonnull(1)))
 
void genlist_insert (struct genlist *pgenlist, void *data, int idx) fc__attribute((nonnull(1)))
 
void genlist_insert_after (struct genlist *pgenlist, void *data, struct genlist_link *plink) fc__attribute((nonnull(1)))
 
void genlist_insert_before (struct genlist *pgenlist, void *data, struct genlist_link *plink) fc__attribute((nonnull(1)))
 
bool genlist_remove (struct genlist *pgenlist, const void *data) fc__attribute((nonnull(1)))
 
bool genlist_remove_if (struct genlist *pgenlist, genlist_cond_fn_t cond_data_func) fc__attribute((nonnull(1)))
 
int genlist_remove_all (struct genlist *pgenlist, const void *data) fc__attribute((nonnull(1)))
 
int genlist_remove_all_if (struct genlist *pgenlist, genlist_cond_fn_t cond_data_func) fc__attribute((nonnull(1)))
 
void genlist_erase (struct genlist *pgenlist, struct genlist_link *plink) fc__attribute((nonnull(1)))
 
void genlist_pop_front (struct genlist *pgenlist) fc__attribute((nonnull(1)))
 
void genlist_pop_back (struct genlist *pgenlist) fc__attribute((nonnull(1)))
 
int genlist_size (const struct genlist *pgenlist) fc__attribute((nonnull(1)))
 
voidgenlist_get (const struct genlist *pgenlist, int idx)
 
voidgenlist_front (const struct genlist *pgenlist)
 
voidgenlist_back (const struct genlist *pgenlist)
 
struct genlist_linkgenlist_link_get (const struct genlist *pgenlist, int idx) fc__attribute((nonnull(1)))
 
static struct genlist_linkgenlist_head (const struct genlist *pgenlist)
 
struct genlist_linkgenlist_tail (const struct genlist *pgenlist)
 
struct genlist_linkgenlist_search (const struct genlist *pgenlist, const void *data) fc__attribute((nonnull(1)))
 
struct genlist_linkgenlist_search_if (const struct genlist *pgenlist, genlist_cond_fn_t cond_data_func) fc__attribute((nonnull(1)))
 
void genlist_sort (struct genlist *pgenlist, int(*compar)(const void *, const void *))
 
void genlist_shuffle (struct genlist *pgenlist)
 
void genlist_reverse (struct genlist *pgenlist) fc__attribute((nonnull(1)))
 
void genlist_allocate_mutex (struct genlist *pgenlist)
 
void genlist_release_mutex (struct genlist *pgenlist)
 
static voidgenlist_link_data (const struct genlist_link *plink)
 
static fc__warn_unused_result struct genlist_linkgenlist_link_prev (const struct genlist_link *plink)
 
static fc__warn_unused_result struct genlist_linkgenlist_link_next (const struct genlist_link *plink)
 

Typedef Documentation

◆ genlist_comp_fn_t

typedef bool(* genlist_comp_fn_t) (const void *, const void *)

Definition at line 54 of file genlist.h.

◆ genlist_cond_fn_t

typedef bool(* genlist_cond_fn_t) (const void *)

Definition at line 53 of file genlist.h.

◆ genlist_copy_fn_t

typedef void *(* genlist_copy_fn_t) (const void *)

Definition at line 52 of file genlist.h.

◆ genlist_free_fn_t

typedef void(* genlist_free_fn_t) (void *)

Definition at line 51 of file genlist.h.

Function Documentation

◆ genlist_allocate_mutex()

void genlist_allocate_mutex ( struct genlist pgenlist)

Allocates list mutex

Definition at line 647 of file genlist.c.

Referenced by _list_allocate_mutex().

◆ genlist_append()

void genlist_append ( struct genlist pgenlist,
void data 
)

Insert an item at the end of the list.

Definition at line 508 of file genlist.c.

Referenced by _list_append().

◆ genlist_back()

void * genlist_back ( const struct genlist pgenlist)

Returns the user-data pointer stored in the last element of the genlist.

Definition at line 237 of file genlist.c.

Referenced by _list_back().

◆ genlist_clear()

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 247 of file genlist.c.

Referenced by _list_clear(), and genlist_destroy().

◆ genlist_copy()

struct genlist * genlist_copy ( const struct genlist pgenlist)

Returns a new genlist that's a copy of the existing one.

Definition at line 157 of file genlist.c.

Referenced by _list_copy().

◆ genlist_copy_full()

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().

◆ genlist_destroy()

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().

◆ genlist_erase()

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 421 of file genlist.c.

Referenced by _list_erase().

◆ genlist_front()

void * genlist_front ( const struct genlist pgenlist)

Returns the user-data pointer stored in the first element of the genlist.

Definition at line 229 of file genlist.c.

Referenced by _list_front().

◆ genlist_get()

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 nullptr. Recall 'idx' can be -1 meaning the last element.

Definition at line 221 of file genlist.c.

Referenced by _list_get(), inputline_handler(), inputline_handler(), inputline_return(), luaconsole_input_handler(), luaconsole_input_handler(), and luaconsole_input_return().

◆ genlist_head()

static struct genlist_link * genlist_head ( const struct genlist pgenlist)
inlinestatic

Definition at line 124 of file genlist.h.

Referenced by _list_head(), genlist_front(), genlist_shuffle(), and genlist_sort().

◆ genlist_insert()

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 456 of file genlist.c.

Referenced by _list_insert().

◆ genlist_insert_after()

void genlist_insert_after ( struct genlist pgenlist,
void data,
struct genlist_link plink 
)

Insert an item after the link. If plink is nullptr, prepend to the list.

Definition at line 480 of file genlist.c.

Referenced by _list_insert_after().

◆ genlist_insert_before()

void genlist_insert_before ( struct genlist pgenlist,
void data,
struct genlist_link plink 
)

Insert an item before the link.

Definition at line 490 of file genlist.c.

Referenced by _list_insert_before().

◆ genlist_link_data()

static void * genlist_link_data ( const struct genlist_link plink)
inlinestatic

Get data pointer of the genlist link

Parameters
plinkLink to get data for
Returns
Pointer to the data

Definition at line 159 of file genlist.h.

Referenced by _list_link_data(), genlist_back(), genlist_front(), and genlist_get().

◆ genlist_link_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 nullptr. Recall 'idx' can be -1 meaning the last element.

Definition at line 202 of file genlist.c.

Referenced by _list_link_get(), and genlist_get().

◆ genlist_link_next()

static fc__warn_unused_result struct genlist_link * genlist_link_next ( const struct genlist_link plink)
inlinestatic

Get next link in genlist

Parameters
plinkLink to start from
Returns
Next link

Definition at line 181 of file genlist.h.

Referenced by _list_link_next().

◆ genlist_link_prev()

static fc__warn_unused_result struct genlist_link * genlist_link_prev ( const struct genlist_link plink)
inlinestatic

Get previous link in genlist

Parameters
plinkLink to start from
Returns
Previous link

Definition at line 170 of file genlist.h.

Referenced by _list_link_prev().

◆ genlist_new()

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().

◆ genlist_new_full()

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().

◆ genlist_pop_back()

void genlist_pop_back ( struct genlist pgenlist)

Remove the last element of the genlist.

Definition at line 441 of file genlist.c.

Referenced by _list_pop_back().

◆ genlist_pop_front()

void genlist_pop_front ( struct genlist pgenlist)

Remove the first element of the genlist.

Definition at line 431 of file genlist.c.

Referenced by _list_pop_front().

◆ genlist_prepend()

void genlist_prepend ( struct genlist pgenlist,
void data 
)

Insert an item at the start of the list.

Definition at line 500 of file genlist.c.

Referenced by _list_prepend(), inputline_return(), and luaconsole_input_return().

◆ genlist_release_mutex()

void genlist_release_mutex ( struct genlist pgenlist)

Releases list mutex

Definition at line 655 of file genlist.c.

Referenced by _list_release_mutex().

◆ genlist_remove()

bool genlist_remove ( struct genlist pgenlist,
const void punlink 
)

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 322 of file genlist.c.

Referenced by _list_remove(), inputline_return(), and luaconsole_input_return().

◆ genlist_remove_all()

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 342 of file genlist.c.

Referenced by _list_remove_all().

◆ genlist_remove_all_if()

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 391 of file genlist.c.

Referenced by _list_remove_all_if().

◆ genlist_remove_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 368 of file genlist.c.

Referenced by _list_remove_if().

◆ genlist_reverse()

void genlist_reverse ( struct genlist pgenlist)

Reverse the order of the elements in the genlist.

Definition at line 625 of file genlist.c.

Referenced by _list_reverse().

◆ genlist_search()

struct genlist_link * genlist_search ( const struct genlist pgenlist,
const void data 
)

Return the link where data is equal to 'data'. Returns nullptr if not found.

This is an O(n) operation. Hence, "search".

Definition at line 518 of file genlist.c.

Referenced by _list_search().

◆ genlist_search_if()

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 nullptr if no match.

Definition at line 536 of file genlist.c.

Referenced by _list_search_if().

◆ genlist_shuffle()

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 595 of file genlist.c.

Referenced by _list_shuffle().

◆ genlist_size()

int genlist_size ( const struct genlist pgenlist)

◆ genlist_sort()

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 563 of file genlist.c.

Referenced by _list_sort().

◆ genlist_tail()

struct genlist_link * genlist_tail ( const struct genlist pgenlist)

Returns the tail link of the genlist.

Definition at line 210 of file genlist.c.

Referenced by _list_tail(), and genlist_back().

◆ genlist_unique()

void genlist_unique ( struct genlist pgenlist)

Remove all duplicates of element from every consecutive group of equal elements in the list.

Definition at line 277 of file genlist.c.

Referenced by _list_unique().

◆ genlist_unique_full()

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 287 of file genlist.c.

Referenced by _list_unique_full(), and genlist_unique().