41 #if defined(unittestDListVoid) && !defined(debugDListVoid) 42 #define debugDListVoid 75 #define DLISTVOID_ENTRY(dnode) dlist_entry(dnode, DListVoidNode_T, m_dnode) 82 #define DLISTVOID_IS_EMPTY(dvoidhead) \ 83 dlist_is_empty(&((dvoidhead)->m_dnodeHead)) 91 #define DLISTVOID_IS_EOL(dvoidhead, pdnode) \ 92 ((pdnode) == &((dvoidhead)->m_dnodeHead)) 458 if( (iIndex < 0) || (iIndex >= nCnt) )
460 LOGERROR(
"%d index is out of range", iIndex);
692 fprintf(fp,
"Node %2d: ", n);
704 #ifdef unittestDListVoid 706 #define UT_APP(p, s) DListVoidAppend(p, (void *)s, (size_t)(strlen(s)+1)) 707 #define UT_PRT(p) DListVoidPrint(p, UTDListVoidTestPrintCallback, fp) 709 static void UTDListVoidTestPrintCallback(FILE *fp,
void *pData)
711 fprintf(fp,
"'%s'", (
char *)pData);
714 void UTDListVoidTest()
716 const char *sTest =
"DListVoidTest";
724 fprintf(fp,
"%s: Appending apples, bananas, cherries, and dates\n", sTest);
725 pSav0 = UT_APP(pHead,
"apples");
726 pSav1 = UT_APP(pHead,
"bananas");
727 UT_APP(pHead,
"cherries");
728 pSav2 = UT_APP(pHead,
"dates");
732 fprintf(fp,
"%s: Deleting bananas\n", sTest);
736 fprintf(fp,
"%s: Deleting apples and dates\n", sTest);
741 fprintf(fp,
"%s: Appending eggplant, fennel, and grapes\n", sTest);
742 UT_APP(pHead,
"eggplant");
743 UT_APP(pHead,
"fennel");
744 UT_APP(pHead,
"grapes");
747 fprintf(fp,
"%s: Testing iterator\n", sTest);
748 for(pSav0=DListVoidIterFirst(pHead, &iter); pSav0 !=
NULL;
749 pSav0=DListVoidIterNext(&iter))
751 fprintf(fp,
"%s: node data = '%s'\n",
755 fprintf(fp,
"%s: Deleting all\n", sTest);
759 #endif // unittestDListVoid void * m_pNext
pointer to next dnode
int(* DListVoidFuncDataCmp_T)(const void *, const void *)
Base: Node data comparator callback function type.
DListVoidNode_T * DListVoidUnlinkNodeAt(DListVoid_T *pHead, int iIndex)
Unlink the node from the dlist at the given index.
DListVoidNode_T * DListVoidIterNodeLast(DListVoid_T *pHead, DListVoidIter_T *pIter)
Initialize dlist iterator and return the last node in dlist.
#define DLIST_NODE_INIT(node)
Initialize node links.
Base dlist iterator structure.
#define _TINT(var)
int (decimal)
static void dlist_prepend(dnode_t *node, dnode_t *head)
prepend new node to head of list
void * DListVoidGetData(DListVoidNode_T *pNode)
Get the user data from the given node.
#define DLISTVOID_IS_EOL(dvoidhead, pdnode)
Test if node is at end-of-list.
void * DListVoidUnlinkDataAt(DListVoid_T *pHead, int iIndex)
Unlink the user data from the dlist at the given index.
#define CHKPTR(p,...)
Checks validity of pointer.
dnode_t m_dnode
dlist pointers
DListVoidNode_T * DListVoidPrepend(DListVoid_T *pHead, void *pData)
Attach the user data to a new node and link to the start of dlist.
Memory allocation and deallocation declarations.
void * m_pThis
pointer to current dnode
The doubly linked node structure.
DListVoidNode_T * DListVoidAppend(DListVoid_T *pHead, void *pData)
Attach user data to a new node and link to the end of dlist.
DListVoidNode_T * DListVoidIterNodeNext(DListVoidIter_T *pIter)
Get the next iterated node in dlist.
Doubly linked list base implementation.
void DListVoidDeleteNode(DListVoid_T *pHead, DListVoidNode_T *pNode)
Unlink node from the dlist and delete the node and it's attached user data.
DListVoid_T * DListVoidNew(DListVoidFuncDataCmp_T fnDataCmp, DListVoidFuncDataDelete_T fnDataDelete)
Allocate and initialize new empty dlist.
DListVoidNode_T * DListVoidIterNodePrev(DListVoidIter_T *pIter)
Get the previous iterated node in dlist.
#define DLISTVOID_IS_EMPTY(dvoidhead)
Test if DListVoid_T* holds the empty list.
static void dlist_delete(dnode_t *node)
deletes node from list
#define DLIST_INSERT_AT_END
Special dlist index value to insert before end-of-list.
#define LOGERROR(fmt,...)
Standard Error logging.
#define LOGDIAG4(fmt,...)
Standard Diagnostic Level 4 logging.
static void dlist_append(dnode_t *node, dnode_t *head)
append a new node to the in of the list
Doubly linked list (dlist) of data pointers #defines, types, and declarations.
#define NEW(T)
Allocate new type.
void(* DListVoidFuncDataDelete_T)(void *)
Base: Node data delete callback function type.
struct dlist_node * next
next node in dlist
void DListVoidDeleteAllNodes(DListVoid_T *pHead)
Unlink and delete all nodes and data from dlist, leaving dlist empty.
int DListVoidCount(DListVoid_T *pHead)
Get the number of nodes in dlist.
RoadNarrows Robotics common configuration file.
void DListVoidDelete(DListVoid_T *pHead)
Delete entire dlist.
DListVoidFuncDataDelete_T m_fnDataDelete
data delete function
struct dlist_node * prev
previous node in dlist
#define dlist_for_each_safe(pos, npos, head)
safely iterate over a list
Unit Tests (define to build test main)
#define DLISTVOID_ENTRY(dnode)
Get embedding node DListVoidNode_T.
#define _TPTR(var)
pointer
#define LOGDIAG4CALL(...)
Standard Diagnostic Level 4 function call tracing.
DListVoidNode_T * DListVoidInsert(DListVoid_T *pHead, int iIndex, void *pData)
Attach the user data to a new node and insert before the dlist index.
DListVoidNode_T * DListVoidIterNodeFirst(DListVoid_T *pHead, DListVoidIter_T *pIter)
Initialize dlist iterator and return the first node in dlist.
void * DListVoidGetDataAt(DListVoid_T *pHead, int iIndex)
Get the user data from the dlist at the given index.
Doubly linked list node structure.
void DListVoidDeleteNodeAt(DListVoid_T *pHead, int iIndex)
Unlink the node from the dlist at the given index and delete it and it's attached user data...
int m_nNumNodes
number of nodes in dlist
DListVoidNode_T * DListVoidFindNode(DListVoid_T *pHead, const void *pData)
Find the first node with the matching data.
static void _dlist_add(dnode_t *node, dnode_t *prev, dnode_t *next)
insert a new entry between two known consecutive entries
DListVoidFuncDataCmp_T m_fnDataCmp
data compare function
void * DListVoidGetNodeAt(DListVoid_T *pHead, int iIndex)
Get the node at the given dlist index.
void(* DListVoidFuncDataPrint_T)(FILE *, void *)
Base: Print node data callback function type.
dnode_t m_dnodeHead
head of dlist
void DListVoidPrint(DListVoid_T *pHead, DListVoidFuncDataPrint_T fnDataPr, FILE *fp)
Traverse dlist and print.
DListVoid_T * m_pHead
pointer to dlistvoid head