MQTT C Client Libraries Internals
Functions
LinkedList.c File Reference

functions which apply to linked list structures. More...

#include "LinkedList.h"
#include <stdlib.h>
#include <string.h>
#include "Heap.h"
Include dependency graph for LinkedList.c:

Functions

static int ListUnlink (List *aList, void *content, int(*callback)(void *, void *), int freeContent)
 Removes and optionally frees an element in a list by comparing the content. More...
 
void ListZero (List *newl)
 Sets a list structure to empty - all null values. More...
 
ListListInitialize (void)
 Allocates and initializes a new list structure. More...
 
void ListAppendNoMalloc (List *aList, void *content, ListElement *newel, size_t size)
 Append an already allocated ListElement and content to a list. More...
 
ListElementListAppend (List *aList, void *content, size_t size)
 Append an item to a list. More...
 
ListElementListInsert (List *aList, void *content, size_t size, ListElement *index)
 Insert an item to a list at a specific position. More...
 
ListElementListFind (List *aList, void *content)
 Finds an element in a list by comparing the content pointers, rather than the contents. More...
 
ListElementListFindItem (List *aList, void *content, int(*callback)(void *, void *))
 Finds an element in a list by comparing the content or pointer to the content. More...
 
int ListDetach (List *aList, void *content)
 Removes but does not free an item in a list by comparing the pointer to the content. More...
 
int ListRemove (List *aList, void *content)
 Removes and frees an item in a list by comparing the pointer to the content. More...
 
void * ListDetachHead (List *aList)
 Removes and frees an the first item in a list. More...
 
int ListRemoveHead (List *aList)
 Removes and frees an the first item in a list. More...
 
void * ListPopTail (List *aList)
 Removes but does not free the last item in a list. More...
 
int ListDetachItem (List *aList, void *content, int(*callback)(void *, void *))
 Removes but does not free an element in a list by comparing the content. More...
 
int ListRemoveItem (List *aList, void *content, int(*callback)(void *, void *))
 Removes and frees an element in a list by comparing the content. More...
 
void ListEmpty (List *aList)
 Removes and frees all items in a list, leaving the list ready for new items. More...
 
void ListFree (List *aList)
 Removes and frees all items in a list, and frees the list itself. More...
 
void ListFreeNoContent (List *aList)
 Removes and but does not free all items in a list, and frees the list itself. More...
 
ListElementListNextElement (List *aList, ListElement **pos)
 Forward iteration through a list. More...
 
ListElementListPrevElement (List *aList, ListElement **pos)
 Backward iteration through a list. More...
 
int intcompare (void *a, void *b)
 List callback function for comparing integers. More...
 
int stringcompare (void *a, void *b)
 List callback function for comparing C strings. More...
 

Detailed Description

functions which apply to linked list structures.

These linked lists can hold data of any sort, pointed to by the content pointer of the ListElement structure. ListElements hold the points to the next and previous items in the list.

Function Documentation

◆ intcompare()

int intcompare ( void *  a,
void *  b 
)

List callback function for comparing integers.

Parameters
afirst integer value
bsecond integer value
Returns
boolean indicating whether a and b are equal

◆ ListAppend()

ListElement* ListAppend ( List aList,
void *  content,
size_t  size 
)

Append an item to a list.

Parameters
aListthe list to which the item is to be added
contentthe list item content itself
sizethe size of the element
Here is the call graph for this function:

◆ ListAppendNoMalloc()

void ListAppendNoMalloc ( List aList,
void *  content,
ListElement newel,
size_t  size 
)

Append an already allocated ListElement and content to a list.

Can be used to move an item from one list to another.

Parameters
aListthe list to which the item is to be added
contentthe list item content itself
newelthe ListElement to be used in adding the new item
sizethe size of the element

◆ ListDetach()

int ListDetach ( List aList,
void *  content 
)

Removes but does not free an item in a list by comparing the pointer to the content.

Parameters
aListthe list in which the search is to be conducted
contentpointer to the content to look for
Returns
1=item removed, 0=item not removed
Here is the call graph for this function:

◆ ListDetachHead()

void* ListDetachHead ( List aList)

Removes and frees an the first item in a list.

Parameters
aListthe list from which the item is to be removed
Returns
1=item removed, 0=item not removed

◆ ListDetachItem()

int ListDetachItem ( List aList,
void *  content,
int(*)(void *, void *)  callback 
)

Removes but does not free an element in a list by comparing the content.

A callback function is used to define the method of comparison for each element.

Parameters
aListthe list in which the search is to be conducted
contentpointer to the content to look for
callbackpointer to a function which compares each element
Returns
1=item removed, 0=item not removed
Here is the call graph for this function:

