VirtualBox

Changeset 26813 in vbox for trunk


Ignore:
Timestamp:
Feb 25, 2010 10:32:48 PM (15 years ago)
Author:
vboxsync
Message:

IPRT/List: Add a method to move the list to a new header

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/list.h

    r26740 r26813  
    200200    (!RTListIsEmpty(pList) ? RTListNodeGetPrev(pList, Type, Member) : NULL)
    201201
     202/**
     203 * Move the given list to a new list header.
     204 *
     205 * @param   pListDst            The new list.
     206 * @param   pListSrc            The list to move.
     207 */
     208DECLINLINE(void) RTListMove(PRTLISTNODE pListDst, PRTLISTNODE pListSrc)
     209{
     210    if (!RTListIsEmpty(pListSrc))
     211    {
     212        pListDst->pNext = pListSrc->pNext;
     213        pListDst->pPrev = pListSrc->pPrev;
     214
     215        /* Adjust the first and last element links */
     216        pListDst->pNext->pPrev = pListDst;
     217        pListDst->pPrev->pNext = pListDst;
     218
     219        /* Finally remove the elements from the source list */
     220        RTListInit(pListSrc);
     221    }
     222}
     223
    202224RT_C_DECLS_END
    203225
  • trunk/src/VBox/Runtime/testcase/tstRTList.cpp

    r26772 r26813  
    113113    tstRTListOrder(hTest, &ListHead, cElements, 0, cElements-1, 1);
    114114
     115    /* Move the list to a new one. */
     116    RTLISTNODE ListHeadNew;
     117
     118    RTListInit(&ListHeadNew);
     119    RTListMove(&ListHeadNew, &ListHead);
     120
     121    RTTEST_CHECK(hTest, RTListIsEmpty(&ListHead) == true);
     122    RTTEST_CHECK(hTest, RTListNodeGetFirst(&ListHead, LISTELEM, Node) == NULL);
     123    RTTEST_CHECK(hTest, RTListNodeGetLast(&ListHead, LISTELEM, Node) == NULL);
     124
     125    tstRTListOrder(hTest, &ListHeadNew, cElements, 0, cElements-1, 1);
     126
    115127    /* Remove elements now  */
    116128    if (cElements > 1)
     
    119131        RTTestISub("Remove every second node");
    120132
    121         PLISTELEM pNode = RTListNodeGetFirst(&ListHead, LISTELEM, Node);
     133        PLISTELEM pNode = RTListNodeGetFirst(&ListHeadNew, LISTELEM, Node);
    122134        for (unsigned i = 0; i < cElements; i++)
    123135        {
     
    137149
    138150        cElements /= 2;
    139         tstRTListOrder(hTest, &ListHead, cElements, 1, idxEnd, 2);
     151        tstRTListOrder(hTest, &ListHeadNew, cElements, 1, idxEnd, 2);
    140152    }
    141153
    142154    /* Remove the rest now. */
    143155    RTTestISub("Remove all nodes");
    144     PLISTELEM pNode = RTListNodeGetFirst(&ListHead, LISTELEM, Node);
     156    PLISTELEM pNode = RTListNodeGetFirst(&ListHeadNew, LISTELEM, Node);
    145157    for (unsigned i = 0; i < cElements; i++)
    146158    {
     
    153165
    154166    /* List should be empty again */
    155     RTTEST_CHECK(hTest, RTListIsEmpty(&ListHead) == true);
    156     RTTEST_CHECK(hTest, RTListNodeGetFirst(&ListHead, LISTELEM, Node) == NULL);
    157     RTTEST_CHECK(hTest, RTListNodeGetLast(&ListHead, LISTELEM, Node) == NULL);
     167    RTTEST_CHECK(hTest, RTListIsEmpty(&ListHeadNew) == true);
     168    RTTEST_CHECK(hTest, RTListNodeGetFirst(&ListHeadNew, LISTELEM, Node) == NULL);
     169    RTTEST_CHECK(hTest, RTListNodeGetLast(&ListHeadNew, LISTELEM, Node) == NULL);
    158170}
    159171
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette