UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches

Manage a linked list (for internal use only). More...

#include "LinkedList.hpp"
+ Include dependency graph for LinkedList.cpp:

Go to the source code of this file.

Functions

int ListInit (LinkedList *list, cmp_routine cmp_func, free_function free_func)
 Initializes LinkedList. Must be called first and only once for List.
 
ListNodeListAddHead (LinkedList *list, void *item)
 Adds a node to the head of the list. Node gets immediately after list head.
 
ListNodeListAddTail (LinkedList *list, void *item)
 Adds a node to the tail of the list. Node gets added immediately before list.tail.
 
ListNodeListAddAfter (LinkedList *list, void *item, ListNode *bnode)
 Adds a node after the specified node. Node gets added immediately after bnode.
 
ListNodeListAddBefore (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.
 
ListNodeListHead (LinkedList *list)
 Returns the head of the list.
 
ListNodeListTail (LinkedList *list)
 Returns the tail of the list.
 
ListNodeListNext (LinkedList *list, ListNode *node)
 Returns the next item in the list.
 
ListNodeListPrev (LinkedList *list, ListNode *node)
 Returns the previous item in the list.
 
ListNodeListFind (LinkedList *list, ListNode *start, void *item)
 Finds the specified item in the list.
 
long ListSize (LinkedList *list)
 Returns the size of the list.
 
Scope restricted to file
int anonymous_namespace{LinkedList.cpp}::freeListNode (ListNode *node, LinkedList *list)
 Free list node.
 
ListNodeanonymous_namespace{LinkedList.cpp}::CreateListNode (void *item, LinkedList *list)
 Dynamically creates a list node.
 

Variables

constexpr int FREELISTSIZE {100}
 Size of a free list.
 

Detailed Description

Manage a linked list (for internal use only).

Because this is for internal use, parameters are NOT checked for validity. The caller must ensure valid parameters.

Definition in file LinkedList.cpp.

Function Documentation

◆ ListInit()

int ListInit ( LinkedList list,
cmp_routine  cmp_func,
free_function  free_func 
)

Initializes LinkedList. Must be called first and only once for List.

Returns
On success: 0
On error: EOUTOFMEM
Parameters
[in]listMust be valid, non null, pointer to a linked list.
[in]cmp_funcFunction used to compare items. (May be NULL).
[in]free_funcFunction used to free items. (May be NULL).

Definition at line 95 of file LinkedList.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ListAddHead()

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.

Returns
On success: The pointer to the ListNode.
On error: nullptr
Parameters
[in]listMust be valid, non null, pointer to a linked list.
[in]itemItem to be added.

Definition at line 119 of file LinkedList.cpp.

+ Here is the call graph for this function:

◆ ListAddTail()

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.

Returns
On success: The pointer to the ListNode.
On error: nullptr
Parameters
[in]listMust be valid, non null, pointer to a linked list.
[in]itemItem to be added.

Definition at line 128 of file LinkedList.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ListAddAfter()

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.

Returns
On success: The pointer to the ListNode.
On error: nullptr
Parameters
[in]listMust be valid, non null, pointer to a linked list.
[in]itemItem to be added.
[in]bnodeNode to add after.

Definition at line 137 of file LinkedList.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ListAddBefore()

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.

Returns
On success: The pointer to the ListNode.
On error: nullptr
Parameters
[in]listMust be valid, non null, pointer to a linked list.
[in]itemItem to be added.
[in]anodeNode to add in front of.

Definition at line 160 of file LinkedList.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ListDelNode()

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.

Returns
On success: The pointer to the item stored in the node or nullptr if the item is freed.
Parameters
[in]listMust be valid, non null, pointer to a linked list.
[in]dnodeNode to delete.
[in]freeItemif !0 then item is freed using free function. If 0 (or free function is NULL) then item is not freed.

Definition at line 183 of file LinkedList.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

Returns
On success: 0 On error: EINVAL
Parameters
[in]listMust be valid, non null, pointer to a linked list.
[in]freeItemIf !0 then item is freed using free function. If 0 (or free function is NULL) then item is not freed.

Definition at line 205 of file LinkedList.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ListHead()

ListNode * ListHead ( LinkedList list)

Returns the head of the list.

Precondition: The list has been initialized.

Returns
On success: The head of the list. nullptr if list is empty.
Parameters
list[0] Must be valid, non null, pointer to a linked list.

Definition at line 223 of file LinkedList.cpp.

+ Here is the caller graph for this function:

◆ ListTail()

ListNode * ListTail ( LinkedList list)

Returns the tail of the list.

Precondition: The list has been initialized.

Returns
On success: The tail of the list. nullptr if list is empty.
Parameters
[in]listMust be valid, non null, pointer to a linked list.

Definition at line 235 of file LinkedList.cpp.

◆ ListNext()

ListNode * ListNext ( LinkedList list,
ListNode node 
)

Returns the next item in the list.

Precondition: The list has been initialized.

Returns
On success: The next item in the list, nullptr if there are no more items in list.
Parameters
[in]listMust be valid, non null, pointer to a linked list.
[in]nodeNode from the list.

Definition at line 247 of file LinkedList.cpp.

+ Here is the caller graph for this function:

◆ ListPrev()

ListNode * ListPrev ( LinkedList list,
ListNode node 
)

Returns the previous item in the list.

Precondition: The list has been initialized.

Returns
On success: The previous item in the list, nullptr if there are no more items in list.
Parameters
[in]listMust be valid, non null, pointer to a linked list.
[in]nodeNode from the list.

Definition at line 259 of file LinkedList.cpp.

◆ ListFind()

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 nullptr then compares items as pointers.

Precondition: The list has been initialized.

Returns
On success: The node containing the item, nullptr if no node contains the item.
Parameters
[in]listMust be valid, non null, pointer to a linked list.
[in]startThe node to start from, nullptr if to start from beginning.
[in]itemThe item to search for.

Definition at line 272 of file LinkedList.cpp.

+ Here is the caller graph for this function:

◆ ListSize()

long ListSize ( LinkedList list)

Returns the size of the list.

Precondition: The list has been initialized.

Returns
On success: The number of items in the list.
Parameters
[in]listMust be valid, non null, pointer to a linked list.

Definition at line 300 of file LinkedList.cpp.

+ Here is the caller graph for this function:

Variable Documentation

◆ FREELISTSIZE

constexpr int FREELISTSIZE {100}
constexpr

Size of a free list.

Definition at line 46 of file LinkedList.cpp.