31 #ifndef IOT_LINEAR_CONTAINERS_H_ 32 #define IOT_LINEAR_CONTAINERS_H_ 35 #include "iot_config.h" 55 typedef struct IotLink
91 #define IOT_LINK_INITIALIZER { 0 } 92 #define IOT_LIST_DOUBLE_INITIALIZER IOT_LINK_INITIALIZER 93 #define IOT_DEQUEUE_INITIALIZER IOT_LINK_INITIALIZER 105 #if IOT_CONTAINERS_ENABLE_ASSERTS == 1 106 #ifndef IotContainers_Assert 108 #define IotContainers_Assert( expression ) assert( expression ) 111 #define IotContainers_Assert( expression ) 121 #define IotLink_Container( type, pLink, linkName ) \ 122 ( ( type * ) ( void * ) ( ( ( uint8_t * ) ( pLink ) ) - offsetof( type, linkName ) ) ) 132 #define IotContainers_ForEach( pStart, pLink ) \ 133 for( ( pLink ) = ( pStart )->pNext; \ 134 ( pLink ) != ( pStart ); \ 135 ( pLink ) = ( pLink )->pNext ) 306 bool isLinked =
false;
310 isLinked = ( pLink->
pNext != NULL ) && ( pLink->
pPrevious != NULL );
338 pList->
pNext = pList;
360 while( pCurrent != pList )
363 pCurrent = pCurrent->
pNext;
382 return( ( pList == NULL ) || ( pList->
pNext == pList ) );
405 pHead = pList->
pNext;
458 pLink->
pNext = pHead;
463 pList->
pNext = pLink;
484 pLink->
pNext = pList;
488 pTail->
pNext = pLink;
552 bool inserted =
false;
556 while( pCurrent != pList )
559 if( compare( pLink, pCurrent ) < 0 )
567 pCurrent = pCurrent->
pNext;
571 if( inserted ==
false )
616 pHead = pList->
pNext;
660 void ( * freeElement )(
void * ),
671 while( pCurrent != pList )
679 if( freeElement != NULL )
681 freeElement( ( ( uint8_t * ) pCurrent ) - linkOffset );
712 bool ( * isMatch )(
const IotLink_t *
const,
void * ),
724 if( pStartPoint == NULL )
726 pCurrent = pList->
pNext;
730 while( pCurrent != pList )
733 if( isMatch != NULL )
735 if( isMatch( pCurrent, pMatch ) ==
true )
742 if( pCurrent == pMatch )
748 pCurrent = pCurrent->
pNext;
778 bool ( * isMatch )(
const IotLink_t *,
void * ),
787 if( pMatchedElement != NULL )
792 return pMatchedElement;
813 bool ( * isMatch )(
const IotLink_t *,
void * ),
815 void ( * freeElement )(
void * ),
819 IotLink_t * pMatchedElement = NULL, * pNextElement = NULL;
829 if( pMatchedElement != NULL )
832 pNextElement = pMatchedElement->
pNext;
837 if( freeElement != NULL )
839 freeElement( ( ( uint8_t * ) pMatchedElement ) - linkOffset );
843 pMatchedElement = pNextElement;
845 }
while( pMatchedElement != NULL );
1014 void ( * freeElement )(
void * ),
1039 bool ( * isMatch )(
const IotLink_t *,
void * ),
1041 void ( * freeElement )(
void * ),
static void IotListDouble_Create(IotListDouble_t *const pList)
Create a new doubly-linked list.
Definition: iot_ble_linear_containers.h:330
static IotLink_t * IotListDouble_FindFirstMatch(const IotListDouble_t *const pList, const IotLink_t *const pStartPoint, bool(*isMatch)(const IotLink_t *const, void *), void *pMatch)
Search a doubly-linked list for the first matching element.
Definition: iot_ble_linear_containers.h:710
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_ble_linear_containers.h:423
static void IotDeQueue_EnqueueHead(IotDeQueue_t *const pQueue, IotLink_t *const pLink)
Add an element at the head of the queue.
Definition: iot_ble_linear_containers.h:936
static void IotDeQueue_RemoveAll(IotDeQueue_t *const pQueue, void(*freeElement)(void *), size_t linkOffset)
Remove all elements in a queue.
Definition: iot_ble_linear_containers.h:1013
static void IotDeQueue_Create(IotDeQueue_t *const pQueue)
Create a new queue.
Definition: iot_ble_linear_containers.h:860
Link member placed in structs of a list or queue.
Definition: iot_ble_linear_containers.h:55
static bool IotListDouble_IsEmpty(const IotListDouble_t *const pList)
Check if a doubly-linked list is empty.
Definition: iot_ble_linear_containers.h:378
static void IotListDouble_InsertSorted(IotListDouble_t *const pList, IotLink_t *const pLink, int32_t(*compare)(const IotLink_t *const, const IotLink_t *const))
Insert an element in a sorted doubly-linked list.
Definition: iot_ble_linear_containers.h:535
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_ble_linear_containers.h:906
static IotLink_t * IotListDouble_RemoveFirstMatch(IotListDouble_t *const pList, const IotLink_t *const pStartPoint, bool(*isMatch)(const IotLink_t *, void *), void *pMatch)
Search a doubly-linked list for the first matching element and remove it.
Definition: iot_ble_linear_containers.h:776
IotLink_t IotDeQueue_t
Represents a queue.
Definition: iot_ble_linear_containers.h:71
static size_t IotListDouble_Count(const IotListDouble_t *const pList)
Return the number of elements contained in an IotListDouble_t.
Definition: iot_ble_linear_containers.h:349
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_ble_linear_containers.h:446
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_ble_linear_containers.h:923
struct IotLink * pNext
Pointer to the next element.
Definition: iot_ble_linear_containers.h:58
static void IotListDouble_Remove(IotLink_t *const pLink)
Remove a single element from a doubly-linked list.
Definition: iot_ble_linear_containers.h:584
#define IotContainers_Assert(expression)
Assertion macro for the linear containers library.
Definition: iot_ble_linear_containers.h:111
static IotLink_t * IotListDouble_RemoveTail(IotListDouble_t *const pList)
Remove the element at the tail of a doubly-linked list.
Definition: iot_ble_linear_containers.h:633
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_ble_linear_containers.h:473
struct IotLink * pPrevious
Pointer to the previous element.
Definition: iot_ble_linear_containers.h:57
static IotLink_t * IotDeQueue_DequeueHead(IotDeQueue_t *const pQueue)
Remove an element at the head of the queue.
Definition: iot_ble_linear_containers.h:953
static IotLink_t * IotDeQueue_DequeueTail(IotDeQueue_t *const pQueue)
Remove an element at the tail of the queue.
Definition: iot_ble_linear_containers.h:983
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_ble_linear_containers.h:498
static void IotDeQueue_EnqueueTail(IotDeQueue_t *const pQueue, IotLink_t *const pLink)
Add an element at the tail of the queue.
Definition: iot_ble_linear_containers.h:966
static void IotListDouble_RemoveAll(IotListDouble_t *const pList, void(*freeElement)(void *), size_t linkOffset)
Remove all elements in a doubly-linked list.
Definition: iot_ble_linear_containers.h:659
static size_t IotDeQueue_Count(const IotDeQueue_t *const pQueue)
Return the number of elements contained in an IotDeQueue_t.
Definition: iot_ble_linear_containers.h:874
static void IotListDouble_RemoveAllMatches(IotListDouble_t *const pList, bool(*isMatch)(const IotLink_t *, void *), void *pMatch, void(*freeElement)(void *), size_t linkOffset)
Remove all matching elements from a doubly-linked list.
Definition: iot_ble_linear_containers.h:812
static bool IotDeQueue_IsEmpty(const IotDeQueue_t *const pQueue)
Check if a queue is empty.
Definition: iot_ble_linear_containers.h:889
static void IotDeQueue_Remove(IotLink_t *const pLink)
Remove a single element from a queue.
Definition: iot_ble_linear_containers.h:995
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_ble_linear_containers.h:396
IotLink_t IotListDouble_t
Represents a doubly-linked list.
Definition: iot_ble_linear_containers.h:65
static IotLink_t * IotListDouble_RemoveHead(IotListDouble_t *const pList)
Remove the element at the head of a doubly-linked list.
Definition: iot_ble_linear_containers.h:609
static bool IotLink_IsLinked(const IotLink_t *const pLink)
Check if an IotLink_t is linked in a list or queue.
Definition: iot_ble_linear_containers.h:303
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_ble_linear_containers.h:512
static void IotDeQueue_RemoveAllMatches(IotDeQueue_t *const pQueue, bool(*isMatch)(const IotLink_t *, void *), void *pMatch, void(*freeElement)(void *), size_t linkOffset)
Remove all matching elements from a queue.
Definition: iot_ble_linear_containers.h:1038