UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
LinkedList.hpp
Go to the documentation of this file.
1#ifndef COMPA_LINKED_LIST_HPP
2#define COMPA_LINKED_LIST_HPP
3/*******************************************************************************
4 *
5 * Copyright (c) 2000-2003 Intel Corporation
6 * All rights reserved.
7 * Copyright (C) 2021+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
8 * Redistribution only with this Copyright remark. Last modified: 2024-03-06
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 *
13 * * Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * * Neither name of Intel Corporation nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
30 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 ******************************************************************************/
44#include "FreeList.hpp"
45
47#define EOUTOFMEM (-7 & 1 << 29)
48
50typedef void (*free_function)(void* arg);
51
53typedef int (*cmp_routine)(void* itemA, void* itemB);
54
58struct ListNode {
59 struct ListNode* prev;
60 struct ListNode* next;
61 void* item;
62};
63
93
101int ListInit(
103 LinkedList* list,
105 cmp_routine cmp_func,
107 free_function free_func);
108
122 LinkedList* list,
124 void* item);
125
138 LinkedList* list,
140 void* item);
141
154 LinkedList* list,
156 void* item,
158 ListNode* bnode);
159
172 LinkedList* list,
174 void* item,
176 ListNode* anode);
177
187void* ListDelNode(
189 LinkedList* list,
191 ListNode* dnode,
194 int freeItem);
195
206int ListDestroy(
208 LinkedList* list,
211 int freeItem);
212
223 LinkedList* list);
224
235 LinkedList* list);
236
248 LinkedList* list,
250 ListNode* node);
251
263 LinkedList* list,
265 ListNode* node);
266
281 LinkedList* list,
283 ListNode* start,
285 void* item);
286
295long ListSize(
297 LinkedList* list);
298
299#endif /* COMPA_LINKED_LIST_HPP */
Manage a free list (for internal use only).
Stores head and size of free list, as well as mutex for protection.
Definition FreeList.hpp:63
cmp_routine cmp_func
compare function to use
ListNode head
head, first item is stored at: head->next
long ListSize(LinkedList *list)
Returns the size of the list.
int ListDestroy(LinkedList *list, int freeItem)
Removes all memory associated with list nodes. Does not free LinkedList *list.
free_function free_func
free function to use
FreeList freeNodeList
free list to use
ListNode * ListPrev(LinkedList *list, ListNode *node)
Returns the previous item in the list.
long size
size of list
void * ListDelNode(LinkedList *list, ListNode *dnode, int freeItem)
Removes a node from the list. The memory for the node is freed.
void(* free_function)(void *arg)
Function for freeing list items.
ListNode * ListAddBefore(LinkedList *list, void *item, ListNode *anode)
Adds a node before the specified node. Node gets added immediately before anode.
ListNode * ListNext(LinkedList *list, ListNode *node)
Returns the next item in the list.
ListNode * ListAddAfter(LinkedList *list, void *item, ListNode *bnode)
Adds a node after the specified node. Node gets added immediately after bnode.
ListNode * ListHead(LinkedList *list)
Returns the head of the 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 * ListTail(LinkedList *list)
Returns the tail of the list.
ListNode * ListFind(LinkedList *list, ListNode *start, void *item)
Finds the specified item in the list.
int ListInit(LinkedList *list, cmp_routine cmp_func, free_function free_func)
Initializes LinkedList. Must be called first and only once for List.
ListNode tail
tail, last item is stored at: tail->prev
int(* cmp_routine)(void *itemA, void *itemB)
Function for comparing list items. Returns 1 if itemA==itemB.
Linked list node. Stores generic item and pointers to next and prev.
Linked list (no protection).