1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491 */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG. */
5 /* This program is free software: you can redistribute it and/or modify */
6 /* it under the terms of the GNU General Public License as published by */
7 /* the Free Software Foundation, either version 2 of the License, or */
8 /* (at your option) any later version. */
10 /* This program is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU General Public License for more details. */
15 /* You should have received a copy of the GNU General Public License */
16 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* You may also obtain this software under a propriety license from Microchip. */
19 /* Please contact Microchip for further information. */
20 /*------------------------------------------------------------------------------------------------*/
24 * \brief Internal header file of the doubly linked list.
26 * \cond UCS_INTERNAL_DOC
34 /*------------------------------------------------------------------------------------------------*/
36 /*------------------------------------------------------------------------------------------------*/
37 #include "ucs_types_cfg.h"
44 /*------------------------------------------------------------------------------------------------*/
45 /* Type definitions */
46 /*------------------------------------------------------------------------------------------------*/
47 /*! \brief Callback signature used by foreach-function
48 * \param d_ptr Reference to the data of the current node
49 * \param up_ptr Reference to the user data
50 * \return true: Stop the for-each-loop
51 * \return false: Continue the for-each-loop
53 typedef bool(*Dl_ForeachFunc_t)(void *d_ptr, void *ud_ptr);
55 /*------------------------------------------------------------------------------------------------*/
57 /*------------------------------------------------------------------------------------------------*/
58 /*! \brief Standard return values of the list module. */
61 DL_OK, /*!< \brief No error */
62 DL_UNKNOWN_NODE, /*!< \brief Unknown node */
63 DL_STOPPED /*!< \brief Search process stopped */
67 /*------------------------------------------------------------------------------------------------*/
69 /*------------------------------------------------------------------------------------------------*/
70 /*! \brief Class structure of doubly linked list node. */
71 typedef struct DlNode_
73 struct DlNode_ *prev; /*!< \brief Reference to previous node in list */
74 struct DlNode_ *next; /*!< \brief Reference to next node in list */
75 void *data_ptr; /*!< \brief Reference to optional data */
76 bool in_use; /*!< \brief Flag which signals that the node is in use */
80 /*! \brief Class structure of the doubly linked list. */
81 typedef struct CDlList_
83 struct DlNode_ *head; /*!< \brief Reference to head of the list */
84 struct DlNode_ *tail; /*!< \brief Reference to tail of the list */
85 uint16_t size; /*!< \brief Number of nodes in the list */
86 void *ucs_user_ptr; /*!< \brief User reference that needs to be passed in every callback function */
90 /*------------------------------------------------------------------------------------------------*/
91 /* Prototypes of class CDlList */
92 /*------------------------------------------------------------------------------------------------*/
93 extern void Dl_Ctor(CDlList *self, void *ucs_user_ptr);
94 extern void Dl_InsertAfter(CDlList *self, CDlNode *node, CDlNode *new_node);
95 extern void Dl_InsertBefore(CDlList *self, CDlNode *node, CDlNode *new_node);
96 extern void Dl_InsertHead(CDlList *self, CDlNode *new_node);
97 extern void Dl_InsertTail(CDlList *self, CDlNode *new_node);
98 extern Dl_Ret_t Dl_Remove(CDlList *self, CDlNode *node);
99 extern CDlNode * Dl_PopHead(CDlList *self);
100 extern CDlNode * Dl_PopTail(CDlList *self);
101 extern CDlNode * Dl_PeekHead(CDlList *self);
102 extern CDlNode * Dl_PeekTail(CDlList *self);
103 extern CDlNode * Dl_Foreach(CDlList *self, Dl_ForeachFunc_t func_ptr, void *user_data_ptr);
104 extern bool Dl_IsNodeInList(CDlList *self, const CDlNode *node);
105 extern void Dl_AppendList(CDlList *self, CDlList *list_ptr);
106 extern uint16_t Dl_GetSize(CDlList *self);
108 /*------------------------------------------------------------------------------------------------*/
109 /* Prototypes of class CDlNode */
110 /*------------------------------------------------------------------------------------------------*/
111 extern void Dln_Ctor(CDlNode *self, void *data_ptr);
112 extern void Dln_SetData(CDlNode *self, void *data_ptr);
113 extern void * Dln_GetData(CDlNode *self);
114 extern bool Dln_IsNodePartOfAList(CDlNode *self);
120 #endif /* #ifndef UCS_DL_H */
127 /*------------------------------------------------------------------------------------------------*/
129 /*------------------------------------------------------------------------------------------------*/