Changeset 553 for trunk/Common/alax.info/roatlcollections.h
- Timestamp:
- Dec 12, 2015, 1:43:20 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/alax.info/roatlcollections.h
r482 r553 576 576 typedef CAtlArray<_Element, _ElementTraits> CBaseArray; 577 577 typedef _Element CCollectionElement; 578 typedef CRoArrayT<_Element, _ElementTraits> CRoArray; 578 579 579 580 private: … … 637 638 return nIndex; 638 639 } 640 template <typename CParameter> 641 VOID Sort(SSIZE_T nFirstIndex, SSIZE_T nLastIndex, INT_PTR (*pCompare)(const typename _ElementTraits::INARGTYPE, const typename _ElementTraits::INARGTYPE, CParameter Parameter), CParameter Parameter) 642 { 643 _A(pCompare); 644 if(nLastIndex - nFirstIndex < 1) 645 return; 646 _Element* pElements = GetData(); 647 SSIZE_T nIndex1 = nFirstIndex, nIndex2 = nLastIndex; 648 SSIZE_T nIndex3 = (nIndex1 + nIndex2) / 2; 649 while(nIndex1 <= nIndex2) 650 { 651 while(pCompare(pElements[nIndex1], pElements[nIndex3], Parameter) < 0) 652 nIndex1++; 653 while(pCompare(pElements[nIndex3], pElements[nIndex2], Parameter) < 0) 654 nIndex2--; 655 if(nIndex1 <= nIndex2) 656 { 657 if(nIndex3 == nIndex1) 658 nIndex3 = nIndex2; 659 else if(nIndex3 == nIndex2) 660 nIndex3 = nIndex1; 661 _Element& ElementA = pElements[nIndex1++]; 662 _Element& ElementB = pElements[nIndex2--]; 663 CTempBufferT<_Element, sizeof (_Element)> pElement(1); 664 _ElementTraits::RelocateElements(pElement, &ElementA, 1); 665 _ElementTraits::RelocateElements(&ElementA, &ElementB, 1); 666 _ElementTraits::RelocateElements(&ElementB, pElement, 1); 667 } 668 } 669 if(nFirstIndex < nIndex2) 670 Sort<CParameter>(nFirstIndex, nIndex2, pCompare, Parameter); 671 if(nIndex1 < nLastIndex) 672 Sort<CParameter>(nIndex1, nLastIndex, pCompare, Parameter); 673 } 674 template <typename CParameter> 675 VOID Sort(INT_PTR (*pCompare)(const typename _ElementTraits::INARGTYPE, const typename _ElementTraits::INARGTYPE, CParameter Parameter), CParameter Parameter) 676 { 677 if(!IsEmpty()) 678 Sort<CParameter>(0, GetCount() - 1, pCompare, Parameter); 679 } 680 static INT_PTR DefaultCompare(const typename _ElementTraits::INARGTYPE Element1, const typename _ElementTraits::INARGTYPE Element2, INT) 681 { 682 return (Element1 < Element2) ? -1 : (Element1 <= Element2) ? 0 : +1; 683 } 684 VOID Sort() 685 { 686 if(!IsEmpty()) 687 Sort<INT>(0, GetCount() - 1, &CRoArray::DefaultCompare, 0); 688 } 639 689 }; 640 690 … … 896 946 typedef CAtlMap<_KeyElement, _Element, _KeyElementTraits, _ElementTraits> CBaseMap; 897 947 typedef CRoMapT<_KeyElement, _Element, _KeyElementTraits, _ElementTraits> CMap; 948 typedef _KeyElement CCollectionKeyElement; 898 949 typedef _Element CCollectionElement; 899 950 … … 975 1026 976 1027 //////////////////////////////////////////////////////// 1028 // CKeyRangeIterator 1029 1030 class CKeyRangeIterator 1031 { 1032 public: 1033 const CMap& m_Map; 1034 POSITION m_Position; 1035 1036 public: 1037 // CKeyRangeIterator 1038 ATL_FORCEINLINE CKeyRangeIterator(const CMap* pMap, POSITION Position) : 1039 m_Map(*pMap), 1040 m_Position(Position) 1041 { 1042 _A(pMap); 1043 } 1044 ATL_FORCEINLINE BOOL operator == (const CKeyRangeIterator& Key) const 1045 { 1046 _A(&m_Map == &Key.m_Map); 1047 return m_Position == Key.m_Position; 1048 } 1049 ATL_FORCEINLINE BOOL operator != (const CKeyRangeIterator& Key) const 1050 { 1051 return !(*this == Key); 1052 } 1053 ATL_FORCEINLINE CKeyRangeIterator& operator ++ () 1054 { 1055 m_Map.GetNext(m_Position); 1056 return *this; 1057 } 1058 ATL_FORCEINLINE operator const typename CMap::CCollectionKeyElement* () const 1059 { 1060 _A(m_Position); 1061 const typename CMap::CCollectionKeyElement& Element = m_Map.GetKeyAt(m_Position); 1062 const CAddressT<const typename CMap::CCollectionKeyElement>& ElementAddress = reinterpret_cast<const CAddressT<const typename CMap::CCollectionKeyElement>&>(Element); 1063 return &ElementAddress; 1064 } 1065 ATL_FORCEINLINE static CKeyRangeIterator begin(const CMap* pMap) 1066 { 1067 return CKeyRangeIterator(pMap, pMap->GetStartPosition()); 1068 } 1069 ATL_FORCEINLINE static CKeyRangeIterator end(const CMap* pMap) 1070 { 1071 return CKeyRangeIterator(pMap, NULL); 1072 } 1073 }; 1074 1075 //////////////////////////////////////////////////////// 1076 // CKeys 1077 1078 class CKeys 1079 { 1080 public: 1081 const CMap* m_pMap; 1082 1083 public: 1084 // CKeys 1085 ATL_FORCEINLINE CKeys(const CMap* pMap) : 1086 m_pMap(pMap) 1087 { 1088 _A(pMap); 1089 } 1090 1091 // Range Iterator 1092 ATL_FORCEINLINE CKeyRangeIterator begin() const 1093 { 1094 return CKeyRangeIterator::begin(m_pMap); 1095 } 1096 ATL_FORCEINLINE CKeyRangeIterator end() const 1097 { 1098 return CKeyRangeIterator::end(m_pMap); 1099 } 1100 }; 1101 1102 //////////////////////////////////////////////////////// 977 1103 // CValueRangeIterator 978 1104 … … 1061 1187 { 1062 1188 return CPositions(this); 1189 } 1190 CKeys GetKeys() const 1191 { 1192 return CKeys(this); 1063 1193 } 1064 1194 CValues GetValues() const
Note: See TracChangeset
for help on using the changeset viewer.