◆ ListEmpty()

void ListEmpty ( List aList)

Removes and frees all items in a list, leaving the list ready for new items.

Parameters
aListthe list to which the operation is to be applied

◆ ListFind()

ListElement* ListFind ( List aList,
void *  content 
)

Finds an element in a list by comparing the content pointers, rather than the contents.

Parameters
aListthe list in which the search is to be conducted
contentpointer to the list item content itself
Returns
the list item found, or NULL
Here is the call graph for this function:

◆ ListFindItem()

ListElement* ListFindItem ( List aList,
void *  content,
int(*)(void *, void *)  callback 
)

Finds an element in a list by comparing the content or pointer to the content.

A callback function is used to define the method of comparison for each element.

Parameters
aListthe list in which the search is to be conducted
contentpointer to the content to look for
callbackpointer to a function which compares each element (NULL means compare by content pointer)
Returns
the list element found, or NULL
Here is the call graph for this function:

◆ ListFree()

void ListFree ( List aList)

Removes and frees all items in a list, and frees the list itself.

Parameters
aListthe list to which the operation is to be applied
Here is the call graph for this function:

◆ ListFreeNoContent()

void ListFreeNoContent ( List aList)

Removes and but does not free all items in a list, and frees the list itself.

Parameters
aListthe list to which the operation is to be applied

◆ ListInitialize()

List* ListInitialize ( void  )

Allocates and initializes a new list structure.

Returns
a pointer to the new list structure
Here is the call graph for this function:

◆ ListInsert()

ListElement* ListInsert ( List aList,
void *  content,
size_t  size,
ListElement index 
)

Insert an item to a list at a specific position.

Parameters
aListthe list to which the item is to be added
contentthe list item content itself
sizethe size of the element
indexthe position in the list. If NULL, this function is equivalent to ListAppend.
Here is the call graph for this function:

◆ ListNextElement()

ListElement* ListNextElement ( List aList,
ListElement **  pos 
)

Forward iteration through a list.

Parameters
aListthe list to which the operation is to be applied
pospointer to the current position in the list. NULL means start from the beginning of the list This is updated on return to the same value as that returned from this function
Returns
pointer to the current list element

◆ ListPopTail()

void* ListPopTail ( List aList)

Removes but does not free the last item in a list.

Parameters
aListthe list from which the item is to be removed
Returns
the last item removed (or NULL if none was)

◆ ListPrevElement()

ListElement* ListPrevElement ( List aList,
ListElement **  pos 
)

Backward iteration through a list.

Parameters
aListthe list to which the operation is to be applied
pospointer to the current position in the list. NULL means start from the end of the list This is updated on return to the same value as that returned from this function
Returns
pointer to the current list element

◆ ListRemove()

int ListRemove ( List aList,
void *  content 
)

Removes and frees an item in a list by comparing the pointer to the content.

Parameters
aListthe list from which the item is to be removed
contentpointer to the content to look for
Returns
1=item removed, 0=item not removed
Here is the call graph for this function:

◆ ListRemoveHead()

int ListRemoveHead ( List aList)

Removes and frees an the first item in a list.

Parameters
aListthe list from which the item is to be removed
Returns
1=item removed, 0=item not removed
Here is the call graph for this function:

◆ ListRemoveItem()

int ListRemoveItem ( List aList,
void *  content,
int(*)(void *, void *)  callback 
)

Removes and frees an element in a list by comparing the content.

A callback function is used to define the method of comparison for each element

Parameters
aListthe list in which the search is to be conducted
contentpointer to the content to look for
callbackpointer to a function which compares each element
Returns
1=item removed, 0=item not removed
Here is the call graph for this function:

◆ ListUnlink()

static int ListUnlink ( List aList,
void *  content,
int(*)(void *, void *)  callback,
int  freeContent 
)
static

Removes and optionally frees an element in a list by comparing the content.

A callback function is used to define the method of comparison for each element.

Parameters
aListthe list in which the search is to be conducted
contentpointer to the content to look for
callbackpointer to a function which compares each element
freeContentboolean value to indicate whether the item found is to be freed
Returns
1=item removed, 0=item not removed
Here is the call graph for this function:

◆ ListZero()

void ListZero ( List newl)

Sets a list structure to empty - all null values.

Does not remove any items from the list.

Parameters
newla pointer to the list structure to be initialized

◆ stringcompare()

int stringcompare ( void *  a,
void *  b 
)

List callback function for comparing C strings.

Parameters
afirst integer value
bsecond integer value
Returns
boolean indicating whether a and b are equal