libUPnP 1.14.19
|
#include "FreeList.h"
Go to the source code of this file.
Data Structures | |
struct | LISTNODE |
struct | LINKEDLIST |
Macros | |
#define | EOUTOFMEM (-7 & 1 << 29) |
#define | FREELISTSIZE 100 |
#define | LIST_SUCCESS 1 |
#define | LIST_FAIL 0 |
Typedefs | |
typedef void(* | free_function) (void *arg) |
typedef int(* | cmp_routine) (void *itemA, void *itemB) |
typedef struct LISTNODE | ListNode |
typedef struct LINKEDLIST | LinkedList |
Functions | |
int | ListInit (LinkedList *list, cmp_routine cmp_func, free_function free_func) |
Initializes LinkedList. Must be called first and only once for List. | |
ListNode * | ListAddHead (LinkedList *list, void *item) |
Adds a node to the head of the list. Node gets immediately after list head. | |
ListNode * | ListAddTail (LinkedList *list, void *item) |
Adds a node to the tail of the list. Node gets added immediately before list.tail. | |
ListNode * | ListAddAfter (LinkedList *list, void *item, ListNode *bnode) |
Adds a node after the specified node. Node gets added immediately after bnode. | |
ListNode * | ListAddBefore (LinkedList *list, void *item, ListNode *anode) |
Adds a node before the specified node. Node gets added immediately before anode. | |
void * | ListDelNode (LinkedList *list, ListNode *dnode, int freeItem) |
Removes a node from the list. The memory for the node is freed. | |
int | ListDestroy (LinkedList *list, int freeItem) |
Removes all memory associated with list nodes. Does not free LinkedList *list. | |
ListNode * | ListHead (LinkedList *list) |
Returns the head of the list. | |
ListNode * | ListTail (LinkedList *list) |
Returns the tail of the list. | |
ListNode * | ListNext (LinkedList *list, ListNode *node) |
Returns the next item in the list. | |
ListNode * | ListPrev (LinkedList *list, ListNode *node) |
Returns the previous item in the list. | |
ListNode * | ListFind (LinkedList *list, ListNode *start, void *item) |
Finds the specified item in the list. | |
long | ListSize (LinkedList *list) |
Returns the size of the list. | |
typedef int(* cmp_routine) (void *itemA, void *itemB) |
Function for comparing list items. Returns 1 if itemA==itemB
typedef void(* free_function) (void *arg) |
Function for freeing list items.
typedef struct LINKEDLIST LinkedList |
Linked list (no protection).
Because this is for internal use, parameters are NOT checked for validity. The first item of the list is stored at node: head->next The last item of the list is stored at node: tail->prev If head->next=tail, then list is empty. To iterate through the list:
LinkedList g; ListNode *temp = NULL; for (temp = ListHead(g);temp!=NULL;temp = ListNext(g,temp)) { }
Linked list node. Stores generic item and pointers to next and prev.
ListNode * ListAddAfter | ( | LinkedList * | list, |
void * | item, | ||
ListNode * | bnode | ||
) |
Adds a node after the specified node. Node gets added immediately after bnode.
Precondition: The list has been initialized.
list | Must be valid, non null, pointer to a linked list. |
item | Item to be added. |
bnode | Node to add after. |
References LINKEDLIST::size.
ListNode * ListAddBefore | ( | LinkedList * | list, |
void * | item, | ||
ListNode * | anode | ||
) |
Adds a node before the specified node. Node gets added immediately before anode.
Precondition: The list has been initialized.
list | Must be valid, non null, pointer to a linked list. |
item | Item to be added. |
anode | Node to add in front of. |
References LINKEDLIST::size.
ListNode * ListAddHead | ( | LinkedList * | list, |
void * | item | ||
) |
Adds a node to the head of the list. Node gets immediately after list head.
Precondition: The list has been initialized.
list | Must be valid, non null, pointer to a linked list. |
item | Item to be added. |
References LINKEDLIST::head.
ListNode * ListAddTail | ( | LinkedList * | list, |
void * | item | ||
) |
Adds a node to the tail of the list. Node gets added immediately before list.tail.
Precondition: The list has been initialized.
list | Must be valid, non null, pointer to a linked list. |
item | Item to be added. |
References LINKEDLIST::tail.
void * ListDelNode | ( | LinkedList * | list, |
ListNode * | dnode, | ||
int | freeItem | ||
) |
Removes a node from the list. The memory for the node is freed.
Precondition: The list has been initialized.
list | Must be valid, non null, pointer to a linked list. |
dnode | Node to delete. |
freeItem | if !0 then item is freed using free function. If 0 (or free function is NULL) then item is not freed. |
References LINKEDLIST::free_func, LINKEDLIST::head, LINKEDLIST::size, and LINKEDLIST::tail.
int ListDestroy | ( | LinkedList * | list, |
int | freeItem | ||
) |
Removes all memory associated with list nodes. Does not free LinkedList *list.
Precondition: The list has been initialized.
list | Must be valid, non null, pointer to a linked list. |
freeItem | if !0 then item is freed using free function. If 0 (or free function is NULL) then item is not freed. |
References LINKEDLIST::freeNodeList, LINKEDLIST::head, LINKEDLIST::size, and LINKEDLIST::tail.
ListNode * ListFind | ( | LinkedList * | list, |
ListNode * | start, | ||
void * | item | ||
) |
Finds the specified item in the list.
Uses the compare function specified in ListInit. If compare function is NULL then compares items as pointers.
Precondition: The list has been initialized.
list | Must be valid, non null, pointer to a linked list. |
start | The node to start from, NULL if to start from beginning. |
item | The item to search for. |
References LINKEDLIST::cmp_func, LINKEDLIST::head, and LINKEDLIST::tail.
ListNode * ListHead | ( | LinkedList * | list | ) |
Returns the head of the list.
Precondition: The list has been initialized.
list | Must be valid, non null, pointer to a linked list. |
References LINKEDLIST::head, and LINKEDLIST::size.
int ListInit | ( | LinkedList * | list, |
cmp_routine | cmp_func, | ||
free_function | free_func | ||
) |
Initializes LinkedList. Must be called first and only once for List.
0
on success. EOUTOFMEM
on failure. list | Must be valid, non null, pointer to a linked list. |
cmp_func | Function used to compare items. (May be NULL). |
free_func | Function used to free items. (May be NULL). |
References LINKEDLIST::cmp_func, LINKEDLIST::free_func, LINKEDLIST::freeNodeList, LINKEDLIST::head, LINKEDLIST::size, and LINKEDLIST::tail.
ListNode * ListNext | ( | LinkedList * | list, |
ListNode * | node | ||
) |
Returns the next item in the list.
Precondition: The list has been initialized.
list | Must be valid, non null, pointer to a linked list. |
node | Node from the list. |
References LINKEDLIST::tail.
ListNode * ListPrev | ( | LinkedList * | list, |
ListNode * | node | ||
) |
Returns the previous item in the list.
Precondition: The list has been initialized.
list | Must be valid, non null, pointer to a linked list. |
node | Node from the list. |
References LINKEDLIST::head.
long ListSize | ( | LinkedList * | list | ) |
Returns the size of the list.
Precondition: The list has been initialized.
list | Must be valid, non null, pointer to a linked list. |
References LINKEDLIST::size.
ListNode * ListTail | ( | LinkedList * | list | ) |
Returns the tail of the list.
Precondition: The list has been initialized.
list | Must be valid, non null, pointer to a linked list. |
References LINKEDLIST::size, and LINKEDLIST::tail.