VirtualBox

Changeset 97825 in vbox


Ignore:
Timestamp:
Dec 16, 2022 2:40:21 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
154905
Message:

IPRT: Added RTCListBase::filter() + testcases.

Location:
trunk
Files:
2 edited

Legend:

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

    r97823 r97825  
    590590
    591591    /**
     592     * Applies a filter of type T to this list.
     593     *
     594     * @param   other           The list which contains the elements to filter out from this list.
     595     * @return  a reference to this list.
     596     */
     597    RTCListBase<T, ITYPE, MT> &filter(const RTCListBase<T, ITYPE, MT> &other)
     598    {
     599        AssertReturn(this != &other, *this);
     600
     601        other.m_guard.enterRead();
     602        m_guard.enterWrite();
     603
     604        for (size_t i = 0; i < m_cElements; i++)
     605        {
     606            for (size_t f = 0; f < other.m_cElements; f++)
     607            {
     608                if (RTCListHelper<T, ITYPE>::at(m_pArray, i) == RTCListHelper<T, ITYPE>::at(other.m_pArray, f))
     609                    removeAtLocked(i);
     610            }
     611        }
     612
     613        m_guard.leaveWrite();
     614        other.m_guard.leaveRead();
     615        return *this;
     616    }
     617
     618    /**
    592619     * Return the first item as constant object.
    593620     *
  • trunk/src/VBox/Runtime/testcase/tstIprtMiniList.cpp

    r97823 r97825  
    7979        RTTESTI_CHECK(spList1 != spList4);
    8080
     81        /*
     82         * Test filtering.
     83         */
     84        /* Basics. */
     85        RTCList<RTCString> spListFiltered;
     86        spListFiltered.filter(RTCString("").split(",")); /* Empty filter. */
     87        /* String list. */
     88        spListFiltered = RTCString("filter-out1,filter-out2,foo").split(",");
     89        spListFiltered.filter(RTCString("filter-out1,filter-out2").split(","));
     90        RTTESTI_CHECK(spListFiltered == RTCString("foo").split(","));
     91        /* Repeat. */
     92        spListFiltered.filter(RTCString("filter-out1,filter-out2").split(","));
     93        RTTESTI_CHECK(spListFiltered == RTCString("foo").split(","));
     94        RTTESTI_CHECK(spListFiltered != RTCString("bar").split(","));
     95
    8196        rcExit = RTTestSummaryAndDestroy(hTest);
    8297    }
Note: See TracChangeset for help on using the changeset viewer.

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