Astarte Device SDK ESP32
ESP32 device SDK for the Astarte platform
Loading...
Searching...
No Matches
astarte_list.h
1/*
2 * (C) Copyright 2018, Davide Bettio, davide@uninstall.it.
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later OR Apache-2.0
5 */
6
7#ifndef _ASTARTE_LIST_H_
8#define _ASTARTE_LIST_H_
9
10#include <stdbool.h>
11#include <stdlib.h>
12
14{
15 struct astarte_list_head_t *next;
16 struct astarte_list_head_t *prev;
17} __attribute__((deprecated("Please use the typedef astarte_list_head_t")));
18
19#pragma GCC diagnostic push
20#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
22#pragma GCC diagnostic pop
23
25{
27 const void *value;
28} __attribute__((deprecated("Please use the typedef astarte_ptr_list_entry_t")));
29
30#pragma GCC diagnostic push
31#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
33#pragma GCC diagnostic pop
34
41#define GET_LIST_ENTRY(list_item, type, list_head_member) \
42 ((type *) (((char *) (list_item)) - ((unsigned long) &((type *) 0)->list_head_member)))
43
49#define LIST_FOR_EACH(item, head) for (item = (head)->next; item != (head); item = item->next)
50
57#define MUTABLE_LIST_FOR_EACH(item, tmp, head) \
58 for (item = (head)->next, tmp = item->next; item != (head); item = tmp, tmp = item->next)
59
68static inline void astarte_list_insert(
69 astarte_list_head_t *new_item, astarte_list_head_t *prev_head, astarte_list_head_t *next_head)
70{
71 new_item->prev = prev_head;
72 new_item->next = next_head;
73 next_head->prev = new_item;
74 prev_head->next = new_item;
75}
76
86static inline void astarte_list_append(astarte_list_head_t *head, astarte_list_head_t *new_item)
87{
88 astarte_list_insert(new_item, head->prev, head);
89}
90
98static inline void astarte_list_prepend(astarte_list_head_t *head, astarte_list_head_t *new_item)
99{
100 astarte_list_insert(new_item, head, head->next);
101}
102
111static inline void astarte_list_remove(astarte_list_head_t *remove_item)
112{
113 remove_item->prev->next = remove_item->next;
114 remove_item->next->prev = remove_item->prev;
115}
116
123static inline void astarte_list_init(astarte_list_head_t *head)
124{
125 head->prev = head;
126 head->next = head;
127}
128
135static inline bool astarte_list_is_empty(astarte_list_head_t *list_item)
136{
137 return (list_item->next == list_item) && (list_item->prev == list_item);
138}
139
147static inline astarte_list_head_t *astarte_list_first(astarte_list_head_t *head)
148{
149 return head->next;
150}
151
159static inline astarte_list_head_t *astarte_list_last(astarte_list_head_t *head)
160{
161 return head->prev;
162}
163
164#endif
Definition astarte_list.h:14
Definition astarte_list.h:25