|
libUPnP
1.8.4
|
#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. More... | |
| ListNode * | ListAddHead (LinkedList *list, void *item) |
| Adds a node to the head of the list. Node gets immediately after list head. More... | |
| ListNode * | ListAddTail (LinkedList *list, void *item) |
| Adds a node to the tail of the list. Node gets added immediately before list.tail. More... | |
| ListNode * | ListAddAfter (LinkedList *list, void *item, ListNode *bnode) |
| Adds a node after the specified node. Node gets added immediately after bnode. More... | |
| ListNode * | ListAddBefore (LinkedList *list, void *item, ListNode *anode) |
| Adds a node before the specified node. Node gets added immediately before anode. More... | |
| void * | ListDelNode (LinkedList *list, ListNode *dnode, int freeItem) |
| Removes a node from the list. The memory for the node is freed. More... | |
| int | ListDestroy (LinkedList *list, int freeItem) |
| Removes all memory associated with list nodes. Does not free LinkedList *list. More... | |
| ListNode * | ListHead (LinkedList *list) |
| Returns the head of the list. More... | |
| ListNode * | ListTail (LinkedList *list) |
| Returns the tail of the list. More... | |
| ListNode * | ListNext (LinkedList *list, ListNode *node) |
| Returns the next item in the list. More... | |
| ListNode * | ListPrev (LinkedList *list, ListNode *node) |
| Returns the previous item in the list. More... | |
| ListNode * | ListFind (LinkedList *list, ListNode *start, void *item) |
| Finds the specified item in the list. More... | |
| long | ListSize (LinkedList *list) |
| Returns the size of the list. More... | |
| 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.
Referenced by ListAddHead().
| 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.
Referenced by ListAddTail().
| 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, and ListAddAfter().
| 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 ListAddBefore(), and LINKEDLIST::tail.
Referenced by BumpPriority().
| 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.
Referenced by BumpPriority(), and ListDestroy().
| 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 FreeListDestroy(), LINKEDLIST::freeNodeList, LINKEDLIST::head, ListDelNode(), 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.
Referenced by print_http_headers().
| 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, FreeListInit(), LINKEDLIST::freeNodeList, and LINKEDLIST::size.
| 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.
Referenced by print_http_headers().
| 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.
1.8.13