EII Message Bus C Reference
linkedlist.h
Go to the documentation of this file.
1 // Copyright (c) 2019 Intel Corporation.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
26 #ifndef _EII_MSGENV_LINKEDLIST_H
27 #define _EII_MSGENV_LINKEDLIST_H
28 
29 #include <stdbool.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif // __cplusplus
34 
38 typedef enum {
39  LL_SUCCESS = 0,
40  LL_ERR_APPEND = 1,
41  LL_ERR_NOT_FOUND = 2,
43 
44 // Forward declaration of node_t
45 typedef struct _node_t node_t;
46 
50 typedef struct _node_t {
51  // Pointer to next node
52  node_t* next;
53 
54  // Value at the current node
55  void* value;
56 
57  // Function to free the value
58  void (*free)(void*);
59 } node_t;
60 
64 typedef struct {
65  // Root element of the linked list
66  node_t* root;
67  int len;
68 } linkedlist_t;
69 
80 #define LINKEDLIST_FOREACH(LL, VALUE_TYPE, CODE) { \
81  node_t* curr = LL->root; \
82  while(curr != NULL) { \
83  VALUE_TYPE* value = (VALUE_TYPE*) curr->value; \
84  CODE \
85  curr = curr->next; \
86  } \
87 }
88 
95 
99 node_t* linkedlist_node_new(void* value, void (*free_fn)(void*));
100 
109 
117 node_t* linkedlist_get_at(linkedlist_t* ll, int idx);
118 
126 
134 
135 #ifdef __cplusplus
136 }
137 #endif // __cplusplus
138 
139 #endif // _EII_MSGENV_LINKEDLIST_H
linkedlist_new
linkedlist_t * linkedlist_new()
_node_t
Definition: linkedlist.h:50
linkedlist_ret_t
linkedlist_ret_t
Definition: linkedlist.h:38
linkedlist_add
linkedlist_ret_t linkedlist_add(linkedlist_t *ll, node_t *node)
linkedlist_destroy
void linkedlist_destroy(linkedlist_t *ll)
linkedlist_node_new
node_t * linkedlist_node_new(void *value, void(*free_fn)(void *))
linkedlist_get_at
node_t * linkedlist_get_at(linkedlist_t *ll, int idx)
linkedlist_t
Definition: linkedlist.h:64
node_t
struct _node_t node_t
Definition: linkedlist.h:45
linkedlist_remove_at
linkedlist_ret_t linkedlist_remove_at(linkedlist_t *ll, int idx)