rtxDList.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2003-2010 Objective Systems, Inc.
00003  *
00004  * This software is furnished under a license and may be used and copied
00005  * only in accordance with the terms of such license and with the
00006  * inclusion of the above copyright notice. This software or any other
00007  * copies thereof may not be provided or otherwise made available to any
00008  * other person. No title to and ownership of the software is hereby
00009  * transferred.
00010  *
00011  * The information in this software is subject to change without notice
00012  * and should not be construed as a commitment by Objective Systems, Inc.
00013  *
00014  * PROPRIETARY NOTICE
00015  *
00016  * This software is an unpublished work subject to a confidentiality agreement
00017  * and is protected by copyright and trade secret law.  Unauthorized copying,
00018  * redistribution or other use of this work is prohibited.
00019  *
00020  * The above notice of copyright on this source code product does not indicate
00021  * any actual or intended publication of such source code.
00022  *
00023  *****************************************************************************/
00028 #ifndef _RTXDLIST_H_
00029 #define _RTXDLIST_H_
00030 
00031 #include "rtxsrc/osSysTypes.h"
00032 #include "rtxsrc/rtxExternDefs.h"
00033 #include "rtxsrc/rtxCommonDefs.h"
00052 typedef struct OSRTDListNode {
00053    void* data;            
00054    struct OSRTDListNode* next; 
00055    struct OSRTDListNode* prev; 
00056 } OSRTDListNode;
00057 
00064 typedef struct OSRTDList {
00065    OSUINT32 count;              
00066    OSRTDListNode* head;         
00067    OSRTDListNode* tail;         
00068 } OSRTDList;
00069 
00070 struct OSCTXT;
00071 
00072 typedef struct OSRTDListBuf {
00073    OSUINT32 n;
00074    OSUINT32 nMax;
00075    OSUINT32 nAll;
00076    OSUINT32 firstSegSz;
00077    size_t elemSize;
00078    OSRTDList tmplist;
00079    void** dataArray;
00080 } OSRTDListBuf;
00081 
00082 #ifndef DLISTBUF_SEG
00083 #define DLISTBUF_SEG 16
00084 #endif
00085 
00086 typedef struct OSRTDListUTF8StrNode {
00087    OSRTDListNode node;
00088    OSUTF8CHAR    utf8chars[1];
00089 } OSRTDListUTF8StrNode;
00090 
00091 #ifdef __cplusplus
00092 extern "C" {
00093 #endif
00094 
00095 /* Doubly-linked list functions */
00096 
00113 EXTERNRT void rtxDListInit (OSRTDList* pList);
00114 
00134 EXTERNRT OSRTDListNode* rtxDListAppend
00135 (struct OSCTXT* pctxt, OSRTDList* pList, void* pData);
00136 
00137 EXTERNRT OSRTDListNode* rtxDListAppendNode
00138 (OSRTDList* pList, OSRTDListNode* pListNode);
00139 
00159 EXTERNRT OSRTDListNode* rtxDListInsert
00160 (struct OSCTXT* pctxt, OSRTDList* pList, OSUINT32 index, void* pData);
00161 
00162 EXTERNRT OSRTDListNode* rtxDListInsertNode
00163 (OSRTDList* pList, OSUINT32 index, OSRTDListNode* pListNode);
00164 
00184 EXTERNRT OSRTDListNode* rtxDListInsertBefore
00185 (struct OSCTXT* pctxt, OSRTDList* pList, OSRTDListNode* node, void* pData);
00186 
00206 EXTERNRT OSRTDListNode* rtxDListInsertAfter
00207 (struct OSCTXT* pctxt, OSRTDList* pList, OSRTDListNode* node, void* pData);
00208 
00222 EXTERNRT OSRTDListNode*
00223 rtxDListFindByIndex (const OSRTDList* pList, OSUINT32 index);
00224 
00235 EXTERNRT OSRTDListNode*
00236 rtxDListFindByData (const OSRTDList* pList, void* data);
00237 
00248 EXTERNRT int rtxDListFindIndexByData (const OSRTDList* pList, void* data);
00249 
00259 EXTERNRT void rtxDListFreeNode
00260    (struct OSCTXT* pctxt, OSRTDList* pList, OSRTDListNode* node);
00261 
00270 EXTERNRT void rtxDListRemove (OSRTDList* pList, OSRTDListNode* node);
00271 
00280 EXTERNRT void rtxDListFreeNodes (struct OSCTXT* pctxt, OSRTDList* pList);
00281 
00291 EXTERNRT void rtxDListFreeAll (struct OSCTXT* pctxt, OSRTDList* pList);
00292 
00310 EXTERNRT int rtxDListToArray
00311 (struct OSCTXT* pctxt, OSRTDList* pList, void** ppArray,
00312  OSUINT32* pElemCount, size_t elemSize);
00313 
00330 EXTERNRT int rtxDListAppendArray
00331 (struct OSCTXT* pctxt, OSRTDList* pList, void* pArray,
00332  OSUINT32 numElements, size_t elemSize);
00333 
00349 EXTERNRT int rtxDListAppendArrayCopy
00350 (struct OSCTXT* pctxt, OSRTDList* pList, const void* pArray,
00351  OSUINT32 numElements, size_t elemSize);
00352 
00368 EXTERNRT int rtxDListToUTF8Str
00369 (struct OSCTXT* pctxt, OSRTDList* pList, OSUTF8CHAR** ppstr, char sep);
00370 
00371 
00372 
00373 typedef int (*PEqualsFunc) (const void* a, const void* b,
00374                                const void* sortCtxt);
00375 
00376 EXTERNRT OSRTDListNode* rtxDListInsertSorted
00377 (struct OSCTXT* pctxt, OSRTDList* pList, void* pData, PEqualsFunc equalsFunc,
00378  void* sortCtxt);
00379 
00380 EXTERNRT OSRTDListNode* rtxDListInsertNodeSorted
00381 (OSRTDList* pList, OSRTDListNode* pListNode, PEqualsFunc equalsFunc,
00382  void* sortCtxt);
00383 
00387 #if defined(_MSC_VER)
00388 // this disables 'conditional expression is constant' warnings
00389 // caused by using do { ... } while(0) in defines.
00390 #pragma warning(disable: 4127)
00391 #endif
00392 
00393 /* This rounds node size up to a 64-bit boundary to fix alignment issues */
00394 #define OSRTDLISTNODESIZE ((sizeof(OSRTDListNode)+7)&(~7))
00395 
00396 #define rtxDListAllocNodeAndData(pctxt,type,ppnode,ppdata) do { \
00397 *ppnode = (OSRTDListNode*) \
00398 rtxMemAlloc (pctxt, sizeof(type)+OSRTDLISTNODESIZE); \
00399 if (0 != *ppnode) { \
00400 (*ppnode)->data = (void*)((char*)(*ppnode)+OSRTDLISTNODESIZE); \
00401 *ppdata = (type*)((*ppnode)->data); \
00402 } else { *ppdata = 0; } \
00403 } while (0)
00404 
00405 #define rtxDListAppendData(pctxt,pList,pData) do { \
00406 OSRTDListNode* _node = (OSRTDListNode*) \
00407 (((char*)(pData)) - sizeof(OSRTDListNode)); \
00408 _node->data = pData; \
00409 rtxDListAppendNode (pList, _node); \
00410 } while (0);
00411 
00412 #define rtxDListFastInit(pList) do { \
00413 if ((pList) != 0) { \
00414 (pList)->head = (pList)->tail = (OSRTDListNode*) 0; \
00415 (pList)->count = 0; } \
00416 } while (0)
00417 
00418 #define rtxDListFreeTailNode(pctxt,pList) \
00419 rtxDListFreeNode(pctxt,pList,(pList)->tail)
00420 
00421 #define rtxDListFreeHeadNode(pctxt,pList) \
00422 rtxDListFreeNode(pctxt,pList,(pList)->head)
00423 
00424 /* Doubly-linked list buffer functions */
00425 
00426 EXTERNRT void rtxDListBufInit (OSRTDListBuf* pBuf,
00427    OSUINT32 segSz, void** ppdata, size_t elemSz);
00428 
00429 EXTERNRT int rtxDListBufExpand (struct OSCTXT* pctxt, OSRTDListBuf* pBuf);
00430 
00431 EXTERNRT int rtxDListBufToArray (struct OSCTXT* pctxt, OSRTDListBuf* pBuf);
00432 
00433 #ifdef __cplusplus
00434 }
00435 #endif
00436 
00437 #endif