1 /*
2     linkedlist: generic c linked list routines
3     Copyright (c) 2004-2016 Adrian M. Gin
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License v2 as published by
7     the Free Software Foundation;
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 
18     The above copyright notice and this permission notice shall be
19     included in all copies or substantial portions of the Software.
20 
21 */
22 
23 #ifdef __cplusplus    /* Insert start of extern C construct */
24 extern "C" {
25 #endif
26 
27 #ifndef _LINKEDLIST_H
28 #define _LINKEDLIST_H
29 
30 #include <stdint.h>
31 #include <stdlib.h>
32 
33 typedef struct LIST_NODE_t
34 {
35   struct LIST_NODE_t* next;
36   struct LIST_NODE_t* prev;
37    void* data;
38 } LIST_NODE_t;
39 
40 typedef struct
41 {
42    LIST_NODE_t* first;
43    LIST_NODE_t* last;
44 } LINKED_LIST_t;
45 
46 void LL_DeleteList(LINKED_LIST_t* linkedList);
47 void LL_DeleteListAndData(LINKED_LIST_t* linkedList);
48 
49 LIST_NODE_t* LL_NewNode(void* data);
50 void* LL_PopData(LINKED_LIST_t* linkedList);
51 void LL_AppendData(LINKED_LIST_t* linkedList, void* data);
52 void LL_InsertAfter(LINKED_LIST_t* linkedList, LIST_NODE_t* node, LIST_NODE_t* newNode);
53 void LL_InsertBefore(LINKED_LIST_t* linkedList, LIST_NODE_t* node, LIST_NODE_t* newNode);
54 void LL_InsertBeginning(LINKED_LIST_t* linkedList, LIST_NODE_t* newNode);
55 void LL_InsertEnd(LINKED_LIST_t* linkedList, LIST_NODE_t* newNode);
56 void LL_Remove(LINKED_LIST_t* linkedList, LIST_NODE_t* node);
57 uint16_t LL_Count(LINKED_LIST_t* linkedList);
58 LIST_NODE_t* LL_ReturnNodeFromIndex(LINKED_LIST_t* linkedList, uint16_t item);
59 void* LL_ReturnNodeDataFromIndex(LINKED_LIST_t* linkedList, uint16_t item);
60 
61 
62 //For FreeRTOS
63 //#define LL_Malloc(size)    pvPortMalloc(size)
64 //#define LL_Free(handle)    vPortFree(handle)
65 
66 #define LL_Malloc(size)    malloc(size)
67 #define LL_Free(handle)    free(handle)
68 
69 #endif
70 
71 #ifdef __cplusplus  /* Insert end of extern C construct. */
72 }                   /* The C header file can now be */
73 #endif              /* included in either C or C++ code. */
74