Changeset 36563 in vbox for trunk/include/iprt
- Timestamp:
- Apr 5, 2011 3:28:31 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 70998
- Location:
- trunk/include/iprt/cpp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/list.h
r36533 r36563 130 130 static inline void set(T2 *p, size_t i, const T1 &v) { p[i] = v; } 131 131 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 } 132 143 static inline void copyTo(T2 *p, T2 *const p1 , size_t iTo, size_t cSize) 133 144 { … … 148 159 static inline void set(T1 **p, size_t i, const T1 &v) { p[i] = new T1(v); } 149 160 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 } 150 172 static inline void copyTo(T1 **p, T1 **const p1 , size_t iTo, size_t cSize) 151 173 { … … 557 579 558 580 /** 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 /** 559 617 * Remove the item at position @a i. 560 618 * … … 608 666 m_cSize = 0; 609 667 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; 610 687 } 611 688 … … 699 776 */ 700 777 template <class T, typename ITYPE = typename RTCIf<(sizeof(T) > sizeof(void*)), T*, T>::result> 701 class RTCList : public RTCListBase<T, ITYPE, false> {}; 778 class RTCList : public RTCListBase<T, ITYPE, false> 779 { 780 typedef RTCListBase<T, ITYPE, false> BASE; 781 public: 782 RTCList(size_t cCapacity = BASE::DefaultCapacity) 783 : BASE(cCapacity) {} 784 }; 702 785 703 786 /** … … 708 791 */ 709 792 template <> 710 class RTCList<uint64_t>: public RTCListBase<uint64_t, uint64_t, false> {}; 793 class RTCList<uint64_t>: public RTCListBase<uint64_t, uint64_t, false> 794 { 795 typedef RTCListBase<uint64_t, uint64_t, false> BASE; 796 public: 797 RTCList(size_t cCapacity = BASE::DefaultCapacity) 798 : BASE(cCapacity) {} 799 }; 711 800 712 801 /** … … 717 806 */ 718 807 template <> 719 class RTCList<int64_t>: public RTCListBase<int64_t, int64_t, false> {}; 808 class RTCList<int64_t>: public RTCListBase<int64_t, int64_t, false> 809 { 810 typedef RTCListBase<int64_t, int64_t, false> BASE; 811 public: 812 RTCList(size_t cCapacity = BASE::DefaultCapacity) 813 : BASE(cCapacity) {} 814 }; 720 815 721 816 /** @} */ -
trunk/include/iprt/cpp/mtlist.h
r36532 r36563 70 70 */ 71 71 template <class T, typename ITYPE = typename RTCIf<(sizeof(T) > sizeof(void*)), T*, T>::result> 72 class RTCMTList : public RTCListBase<T, ITYPE, true> {}; 72 class RTCMTList : public RTCListBase<T, ITYPE, true> 73 { 74 typedef RTCListBase<T, ITYPE, true> BASE; 75 public: 76 RTCMTList(size_t cCapacity = BASE::DefaultCapacity) 77 : BASE(cCapacity) {} 78 }; 73 79 74 80 /** … … 79 85 */ 80 86 template <> 81 class RTCMTList<uint64_t>: public RTCListBase<uint64_t, uint64_t, true> {}; 87 class RTCMTList<uint64_t>: public RTCListBase<uint64_t, uint64_t, true> 88 { 89 typedef RTCListBase<uint64_t, uint64_t, true> BASE; 90 public: 91 RTCMTList(size_t cCapacity = BASE::DefaultCapacity) 92 : BASE(cCapacity) {} 93 }; 82 94 83 95 /** … … 88 100 */ 89 101 template <> 90 class RTCMTList<int64_t>: public RTCListBase<int64_t, uint64_t, true> {}; 102 class RTCMTList<int64_t>: public RTCListBase<int64_t, int64_t, true> 103 { 104 typedef RTCListBase<int64_t, int64_t, true> BASE; 105 public: 106 RTCMTList(size_t cCapacity = BASE::DefaultCapacity) 107 : BASE(cCapacity) {} 108 }; 91 109 92 110 /** @} */
Note:
See TracChangeset
for help on using the changeset viewer.