3 * All rights reserved.
\r
6 * SPDX-License-Identifier: BSD-3-Clause
\r
9 #ifndef _GENERIC_LIST_H_
\r
10 #define _GENERIC_LIST_H_
\r
12 /*!*********************************************************************************
\r
13 *************************************************************************************
\r
15 *************************************************************************************
\r
16 ********************************************************************************** */
\r
18 /*! *********************************************************************************
\r
19 *************************************************************************************
\r
20 * Public macro definitions
\r
21 *************************************************************************************
\r
22 ********************************************************************************** */
\r
24 /*! *********************************************************************************
\r
25 *************************************************************************************
\r
26 * Public type definitions
\r
27 *************************************************************************************
\r
28 ********************************************************************************** */
\r
29 /*! @brief The list status */
\r
30 typedef enum _list_status
\r
32 kLIST_Ok = kStatus_Success, /*!< Success */
\r
33 kLIST_Full = MAKE_STATUS(kStatusGroup_LIST, 1), /*!< FULL */
\r
34 kLIST_Empty = MAKE_STATUS(kStatusGroup_LIST, 2), /*!< Empty */
\r
35 kLIST_OrphanElement = MAKE_STATUS(kStatusGroup_LIST, 3), /*!< Orphan Element */
\r
38 /*! @brief The list structure*/
\r
39 typedef struct list_tag
\r
41 struct list_element_tag *head; /*!< list head */
\r
42 struct list_element_tag *tail; /*!< list tail */
\r
43 uint16_t size; /*!< list size */
\r
44 uint16_t max; /*!< list max number of elements */
\r
45 }list_t, *list_handle_t;
\r
47 /*! @brief The list element*/
\r
48 typedef struct list_element_tag
\r
50 struct list_element_tag *next; /*!< next list element */
\r
51 struct list_element_tag *prev; /*!< previous list element */
\r
52 struct list_tag *list; /*!< pointer to the list */
\r
53 }list_element_t, *list_element_handle_t;
\r
55 /*! *********************************************************************************
\r
56 *************************************************************************************
\r
58 *************************************************************************************
\r
59 ********************************************************************************** */
\r
60 /*******************************************************************************
\r
62 ******************************************************************************/
\r
64 #if defined(__cplusplus)
\r
66 #endif /* _cplusplus */
\r
68 * @brief Initialize the list.
\r
70 * This function initialize the list.
\r
72 * @param list - List handle to initialize.
\r
73 * @param max - Maximum number of elements in list. 0 for unlimited.
\r
75 void LIST_Init(list_handle_t list, uint32_t max);
\r
78 * @brief Gets the list that contains the given element.
\r
81 * @param element - Handle of the element.
\r
82 * @retval NULL if element is orphan, Handle of the list the element is inserted into.
\r
84 list_handle_t LIST_GetList(list_element_handle_t element);
\r
87 * @brief Links element to the head of the list.
\r
89 * @param list - Handle of the list.
\r
90 * @param element - Handle of the element.
\r
91 * @retval kLIST_Full if list is full, kLIST_Ok if insertion was successful.
\r
93 list_status_t LIST_AddHead(list_handle_t list, list_element_handle_t element);
\r
96 * @brief Links element to the tail of the list.
\r
98 * @param list - Handle of the list.
\r
99 * @param element - Handle of the element.
\r
100 * @retval kLIST_Full if list is full, kLIST_Ok if insertion was successful.
\r
102 list_status_t LIST_AddTail(list_handle_t list, list_element_handle_t element);
\r
105 * @brief Unlinks element from the head of the list.
\r
107 * @param list - Handle of the list.
\r
109 * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
\r
111 list_element_handle_t LIST_RemoveHead(list_handle_t list);
\r
114 * @brief Gets head element handle.
\r
116 * @param list - Handle of the list.
\r
118 * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
\r
120 list_element_handle_t LIST_GetHead(list_handle_t list);
\r
123 * @brief Gets next element handle for given element handle.
\r
125 * @param element - Handle of the element.
\r
127 * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
\r
129 list_element_handle_t LIST_GetNext(list_element_handle_t element);
\r
132 * @brief Gets previous element handle for given element handle.
\r
134 * @param element - Handle of the element.
\r
136 * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
\r
138 list_element_handle_t LIST_GetPrev(list_element_handle_t element);
\r
141 * @brief Unlinks an element from its list.
\r
143 * @param element - Handle of the element.
\r
145 * @retval kLIST_OrphanElement if element is not part of any list.
\r
146 * @retval kLIST_Ok if removal was successful.
\r
148 list_status_t LIST_RemoveElement(list_element_handle_t element);
\r
151 * @brief Links an element in the previous position relative to a given member of a list.
\r
153 * @param element - Handle of the element.
\r
154 * @param newElement - New element to insert before the given member.
\r
156 * @retval kLIST_OrphanElement if element is not part of any list.
\r
157 * @retval kLIST_Ok if removal was successful.
\r
159 list_status_t LIST_AddPrevElement(list_element_handle_t element, list_element_handle_t newElement);
\r
162 * @brief Gets the current size of a list.
\r
164 * @param list - Handle of the list.
\r
166 * @retval Current size of the list.
\r
168 uint32_t LIST_GetSize(list_handle_t list);
\r
171 * @brief Gets the number of free places in the list.
\r
173 * @param list - Handle of the list.
\r
175 * @retval Available size of the list.
\r
177 uint32_t LIST_GetAvailableSize(list_handle_t list);
\r
181 #if defined(__cplusplus)
\r
185 #endif /*_GENERIC_LIST_H_*/
\r