28 #ifndef IOT_LINEAR_CONTAINERS_H_    29 #define IOT_LINEAR_CONTAINERS_H_    32 #include "iot_config.h"    52 typedef struct IotLink
    87 #define IOT_LINK_INITIALIZER           { 0 }                    88 #define IOT_LIST_DOUBLE_INITIALIZER    IOT_LINK_INITIALIZER     89 #define IOT_DEQUEUE_INITIALIZER        IOT_LINK_INITIALIZER    101 #if IOT_CONTAINERS_ENABLE_ASSERTS == 1   102     #ifndef IotContainers_Assert   103         #ifdef Iot_DefaultAssert   104             #define IotContainers_Assert( expression )    Iot_DefaultAssert( expression )   106             #error "Asserts are enabled for containers, but IotContainers_Assert is not defined"   110     #define IotContainers_Assert( expression )   120 #define IotLink_Container( type, pLink, linkName ) \   121     ( ( type * ) ( void * ) ( ( ( uint8_t * ) ( pLink ) ) - offsetof( type, linkName ) ) )   131 #define IotContainers_ForEach( pStart, pLink ) \   132     for( ( pLink ) = ( pStart )->pNext;        \   133          ( pLink ) != ( pStart );              \   134          ( pLink ) = ( pLink )->pNext )   214     bool isLinked = 
false;
   218         isLinked = ( pLink->
pNext != NULL ) && ( pLink->
pPrevious != NULL );
   246     pList->
pNext = pList;
   268         while( pCurrent != pList )
   271             pCurrent = pCurrent->
pNext;
   290     return( ( pList == NULL ) || ( pList->
pNext == pList ) );
   313             pHead = pList->
pNext;
   366     pLink->
pNext = pHead;
   371     pList->
pNext = pLink;
   392     pLink->
pNext = pList;
   396     pTail->
pNext = pLink;
   445                                                int32_t ( *compare )( 
const IotLink_t * 
const pParam1, 
const IotLink_t * 
const pParam2 ) )
   460         bool inserted = 
false;
   464         while( pCurrent != pList )
   467             if( compare( pLink, pCurrent ) < 0 )
   475             pCurrent = pCurrent->
pNext;
   479         if( inserted == 
false )
   524         pHead = pList->
pNext;
   568                                             void ( *freeElement )( 
void * pData ),
   579     while( pCurrent != pList )
   587         if( freeElement != NULL )
   589             freeElement( ( ( uint8_t * ) pCurrent ) - linkOffset );
   620                                                         bool ( *isMatch )( 
const IotLink_t * 
const pOperationLink, 
void * pCompare ),
   628     bool matchFound = 
false;
   634     if( pStartPoint == NULL )
   636         pCurrent = pList->
pNext;
   640     while( pCurrent != pList )
   643         if( isMatch != NULL )
   645             matchFound = isMatch( pCurrent, pMatch );
   649             matchFound = ( pCurrent == pMatch );
   652         if( matchFound == 
true )
   654             pMatchedLink = pCurrent;
   658         pCurrent = pCurrent->
pNext;
   688                                                           bool ( *isMatch )( 
const IotLink_t * 
const pOperationLink, 
void * pCompare ),
   697     if( pMatchedElement != NULL )
   702     return pMatchedElement;
   723                                                    bool ( *isMatch )( 
const IotLink_t * 
const pOperationLink, 
void * pCompare ),
   725                                                    void ( *freeElement )( 
void * pData ),
   729     IotLink_t * pMatchedElement = NULL, * pNextElement = NULL;
   739         if( pMatchedElement != NULL )
   742             pNextElement = pMatchedElement->
pNext;
   747             if( freeElement != NULL )
   749                 freeElement( ( ( uint8_t * ) pMatchedElement ) - linkOffset );
   753             pMatchedElement = pNextElement;
   755     } 
while( pMatchedElement != NULL );
   924                                          void ( * freeElement )( 
void * pData ),
   949                                                 bool ( * isMatch )( 
const IotLink_t * 
const pOperationLink, 
void * pCompare ),
   951                                                 void ( * freeElement )( 
void * pData ),
 static void IotDeQueue_Remove(IotLink_t *const pLink)
