VirtualBox

Changeset 36563 in vbox for trunk/include/iprt


Ignore:
Timestamp:
Apr 5, 2011 3:28:31 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
70998
Message:

iprt-cpp: More RTC*List methods. Added explicit constructors to the specializations.

Location:
trunk/include/iprt/cpp
Files:
2 edited

Legend:

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

    r36533 r36563  
    130130    static inline void      set(T2 *p, size_t i, const T1 &v) { p[i] = v; }
    131131    static inline T1 &      at(T2 *p, size_t i) { return p[i]; }
     132    static inline size_t    find(T2 *p, const T1 &v, size_t cSize)
     133    {
     134        size_t i = 0;
     135        while(i < cSize)
     136        {
     137            if (p[i] == v)
     138                break;
     139            ++i;
     140        }
     141        return i;
     142    }
    132143    static inline void      copyTo(T2 *p, T2 *const p1 , size_t iTo, size_t cSize)
    133144    {
     
    148159    static inline void      set(T1 **p, size_t i, const T1 &v) { p[i] = new T1(v); }
    149160    static inline T1 &      at(T1 **p, size_t i) { return *p[i]; }
     161    static inline size_t    find(T1 **p, const T1 &v, size_t cSize)
     162    {
     163        size_t i = 0;
     164        while(i < cSize)
     165        {
     166            if (*p[i] == v)
     167                break;
     168            ++i;
     169        }
     170        return i;
     171    }
    150172    static inline void      copyTo(T1 **p, T1 **const p1 , size_t iTo, size_t cSize)
    151173    {
     
    557579
    558580    /**
     581     * Check if @a val is contained in the array.
     582     *
     583     * @param   val     The value to check for.
     584     * @return  true if it is found, false otherwise.
     585     */
     586    bool contains(const T &val) const
     587    {
     588        m_guard.enterRead();
     589        bool res = RTCListHelper<T, ITYPE>::find(m_pArray, val, m_cSize) != m_cSize;
     590        m_guard.leaveRead();
     591        return res;
     592    }
     593
     594    /**
     595     * Remove the first item.
     596     *
     597     * @note No boundary checks are done. Make sure @a i is equal or greater zero
     598     *       and smaller than RTCList::size.
     599     */
     600    void removeFirst()
     601    {
     602        removeAt(0);
     603    }
     604
     605    /**
     606     * Remove the last item.
     607     *
     608     * @note No boundary checks are done. Make sure @a i is equal or greater zero
     609     *       and smaller than RTCList::size.
     610     */
     611    void removeLast()
     612    {
     613        removeAt(m_cSize - 1);
     614    }
     615
     616    /**
    559617     * Remove the item at position @a i.
    560618     *
     
    608666        m_cSize = 0;
    609667        m_guard.leaveWrite();
     668    }
     669
     670    /**
     671     * Return the raw array. For native types this is a pointer to continuous
     672     * memory of the items. For pointer types this is a continuous memory of
     673     * pointers to the items.
     674     *
     675     * @warning If you change anything in the underlaying list, this memory
     676     *          will very likely become invalid. So take care when using this
     677     *          method and better try to avoid using it.
     678     *
     679     * @returns the raw memory.
     680     */
     681    ITYPE* raw() const
     682    {
     683        m_guard.enterRead();
     684        ITYPE* res = m_pArray;
     685        m_guard.leaveRead();
     686        return res;
    610687    }
    611688
     
    699776 */
    700777template <class T, typename ITYPE = typename RTCIf<(sizeof(T) > sizeof(void*)), T*, T>::result>
    701 class RTCList : public RTCListBase<T, ITYPE, false> {};
     778class RTCList : public RTCListBase<T, ITYPE, false>
     779{
     780    typedef RTCListBase<T, ITYPE, false> BASE;
     781public:
     782    RTCList(size_t cCapacity = BASE::DefaultCapacity)
     783     : BASE(cCapacity) {}
     784};
    702785
    703786/**
     
    708791 */
    709792template <>
    710 class RTCList<uint64_t>: public RTCListBase<uint64_t, uint64_t, false> {};
     793class RTCList<uint64_t>: public RTCListBase<uint64_t, uint64_t, false>
     794{
     795    typedef RTCListBase<uint64_t, uint64_t, false> BASE;
     796public:
     797    RTCList(size_t cCapacity = BASE::DefaultCapacity)
     798     : BASE(cCapacity) {}
     799};
    711800
    712801/**
     
    717806 */
    718807template <>
    719 class RTCList<int64_t>: public RTCListBase<int64_t, int64_t, false> {};
     808class RTCList<int64_t>: public RTCListBase<int64_t, int64_t, false>
     809{
     810    typedef RTCListBase<int64_t, int64_t, false> BASE;
     811public:
     812    RTCList(size_t cCapacity = BASE::DefaultCapacity)
     813     : BASE(cCapacity) {}
     814};
    720815
    721816/** @} */
  • trunk/include/iprt/cpp/mtlist.h

    r36532 r36563  
    7070 */
    7171template <class T, typename ITYPE = typename RTCIf<(sizeof(T) > sizeof(void*)), T*, T>::result>
    72 class RTCMTList : public RTCListBase<T, ITYPE, true> {};
     72class RTCMTList : public RTCListBase<T, ITYPE, true>
     73{
     74    typedef RTCListBase<T, ITYPE, true> BASE;
     75public:
     76    RTCMTList(size_t cCapacity = BASE::DefaultCapacity)
     77     : BASE(cCapacity) {}
     78};
    7379
    7480/**
     
    7985 */
    8086template <>
    81 class RTCMTList<uint64_t>: public RTCListBase<uint64_t, uint64_t, true> {};
     87class RTCMTList<uint64_t>: public RTCListBase<uint64_t, uint64_t, true>
     88{
     89    typedef RTCListBase<uint64_t, uint64_t, true> BASE;
     90public:
     91    RTCMTList(size_t cCapacity = BASE::DefaultCapacity)
     92     : BASE(cCapacity) {}
     93};
    8294
    8395/**
     
    88100 */
    89101template <>
    90 class RTCMTList<int64_t>: public RTCListBase<int64_t, uint64_t, true> {};
     102class RTCMTList<int64_t>: public RTCListBase<int64_t, int64_t, true>
     103{
     104    typedef RTCListBase<int64_t, int64_t, true> BASE;
     105public:
     106    RTCMTList(size_t cCapacity = BASE::DefaultCapacity)
     107     : BASE(cCapacity) {}
     108};
    91109
    92110/** @} */
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