Initial Commit
[apps/agl-service-unicens.git] / ucs2-lib / inc / ucs_dl.h
1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491                                                                            */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG.                              */
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 as published by                           */
7 /* the Free Software Foundation, either version 2 of the License, or                              */
8 /* (at your option) any later version.                                                            */
9 /*                                                                                                */
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.                                                   */
14 /*                                                                                                */
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/>.                          */
17 /*                                                                                                */
18 /* You may also obtain this software under a propriety license from Microchip.                    */
19 /* Please contact Microchip for further information.                                              */
20 /*------------------------------------------------------------------------------------------------*/
21
22 /*!
23  * \file
24  * \brief Internal header file of the doubly linked list.
25  *
26  * \cond UCS_INTERNAL_DOC
27  * \addtogroup G_DL
28  * @{
29  */
30
31 #ifndef UCS_DL_H
32 #define UCS_DL_H
33
34 /*------------------------------------------------------------------------------------------------*/
35 /* Includes                                                                                       */
36 /*------------------------------------------------------------------------------------------------*/
37 #include "ucs_types_cfg.h"
38
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #endif
43
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
52  */
53 typedef bool(*Dl_ForeachFunc_t)(void *d_ptr, void *ud_ptr);
54
55 /*------------------------------------------------------------------------------------------------*/
56 /* Enumerators                                                                                    */
57 /*------------------------------------------------------------------------------------------------*/
58 /*! \brief   Standard return values of the list module. */
59 typedef enum Dl_Ret_
60 {
61     DL_OK,                      /*!< \brief No error */
62     DL_UNKNOWN_NODE,            /*!< \brief Unknown node */
63     DL_STOPPED                  /*!< \brief Search process stopped */
64
65 } Dl_Ret_t;
66
67 /*------------------------------------------------------------------------------------------------*/
68 /* Structures                                                                                     */
69 /*------------------------------------------------------------------------------------------------*/
70 /*! \brief Class structure of doubly linked list node. */
71 typedef struct DlNode_
72 {
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 */
77
78 } CDlNode;
79
80 /*! \brief Class structure of the doubly linked list. */
81 typedef struct CDlList_
82 {
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 */
87
88 } CDlList;
89
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);
107
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);
115
116 #ifdef __cplusplus
117 }   /* extern "C" */
118 #endif
119
120 #endif  /* #ifndef UCS_DL_H */
121
122 /*!
123  * @}
124  * \endcond
125  */
126
127 /*------------------------------------------------------------------------------------------------*/
128 /* End of file                                                                                    */
129 /*------------------------------------------------------------------------------------------------*/
130