OS  v7.3.3
Documentation
Loading...
Searching...
No Matches
qlists.h
1
8#ifndef QLISTS_H
9 #define QLISTS_H
10
11 #include "qtypes.h"
12 #include <string.h>
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
55 typedef struct _qList_Node_s { // skipcq: CXX-E2000
57 struct _qList_Node_s *next, *prev; /*< Pointers to adjacent nodes. */
58 void *container; /*< Pointer to the container list*/
60 }
62
79 #define qNode_MinimalFields void *next, *prev, *container
80
85 typedef struct _qList_s { // skipcq: CXX-E2000
87 qNode_MinimalFields; /*< To allow "list of lists" aka "nested-lists"*/
88 qList_Node_t *head, *tail; /*< Pointers to the beginning of and the end of the list. */
89 size_t size; /*< Used to hold the current size of the list. */
91 }
92 qList_t;
93
97 #define QLIST_INITIALIZER { NULL, NULL, NULL, NULL, NULL, 0U }
98
108
115 typedef struct _qList_ForEachHandle_s { // skipcq: CXX-E2000
116 void *node;
117 void *arg;
119 }
120 #ifdef DOXYGEN
122 #else
123 _qList_ForEachHandle_t; // skipcq: CXX-E2000
124 typedef _qList_ForEachHandle_t* qList_ForEachHandle_t;
125 #endif
126
133 typedef struct _qList_CompareHandle_s { // skipcq: CXX-E2000
134 const void *n1;
135 const void *n2;
136 }
137 #ifdef DOXYGEN
139 #else
140 _qList_CompareHandle_t; // skipcq: CXX-E2000
141 typedef _qList_CompareHandle_t* qList_CompareHandle_t;
142 #endif
143
171
176
181 #define QLIST_AT_FRONT ( (qList_Position_t)( -1 ) )
182
187 #define QLIST_AT_BACK ( (qList_Position_t)( 2147483647 ) )
188
189
197 qBool_t qList_Initialize( qList_t * const l );
198
209 qBool_t qList_Insert( qList_t * const l,
210 void * const node,
211 const qList_Position_t p );
212
218 qBool_t qList_RemoveItself( void *const node );
219
230 void* qList_Remove( qList_t * const l,
231 void * const node,
232 const qList_Position_t p );
233
249 qBool_t qList_Move( qList_t *const dst,
250 qList_t *const src,
251 const qList_Position_t p );
252
259 qBool_t qList_IsMember( const qList_t * const l,
260 const void * const node );
261
267 void* qList_GetFront( const qList_t * const l );
268
274 void* qList_GetBack( const qList_t * const l );
275
281 qBool_t qList_IsEmpty( const qList_t * const l );
282
288 size_t qList_Length( const qList_t * const l );
289
290
308
329 qBool_t qList_Sort( qList_t * const l,
331
333 qList_Node_t* _qNode_Backward( const qList_Node_t *const n ); /*This function are not intended for the user usage*/ // skipcq: CXX-E2000
334 qList_Node_t* _qNode_Forward( const qList_Node_t *const n ); /*This function are not intended for the user usage*/ // skipcq: CXX-E2000
340 typedef qList_Node_t* (*qList_Direction_t)( const qList_Node_t *const node );
341
346 #define QLIST_FORWARD ( _qNode_Forward )
347
352 #define QLIST_BACKWARD ( _qNode_Backward )
353
357 typedef struct _qList_Iterator_s { // skipcq: CXX-E2000
359 qList_t *l;
360 qList_Node_t *iter;
361 void *current;
363 }
365
366
377 qList_t *const l,
378 void *nodeOffset,
379 const qList_Direction_t d );
380
397 qBool_t qList_ForEach( const qList_t *const l,
398 const qList_NodeFcn_t f,
399 void *arg,
401 void *nodeOffset );
402
413 qBool_t qList_Swap( void *node1,
414 void *node2 );
415
422 qList_Iterator_t qList_Begin( qList_t *const xList );
423
430 qList_Iterator_t qList_End( qList_t *const xList );
431
440 const void * const node );
441
447
453
458 void* qListIterator_Get( const qList_Iterator_t * const i );
459
461 #ifdef __cplusplus
462 }
463 #endif
464
465#endif
qBool_t qList_Move(qList_t *const dst, qList_t *const src, const qList_Position_t p)
Moves(or merge) the entire list pointed by src to the list pointed by dst at location specified by p....
Definition qlists.c:236
qINT32_t qList_Position_t
Typedef to hold the target position of a node in a list.
Definition qlists.h:175
qBool_t qList_RemoveItself(void *const node)
If the node is member of a list, the node will be removed from it.
Definition qlists.c:160
qBool_t qList_Sort(qList_t *const l, qList_CompareFcn_t f)
Sort the double linked list using the f function to determine the order. The sorting algorithm used b...
Definition qlists.c:361
qBool_t qListIterator_Until(const qList_Iterator_t *const i, const void *const node)
Check until current iterator reach the given node.
Definition qlists.c:635
qList_Iterator_t qList_End(qList_t *const xList)
Returns an iterator pointing to the last element in the list container.
Definition qlists.c:626
qBool_t qList_IsEmpty(const qList_t *const l)
Check if the list is empty.
Definition qlists.c:340
void * qListIterator_Get(const qList_Iterator_t *const i)
Gets the node that the iterator is currently pointing to.
Definition qlists.c:666
void * qList_Remove(qList_t *const l, void *const node, const qList_Position_t p)
Remove an item from the list.
Definition qlists.c:195
void * qList_GetBack(const qList_t *const l)
Get a pointer to the back item of the list.
Definition qlists.c:327
qBool_t(* qList_CompareFcn_t)(qList_CompareHandle_t h)
Pointer to a function used by the qList_Sort() API to compare nodes of a list.
Definition qlists.h:307
qBool_t qList_IsMember(const qList_t *const l, const void *const node)
Check if the node is member of the list.
Definition qlists.c:295
#define qNode_MinimalFields
This macro can be used to create custom data that can be used as node of a list. User should locate t...
Definition qlists.h:79
qBool_t qList_Insert(qList_t *const l, void *const node, const qList_Position_t p)
Insert an item into the list.
Definition qlists.c:117
qBool_t qList_IteratorSet(qList_Iterator_t *i, qList_t *const l, void *nodeOffset, const qList_Direction_t d)
Setup an instance of the given iterator to traverse the list.
Definition qlists.c:431
qBool_t qList_Swap(void *node1, void *node2)
Swap two nodes that belongs to the same list by changing its own links.
Definition qlists.c:521
void qListIterator_Backward(qList_Iterator_t *i)
Move the iterator backward.
Definition qlists.c:658
qBool_t qList_ForEach(const qList_t *const l, const qList_NodeFcn_t f, void *arg, qList_Direction_t d, void *nodeOffset)
Operate on each element of the list.
Definition qlists.c:460
qList_Node_t *(* qList_Direction_t)(const qList_Node_t *const node)
Typedef to hold the direction in which the list should be traversed.
Definition qlists.h:340
qBool_t qList_Initialize(qList_t *const l)
Must be called before a list is used. This initialises all the members of the list structure.
Definition qlists.c:27
void * qList_GetFront(const qList_t *const l)
Get a pointer to the front item of the list.
Definition qlists.c:314
qList_WalkStage_t
An enum to describe the ForEach stage.
Definition qlists.h:102
void qListIterator_Forward(qList_Iterator_t *i)
Move the iterator forward.
Definition qlists.c:650
qList_Iterator_t qList_Begin(qList_t *const xList)
Returns an iterator pointing to the first element in the list container.
Definition qlists.c:617
qBool_t(* qList_NodeFcn_t)(qList_ForEachHandle_t h)
Pointer to a function that operates on every node when using the qList_ForEach() API.
Definition qlists.h:170
size_t qList_Length(const qList_t *const l)
Get the number of items inside the list.
Definition qlists.c:350
@ qList_WalkEnd
Definition qlists.h:105
@ qList_WalkInit
Definition qlists.h:103
@ qList_WalkThrough
Definition qlists.h:104
qUINT8_t qBool_t
A type to instantiate an OS boolean variable.
Definition qtypes.h:139
int32_t qINT32_t
Signed integer type with width of exactly 32 bits respectively.
Definition qtypes.h:55
Handle of the qList_Sort() API that is passed as an argument to the compare function.
Definition qlists.h:133
const void * n1
Definition qlists.h:134
const void * n2
Definition qlists.h:135
Handle of the qList_ForEach() API that is passed as an argument to the function that operates on each...
Definition qlists.h:115
qList_WalkStage_t stage
Definition qlists.h:118
void * node
Definition qlists.h:116
void * arg
Definition qlists.h:117
Typedef to hold a list-iterator instance.
Definition qlists.h:357
A list-node object (Used internally)
Definition qlists.h:55
A list object (Generic double-linked)
Definition qlists.h:85