Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
DoubleList.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Embedded Web-Server
10 *
11 ****************************************************************************
12 * HEADER
13 *
14 * $Id: DoubleList.h 5853 2026-08-17 09:48:31Z gianluca $
15 *
16 * COPYRIGHT: Real Time Logic, 2004 - 2026
17 *
18 * This software is copyrighted by and is the sole property of Real
19 * Time Logic LLC. All rights, title, ownership, or other interests in
20 * the software remain the property of Real Time Logic LLC. This
21 * software may only be used in accordance with the terms and
22 * conditions stipulated in the corresponding license agreement under
23 * which the software has been supplied. Any unauthorized use,
24 * duplication, transmission, distribution, or disclosure of this
25 * software is expressly forbidden.
26 *
27 * This Copyright notice may not be removed or modified without prior
28 * written consent of Real Time Logic LLC.
29 *
30 * Real Time Logic LLC. reserves the right to modify this software
31 * without notice.
32 *
33 * http://www.realtimelogic.com
34 ****************************************************************************
35 *
36 * DiskIo implements the abstract class IoIntf. See the reference
37 * manual for more information on the IoIntf (IO interface)
38 * requirements.
39 *
40 * This is a generic header file for all file systems and
41 * platforms. See the sub-directories for platform specific
42 * implementations.
43 */
44
45#ifndef _DoubleList_h
46#define _DoubleList_h
47
48#include <TargConfig.h>
49
50#ifndef DL_INLINE
51#define DL_INLINE 1
52#endif
53
54struct DoubleList;
55
56typedef struct DoubleLink
57{
58#ifdef __cplusplus
59 void *operator new(size_t s) { return ::baMalloc(s); }
60 void operator delete(void* d) { if(d) ::baFree(d); }
61 void *operator new(size_t, void *place) { return place; }
62 void operator delete(void*, void *) { }
63 DoubleLink();
64 ~DoubleLink();
65 void insertAfter(DoubleLink* newLink);
66 void insertBefore(DoubleLink* newLink);
67 void unlink();
68 bool isLinked();
69 DoubleLink* getNext();
70#endif
71 struct DoubleLink* next;
72 struct DoubleLink* prev;
73} DoubleLink;
74
75
76
77typedef struct DoubleList
78{
79#ifdef __cplusplus
80 DoubleList();
81 void insertFirst(DoubleLink* newLink);
82 void insertLast(DoubleLink* newLink);
83 bool isLast(DoubleLink* n);
84 DoubleLink* firstNode();
85 DoubleLink* lastNode();
86 bool isEmpty();
87 DoubleLink* removeFirst();
88 bool isInList(DoubleLink* n);
89#endif
90 DoubleLink* next;
91 DoubleLink* prev;
92} DoubleList;
93
94#if DL_INLINE
95#define DoubleLink_constructor(o) do { \
96 ((DoubleLink*)o)->next = 0; \
97 ((DoubleLink*)o)->prev = 0; \
98} while(0)
99
100
101#define DoubleLink_destructor(o) do { \
102 if(DoubleLink_isLinked(o)) \
103 DoubleLink_unlink((DoubleLink*)o); \
104} while(0)
105
106#define DoubleLink_insertAfter(o, newLink) do { \
107 baAssert(((DoubleLink*)newLink)->prev==0&&((DoubleLink*)newLink)->next==0);\
108 ((DoubleLink*)newLink)->next = ((DoubleLink*)o)->next; \
109 ((DoubleLink*)newLink)->prev = ((DoubleLink*)o); \
110 ((DoubleLink*)o)->next->prev = ((DoubleLink*)newLink); \
111 ((DoubleLink*)o)->next = ((DoubleLink*)newLink); \
112} while(0)
113
114
115#define DoubleLink_insertBefore(o, newLink) do { \
116 baAssert(((DoubleLink*)newLink)->prev==0&&((DoubleLink*)newLink)->next==0);\
117 ((DoubleLink*)newLink)->prev = ((DoubleLink*)o)->prev; \
118 ((DoubleLink*)newLink)->next = ((DoubleLink*)o); \
119 ((DoubleLink*)o)->prev->next = ((DoubleLink*) newLink); \
120 ((DoubleLink*)o)->prev = ((DoubleLink*) newLink); \
121} while(0)
122
123
124#ifdef NDEBUG
125#define DoubleLink_isLinked(o) \
126 (((DoubleLink*)o)->prev ? TRUE : FALSE)
127#else
128#define DoubleLink_isLinked(o) \
129 (((DoubleLink*)o)->prev ? (baAssert(((DoubleLink*)o)->next), TRUE) : FALSE)
130#endif
131
132#define DoubleLink_getNext(o) ((DoubleLink*)(o))->next
133
134#define DoubleLink_unlink(o) do { \
135 baAssert(((DoubleLink*)o)->prev && ((DoubleLink*)o)->next);\
136 ((DoubleLink*) o)->next->prev = ((DoubleLink*)o)->prev; \
137 ((DoubleLink*) o)->prev->next = ((DoubleLink*)o)->next; \
138 ((DoubleLink*) o)->next = 0; \
139 ((DoubleLink*) o)->prev = 0; \
140} while(0)
141
142#define DoubleList_constructor(o) do { \
143 (o)->next = (DoubleLink*)o; \
144 (o)->prev = (DoubleLink*)o; \
145} while(0)
146
147
148#define DoubleList_insertFirst(o, newLink) do { \
149 baAssert(((DoubleLink*)newLink)->prev==0&&((DoubleLink*)newLink)->next==0);\
150 ((DoubleLink*)newLink)->next = (o)->next; \
151 ((DoubleLink*)newLink)->prev = (DoubleLink*)o; \
152 (o)->next->prev = ((DoubleLink*) newLink); \
153 (o)->next = ((DoubleLink*) newLink); \
154} while(0)
155
156
157#define DoubleList_insertLast(o, newLink) do { \
158 baAssert(((DoubleLink*)newLink)->prev==0&&((DoubleLink*)newLink)->next==0);\
159 ((DoubleLink*)newLink)->next = (DoubleLink*)o; \
160 ((DoubleLink*)newLink)->prev = (o)->prev; \
161 (o)->prev->next = ((DoubleLink*)newLink); \
162 (o)->prev = ((DoubleLink*)newLink); \
163} while(0)
164
165
166#define DoubleList_isLast(o, n) (((DoubleLink*)(n))->next == (DoubleLink*)(o))
167#define DoubleList_isEnd(o, n) ((DoubleLink*)(n) == (DoubleLink*)(o))
168
169#define DoubleList_firstNode(o) \
170 ((o)->next != (DoubleLink*)o ? (o)->next : 0)
171#define DoubleList_lastNode(o) \
172 ((o)->prev != (DoubleLink*)o ? (o)->prev : 0)
173
174#endif /* DL_INLINE */
175
176#define DoubleList_isEmpty(o) \
177 ((o)->next == ((DoubleLink*)(o)))
178
179
180#ifdef __cplusplus
181extern "C" {
182#endif
183
184BA_API DoubleLink* DoubleList_removeFirst(DoubleList* o);
185
186/* Returns true if the node is in any list. You cannot use this
187 * function for testing if the node is in a particular list, that is
188 * your problem. The function performs some additional tests if NDEBUG
189 * is not defined and asserts that if the node is in a list, it should
190 * be in this list. The ESP32 compiler does not create correct code
191 * for function DoubleList_isInListF
192 */
193#if defined(NDEBUG) || defined(ESP_PLATFORM)
194#define DoubleList_isInList(o, node) (((DoubleLink*)node)->prev ? TRUE : FALSE)
195#else
196#define DoubleList_isInList(o, node) DoubleList_isInListF(o, node, __FILE__, __LINE__)
197BA_API BaBool DoubleList_isInListF(DoubleList* o,void* node,const char* file,int line);
198#endif
199
200#if DL_INLINE == 0
201BA_API void DoubleLink_constructor(void* o);
202BA_API void DoubleLink_destructor(void* o);
203BA_API void DoubleLink_insertAfter(void* o, void* newLink);
204BA_API void DoubleLink_insertBefore(void* o, void* newLink);
205BA_API int DoubleLink_isLinked(void* o);
206BA_API DoubleLink* DoubleLink_getNext(void* o);
207BA_API void DoubleLink_unlink(DoubleLink* o);
208BA_API void DoubleList_constructor(DoubleList* o);
209BA_API void DoubleList_insertFirst(DoubleList* o, void* newLink);
210BA_API void DoubleList_insertLast(DoubleList* o, void* newLink);
211BA_API int DoubleList_isLast(DoubleList* o, void* n);
212BA_API int DoubleList_isEnd(DoubleList* o, void* n);
213BA_API DoubleLink* DoubleList_firstNode(DoubleList* o);
214BA_API DoubleLink* DoubleList_lastNode(DoubleList* o);
215#endif /* DL_INLINE */
216
217
218#ifdef __cplusplus
219}
220inline DoubleLink::DoubleLink() {
221 DoubleLink_constructor(this);
222}
223inline DoubleLink::~DoubleLink() {
224 DoubleLink_destructor(this);
225}
226inline void DoubleLink::insertAfter(DoubleLink* newLink) {
227 DoubleLink_insertAfter(this, newLink);
228}
229inline void DoubleLink::insertBefore(DoubleLink* newLink) {
230 DoubleLink_insertBefore(this, newLink);
231}
232inline void DoubleLink::unlink() {
233 DoubleLink_unlink(this);
234}
235inline bool DoubleLink::isLinked() {
236 return DoubleLink_isLinked(this) ? true : false;
237}
238inline DoubleLink* DoubleLink::getNext() {
239 return DoubleLink_getNext(this);
240}
241inline DoubleList::DoubleList() {
242 DoubleList_constructor(this);
243}
244inline void DoubleList::insertFirst(DoubleLink* newLink) {
245 DoubleList_insertFirst(this, newLink);
246}
247inline void DoubleList::insertLast(DoubleLink* newLink) {
248 DoubleList_insertLast(this, newLink);
249}
250inline bool DoubleList::isLast(DoubleLink* n) {
251 return DoubleList_isLast(this, n) ? true : false;
252}
253inline DoubleLink* DoubleList::firstNode() {
254 return DoubleList_firstNode(this);
255}
256inline DoubleLink* DoubleList::lastNode() {
257 return DoubleList_lastNode(this);
258}
259inline bool DoubleList::isEmpty() {
260 return DoubleList_isEmpty(this) ? true : false;
261}
262inline DoubleLink* DoubleList::removeFirst() {
263 return DoubleList_removeFirst(this);
264}
265inline bool DoubleList::isInList(DoubleLink* n) {
266 return DoubleList_isInList(this, n) ? true : false;
267}
268#endif
269
270
271
272
273/*===========================================================================
274 *
275 * Class: DoubleListEnumerator
276 *---------------------------------------------------------------------------
277 * Description:
278 * Usage:
279 * DoubleListEnumerator e(list);
280 * for(DoubleLink* link = e.getElement() ; link ; link = e.nextElement())
281 * or
282 * DoubleListEnumerator e(list);
283 * DoubleLink* link = e.getElement();
284 * while(link)
285 * {
286 * if(link bla bla)
287 * //Deletes current element and returns next element
288 * link = e.deleteElement();
289 * else
290 * link = e.nextElement();
291 * }
292 */
293typedef struct DoubleListEnumerator
294{
295#ifdef __cplusplus
296 DoubleListEnumerator(){}
297 DoubleListEnumerator(DoubleList* list);
298 DoubleLink* getElement();
299 DoubleLink* nextElement();
300 DoubleLink* removeElement();
301 private:
302#endif
303 DoubleList* list;
304 DoubleLink* curElement;
305} DoubleListEnumerator;
306
307#define DoubleListEnumerator_getElement(o) (o)->curElement
308
309#if DL_INLINE
310#define DoubleListEnumerator_constructor(o, listMA) do \
311{ \
312 (o)->list = listMA; \
313 (o)->curElement = DoubleList_firstNode((o)->list);\
314} while(0)
315
316#define DoubleListEnumerator_nextElement(o) \
317 ((o)->curElement ? ( \
318 (o)->curElement = (o)->curElement->next == (DoubleLink*)(o)->list ? 0 : (o)->curElement->next, \
319 (o)->curElement \
320 ) : 0)
321#endif
322
323#ifdef __cplusplus
324extern "C" {
325#endif
326
327#if DL_INLINE == 0
328BA_API void DoubleListEnumerator_constructor(DoubleListEnumerator* o, DoubleList* list);
329BA_API DoubleLink* DoubleListEnumerator_nextElement(DoubleListEnumerator* o);
330#endif
331
332
333BA_API DoubleLink* DoubleListEnumerator_removeElement(DoubleListEnumerator* o);
334#ifdef __cplusplus
335}
336inline DoubleListEnumerator::DoubleListEnumerator(DoubleList* list) {
337 DoubleListEnumerator_constructor(this, list); }
338inline DoubleLink*
339DoubleListEnumerator::removeElement() {
340 return DoubleListEnumerator_removeElement(this); }
341inline DoubleLink*
342DoubleListEnumerator::getElement() {return DoubleListEnumerator_getElement(this);}
343inline DoubleLink*
344DoubleListEnumerator::nextElement() {return DoubleListEnumerator_nextElement(this); }
345#endif
346
347
348#endif
void * baMalloc(size_t size)
Allocate uninitialized storage using the target's configured allocator.
void baFree(void *p)
Release storage using the target's configured allocator.
U8 BaBool
Boolean stored in an unsigned byte; FALSE is zero and TRUE is one.
Definition: GenPrimT.h:118