RTI Connext Micro  Version 2.4.1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
reda_circularlist.h
1 /*
2  * FILE: reda_circularlist.c - Circular list interface
3  *
4  * Copyright 2012-2014 Real-Time Innovations, Inc.
5  *
6  * No duplications, whole or partial, manual or electronic, may be made
7  * without express written permission. Any such copies, or
8  * revisions thereof, must display this notice unaltered.
9  * This code contains trade secrets of Real-Time Innovations, Inc.
10  *
11  * Modification History
12  * --------------------
13  * 04jan2012,tk Written
14  */
15 /*ci
16  * \file
17  *
18  * \brief The REDA CircularList interface provides a platform independent API to
19  * manage a circular lists
20  *
21  * \defgroup REDACircularListClass REDA CircularList
22  *
23  * \ingroup REDAModule
24  *
25  * \details
26  *
27  * The REDA CircularList implements a circular list as a double linked list
28  * where the head is an empty list-node.
29  *
30  */
31 /*ci \addtogroup REDACircularListClass
32  * @{
33  */
34 #ifndef reda_circularlist_h
35 #define reda_circularlist_h
36 
37 #ifndef reda_dll_h
38 #include "reda/reda_dll.h"
39 #endif
40 
41 #ifdef __cplusplus
42 extern "C"
43 {
44 #endif
45 
46 /*ci
47  * \brief REDA_CircularListNode element
48  *
49  * \details
50  *
51  * Any node can be added to a circular list, and all APIs is assumed all nodes
52  * includes this node as the first element:
53  *
54  * \code
55  *
56  * struct MyNode
57  * {
58  * struct REDA_CircularListNode _node;
59  * ...
60  * };
61  * \endcode
62  *
63  * Note that REDA_CircularListNode does not contain a pointer to the node
64  * data (MyNode) above.
65  */
66 struct REDA_CircularListNode
67 {
68  struct REDA_CircularListNode *_prev;
69  struct REDA_CircularListNode *_next;
70 };
71 
72 /*ci
73  * \brief Abstract REDA_CircularList type
74  */
75 typedef struct REDA_CircularListNode REDA_CircularList_T;
76 
77 /*ci
78  * \brief Abstract REDA_CircularListNode type
79  */
80 typedef struct REDA_CircularListNode REDA_CircularListNode_T;
81 
82 /*ci
83  * \brief Initialize a circular list
84  *
85  * \details
86  *
87  * Initialize a circular list to an empty state. A variable of type
88  * REDA_CircularList_T should be initialized exactly once.
89  *
90  * \param[in] list circular list to initialize
91  */
92 REDADllExport void
93 REDA_CircularList_init(REDA_CircularList_T *list);
94 
95 /*ci
96  * \brief Initialize a circular list node
97  *
98  * \details
99  *
100  * Initialize a circular list node. An initialized node is not linked to
101  * any list. It is the callers responsiblilty to ensure that
102  * REDA_CircularListNode_init is <em> not </em> called on linked node.
103  *
104  * \param[in] node circular list node to initialize
105  *
106  */
107 REDADllExport void
108 REDA_CircularListNode_init(struct REDA_CircularListNode *node);
109 
110 /*ci
111  * \brief Link a circular list node after a node already in the list
112  *
113  * \details
114  *
115  * Link a circular list node after another node. Note that circular list
116  * head is a circular list node itself.
117  *
118  * \param[in] after circular list node to link after
119  * \param[in] node circular list node to add to the list
120  *
121  * \sa \ref REDA_CircularList_link_node_after
122  */
123 REDADllExport void
124 REDA_CircularList_link_node_after(struct REDA_CircularListNode *after,
125  struct REDA_CircularListNode *node);
126 
127 /*ci
128  * \brief Unlink a circular list node from a circular list node
129  *
130  * \details
131  *
132  * Remove a node from a circular list. No memory deallocation takes place
133  * when a node is unlinked.
134  *
135  * \param[in] node circular list node to remove
136  * \param[in] node circular list node to add to the list
137  *
138  * \sa \ref REDA_CircularList_link_node_after
139  */
140 REDADllExport void
141 REDA_CircularList_unlink_node(struct REDA_CircularListNode *node);
142 
143 /*ci
144  * \brief Add a circular list node to the end of a circular list
145  *
146  * \details
147  *
148  * Append a circular list node to the end of a circular list
149  *
150  * \param[in] list circular list node to append element to
151  * \param[in] node circular list node to append
152  *
153  */
154 REDADllExport void
155 REDA_CircularList_append(REDA_CircularList_T *list,
156  REDA_CircularListNode_T *node);
157 
158 #define REDA_CircularList_append(list_,node_) \
159  REDA_CircularList_link_node_after((list_)->_prev,node_)
160 
161 /*ci
162  * \brief Add a circular list node to the beginning of the circular list
163  *
164  * \details
165  *
166  * Add a circular list node to the beginning of a circular list
167  *
168  * \param[in] list circular list node to prepend element to
169  * \param[in] node circular list node to prepend
170  *
171  */
172 REDADllExport void
173 REDA_CircularList_prepend(REDA_CircularList_T *list,
174  REDA_CircularListNode_T *node);
175 
176 #define REDA_CircularList_prepend(list_,node_) \
177  REDA_CircularList_link_node_after((list_),node_)
178 
179 /*ci
180  * \brief Check if a circular list is empty
181  *
182  * \details
183  *
184  * Check if a circular list is empty
185  *
186  * \param[in] list circular list to check
187  *
188  * \return RTI_TRUE if circular list is empty, RTI_FALSE if not empty
189  */
190 REDADllExport RTI_BOOL
191 REDA_CircularList_is_empty(REDA_CircularList_T *list);
192 
193 #define REDA_CircularList_is_empty(c_list_) \
194  ((c_list_)->_next == (c_list_) ? 1 : 0)
195 
196 /*ci
197  * \brief Check if a node is at the head of the circular list head
198  *
199  * \details
200  *
201  * Check if a node is at the head of the circular list head
202  *
203  * \param[in] list circular list node to check
204  * \param[in] node circular list node to check
205  *
206  * \return RTI_TRUE is node is at head, RTI_FALSE is not
207  */
208 REDADllExport RTI_BOOL
209 REDA_CircularList_node_at_head(REDA_CircularList_T *list,
210  REDA_CircularListNode_T *node);
211 
212 #define REDA_CircularList_node_at_head(c_list_,c_node_) \
213  ((void*)(c_list_) == (void*)(c_node_))
214 
215 /*ci
216  * \brief Return the head of a circular list
217  *
218  * \details
219  *
220  * Return the head of a circular list
221  *
222  * \param[in] list circular list node to return head of
223  *
224  * \return pointer to first element in circular list
225  */
226 REDADllExport REDA_CircularListNode_T*
227 REDA_CircularList_get_first(REDA_CircularList_T *list);
228 
229 #define REDA_CircularList_get_first(c_list_) ((c_list_)->_next)
230 
231 /*ci
232  * \brief Return the last element of a circular list
233  *
234  * \details
235  *
236  * Return the last element of a circular list
237  *
238  * \param[in] list circular list node to return the last element of
239  *
240  * \return pointer to last element in circular list
241  */
242 REDADllExport REDA_CircularListNode_T*
243 REDA_CircularList_get_last(REDA_CircularList_T *list);
244 
245 #define REDA_CircularList_get_last(c_list_) ((c_list_)->_prev)
246 
247 /*ci
248  * \brief Return the next element after a node
249  *
250  * \details
251  *
252  * Given a node in the circular list node, return the element after the node
253  *
254  * \param[in] node circular list node to return the next element of
255  *
256  * \return pointer to element after the node
257  */
258 REDADllExport REDA_CircularListNode_T*
259 REDA_CircularListNode_get_next(REDA_CircularListNode_T *node);
260 
261 #define REDA_CircularListNode_get_next(c_node_) ((c_node_)->_next)
262 
263 /*ci
264  * \brief Return the previous element after a node
265  *
266  * \details
267  *
268  * Given a node in the circular list node, return the element before the node
269  *
270  * \param[in] node circular list node to return the previous element of
271  *
272  * \return pointer to element before the node
273  */
274 REDADllExport REDA_CircularListNode_T*
275 REDA_CircularListNode_get_prev(REDA_CircularListNode_T *node);
276 
277 #define REDA_CircularListNode_get_prev(c_node_) ((c_node_)->_prev)
278 
279 /*ci
280  * \brief Check if a node is linked into a circular list
281  *
282  * \details
283  *
284  * Check if a node is linked into a circular list
285  *
286  * \param[in] node circular list node to check
287  *
288  * \return RTI_TRUE is node is linked, RTI_FALSE if not
289  */
290 REDADllExport RTI_BOOL
291 REDA_CircularListNode_is_linked(REDA_CircularListNode_T *node);
292 
293 #define REDA_CircularListNode_is_linked(c_node_) \
294  (((c_node_)->_next || (c_node_)->_prev) ? 1 : 0)
295 
296 #ifdef __cplusplus
297 } /* extern "C" */
298 #endif
299 
300 #endif /* reda_circularlist_h */
301 
302 /*ci @} */

RTI Connext Micro Version 2.4.1.0 Copyright © Thu Nov 20 2014 Real-Time Innovations, Inc