Remove a single element from a queue. 
Definition: iot_linear_containers.h:1062
static IotLink_t * IotDeQueue_PeekHead(const IotDeQueue_t *const pQueue)
Return an IotLink_t representing the element at the front of the queue without removing it...
Definition: iot_linear_containers.h:973
static IotLink_t * IotListDouble_RemoveFirstMatch(const IotListDouble_t *const pList, const IotLink_t *const pStartPoint, bool(*isMatch)(const IotLink_t *const pOperationLink, void *pCompare), void *pMatch)
Search a doubly-linked list for the first matching element and remove it. 
Definition: iot_linear_containers.h:843
static bool IotListDouble_IsEmpty(const IotListDouble_t *const pList)
Check if a doubly-linked list is empty. 
Definition: iot_linear_containers.h:443
static IotLink_t * IotListDouble_FindFirstMatch(const IotListDouble_t *const pList, const IotLink_t *const pStartPoint, bool(*isMatch)(const IotLink_t *const pOperationLink, void *pCompare), void *pMatch)
Search a doubly-linked list for the first matching element. 
Definition: iot_linear_containers.h:775
static void IotListDouble_InsertBefore(IotLink_t *const pElement, IotLink_t *const pLink)
Insert an element before another element in a doubly-linked list. 
Definition: iot_linear_containers.h:563
Link member placed in structs of a list or queue. 
Definition: iot_linear_containers.h:52
static void IotDeQueue_EnqueueTail(IotDeQueue_t *const pQueue, IotLink_t *const pLink)
Add an element at the tail of the queue. 
Definition: iot_linear_containers.h:1033
static IotLink_t * IotListDouble_PeekHead(const IotListDouble_t *const pList)
Return an IotLink_t representing the first element in a doubly-linked list without removing it...
Definition: iot_linear_containers.h:461
static void IotListDouble_RemoveAll(const IotListDouble_t *const pList, void(*freeElement)(void *pData), size_t linkOffset)
Remove all elements in a doubly-linked list. 
Definition: iot_linear_containers.h:724
IotLink_t IotDeQueue_t
Represents a queue. 
Definition: iot_linear_containers.h:68
static IotLink_t * IotListDouble_RemoveTail(const IotListDouble_t *const pList)
Remove the element at the tail of a doubly-linked list. 
Definition: iot_linear_containers.h:698
static size_t IotListDouble_Count(const IotListDouble_t *const pList)
Return the number of elements contained in an IotListDouble_t. 
Definition: iot_linear_containers.h:414
static void IotListDouble_InsertAfter(IotLink_t *const pElement, IotLink_t *const pLink)
Insert an element after another element in a doubly-linked list. 
Definition: iot_linear_containers.h:577
static size_t IotDeQueue_Count(const IotDeQueue_t *const pQueue)
Return the number of elements contained in an IotDeQueue_t. 
Definition: iot_linear_containers.h:941
static void IotDeQueue_EnqueueHead(IotDeQueue_t *const pQueue, IotLink_t *const pLink)
Add an element at the head of the queue. 
Definition: iot_linear_containers.h:1003
struct IotLink * pNext
Pointer to the next element. 
Definition: iot_linear_containers.h:55
static void IotListDouble_RemoveAllMatches(const IotListDouble_t *const pList, bool(*isMatch)(const IotLink_t *const pOperationLink, void *pCompare), void *pMatch, void(*freeElement)(void *pData), size_t linkOffset)
Remove all matching elements from a doubly-linked list. 
Definition: iot_linear_containers.h:879
#define IotContainers_Assert(expression)
Assertion macro for the linear containers library. 
Definition: iot_linear_containers.h:114
static IotLink_t * IotDeQueue_DequeueHead(const IotDeQueue_t *const pQueue)
Remove an element at the head of the queue. 
Definition: iot_linear_containers.h:1020
static IotLink_t * IotListDouble_RemoveHead(const IotListDouble_t *const pList)
Remove the element at the head of a doubly-linked list. 
Definition: iot_linear_containers.h:674
struct IotLink * pPrevious
Pointer to the previous element. 
Definition: iot_linear_containers.h:54
static IotLink_t * IotListDouble_PeekTail(const IotListDouble_t *const pList)
Return an IotLink_t representing the last element in a doubly-linked list without removing it...
Definition: iot_linear_containers.h:488
static void IotDeQueue_Create(IotDeQueue_t *const pQueue)
Create a new queue. 
Definition: iot_linear_containers.h:927
static void IotListDouble_InsertHead(IotListDouble_t *const pList, IotLink_t *const pLink)
Insert an element at the head of a doubly-linked list. 
Definition: iot_linear_containers.h:511
static IotLink_t * IotDeQueue_PeekTail(const IotDeQueue_t *const pQueue)
Return an IotLink_t representing the element at the back of the queue without removing it...
Definition: iot_linear_containers.h:990
static void IotListDouble_Create(IotListDouble_t *const pList)
Create a new doubly-linked list. 
Definition: iot_linear_containers.h:395
static IotLink_t * IotDeQueue_DequeueTail(const IotDeQueue_t *const pQueue)
Remove an element at the tail of the queue. 
Definition: iot_linear_containers.h:1050
static bool IotLink_IsLinked(const IotLink_t *const pLink)
Check if an IotLink_t is linked in a list or queue. 
Definition: iot_linear_containers.h:368
static void IotListDouble_InsertTail(IotListDouble_t *const pList, IotLink_t *const pLink)
Insert an element at the tail of a doubly-linked list. 
Definition: iot_linear_containers.h:538
IotLink_t IotListDouble_t
Represents a doubly-linked list. 
Definition: iot_linear_containers.h:62
static void IotDeQueue_RemoveAllMatches(const IotDeQueue_t *const pQueue, bool(*isMatch)(const IotLink_t *const pOperationLink, void *pCompare), void *pMatch, void(*freeElement)(void *pData), size_t linkOffset)
Remove all matching elements from a queue. 
Definition: iot_linear_containers.h:1105
static void IotListDouble_Remove(IotLink_t *const pLink)
Remove a single element from a doubly-linked list. 
Definition: iot_linear_containers.h:649
static void IotListDouble_InsertSorted(IotListDouble_t *const pList, IotLink_t *const pLink, int32_t(*compare)(const IotLink_t *const pParam1, const IotLink_t *const pParam2))
Insert an element in a sorted doubly-linked list. 
Definition: iot_linear_containers.h:600
static void IotDeQueue_RemoveAll(const IotDeQueue_t *const pQueue, void(*freeElement)(void *pData), size_t linkOffset)
Remove all elements in a queue. 
Definition: iot_linear_containers.h:1080
static bool IotDeQueue_IsEmpty(const IotDeQueue_t *const pQueue)
Check if a queue is empty. 
Definition: iot_linear_containers.h:956