Changeset 553
- Timestamp:
- Dec 12, 2015, 1:43:20 PM (8 years ago)
- Location:
- trunk/Common/alax.info
- Files:
-
- 2 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 -
trunk/Common/alax.info/roatlcom.h
r482 r553 101 101 #if _TRACE 102 102 103 inline BOOL TryFormatInterfaceName(const IID& Identifier, CString& sName) 104 { 105 _A(sName.IsEmpty()); 106 static const CEnumerationNameT<IID> g_pMap[] = 107 { 108 #define A(x) { __uuidof(x), #x }, 109 A(IActivationFilter) 110 A(IMarshal) 111 //A(IProxyManager) 112 A(IStdMarshalInfo) 113 A(IExternalConnection) 114 //A(IdentityUnmarshal) 115 A(IMultiQI) 116 A(IInternalUnknown) 117 A(IFastRundown) 118 A(INoMarshal) 119 A(IDataObject) 120 A(IAgileObject) 121 A(IClassFactory) 122 A(IClassFactory2) 123 #undef A 124 }; 125 sName = FormatEnumerationT(g_pMap, Identifier, TRUE); 126 return !sName.IsEmpty(); 127 } 128 103 129 #define DECLARE_QI_TRACE(_Class) \ 104 130 static HRESULT WINAPI InternalQueryInterface(VOID* pThis, const _ATL_INTMAP_ENTRY* pEntries, REFIID InterfaceIdentifier, void** ppvObject) throw()\ … … 108 134 _V(StringFromGUID2(InterfaceIdentifier, pszInterfaceIdentifier, DIM(pszInterfaceIdentifier))); \ 109 135 ::CString sInterfaceName; \ 110 if(!_RegKeyHelper::QueryStringValue(HKEY_CLASSES_ROOT, AtlFormatString(_T("Interface\\%ls"), pszInterfaceIdentifier), NULL, sInterfaceName)) \ 111 sInterfaceName = ::CString(pszInterfaceIdentifier); \ 136 if(!TryFormatInterfaceName(InterfaceIdentifier, sInterfaceName)) \ 137 if(!_RegKeyHelper::QueryStringValue(HKEY_CLASSES_ROOT, AtlFormatString(_T("Interface\\%ls"), pszInterfaceIdentifier), NULL, sInterfaceName)) \ 138 sInterfaceName = ::CString(pszInterfaceIdentifier); \ 112 139 ATLTRACE(atlTraceQI, SUCCEEDED(nResult) ? 4 : 3, _T("0x%p, Interface %s, Result 0x%08X\n"), pThis, sInterfaceName, nResult); \ 113 140 return nResult;\ … … 561 588 public: 562 589 // CFakeActiveObjectHandler 563 static DWORD RegisterActiveObject(IUnknown* pUnknown, REFCLSID ClassIdentifier, DWORD nFlags) throw() 564 { 565 pUnknown; 566 ClassIdentifier; 567 nFlags; 590 static DWORD RegisterActiveObject(IUnknown* pUnknown, REFCLSID ClassIdentifier, DWORD nFlags) 591 { 592 pUnknown; ClassIdentifier; nFlags; 568 593 return 1; 569 594 } 570 static VOID RevokeActiveObject(DWORD nCookie) throw()571 { 572 ATLASSERT(nCookie == 1);595 static VOID RevokeActiveObject(DWORD nCookie) 596 { 597 _A(nCookie == 1); 573 598 } 574 599 }; … … 581 606 { 582 607 DWORD nCookie; 583 ATLCHECK(::RegisterActiveObject(pUnknown, ClassIdentifier, nFlags, &nCookie));608 __C(::RegisterActiveObject(pUnknown, ClassIdentifier, nFlags, &nCookie)); 584 609 return nCookie; 585 610 } 586 611 static VOID RevokeActiveObject(DWORD nCookie) 587 612 { 588 ATLCHECK(::RevokeActiveObject(nCookie, NULL));613 __C(::RevokeActiveObject(nCookie, NULL)); 589 614 } 590 615 }; … … 597 622 { 598 623 WCHAR pszIdentifierString[64] = { 0 }; 599 ATLVERIFY(StringFromGUID2(Identifier, pszIdentifierString, _countof(pszIdentifierString)));624 _W(StringFromGUID2(Identifier, pszIdentifierString, _countof(pszIdentifierString))); 600 625 return pszIdentifierString; 601 626 } … … 604 629 // NOTE: Direct registration into ROT allows us to specify ROTFLAGS_ALLOWANYCLIENT flag and 605 630 // allow interaction between server *service* and client application 606 ATLASSERT(nFlags == ACTIVEOBJECT_STRONG);631 _A(nFlags == ACTIVEOBJECT_STRONG); 607 632 CComPtr<IRunningObjectTable> pRunningObjectTable; 608 ATLCHECK(GetRunningObjectTable(0, &pRunningObjectTable));633 __C(GetRunningObjectTable(0, &pRunningObjectTable)); 609 634 CComPtr<IMoniker> pMoniker; 610 ATLCHECK(CreateItemMoniker(OLESTR("!"), StringFromIdentifier(ClassIdentifier), &pMoniker));635 __C(CreateItemMoniker(OLESTR("!"), StringFromIdentifier(ClassIdentifier), &pMoniker)); 611 636 DWORD nCookie; 612 ATLCHECK(pRunningObjectTable->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE | ROTFLAGS_ALLOWANYCLIENT, pUnknown, pMoniker, &nCookie));637 __C(pRunningObjectTable->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE | ROTFLAGS_ALLOWANYCLIENT, pUnknown, pMoniker, &nCookie)); 613 638 return nCookie; 614 639 } … … 616 641 { 617 642 CComPtr<IRunningObjectTable> pRunningObjectTable; 618 ATLCHECK(GetRunningObjectTable(0, &pRunningObjectTable));619 ATLCHECK(pRunningObjectTable->Revoke(nCookie));620 } 621 }; 622 623 template <typename _Handler = CRunningObjectActiveObjectHandler>643 __C(GetRunningObjectTable(0, &pRunningObjectTable)); 644 __C(pRunningObjectTable->Revoke(nCookie)); 645 } 646 }; 647 648 template <typename CHandler = CRunningObjectActiveObjectHandler> 624 649 class CActiveObjectT : 625 protected _Handler650 protected CHandler 626 651 { 627 652 private: 628 DWORD m_nCookie; // Active object identifier653 DWORD m_nCookie; 629 654 630 655 public: 631 656 // CActiveObjectT 632 CActiveObjectT() throw():657 CActiveObjectT() : 633 658 m_nCookie(0) 634 659 { 635 660 } 636 ~CActiveObjectT() throw()661 ~CActiveObjectT() 637 662 { 638 663 _ATLTRY … … 645 670 } 646 671 } 647 DWORD GetCookie() const throw()672 DWORD GetCookie() const 648 673 { 649 674 return m_nCookie; 650 675 } 676 BOOL IsRegistered() const 677 { 678 return GetCookie() != 0; 679 } 651 680 VOID Register(IUnknown* pUnknown, const CLSID& ClassIdentifier, DWORD nFlags = ACTIVEOBJECT_STRONG) 652 681 { 653 ATLASSERT(m_nCookie == 0);682 _A(m_nCookie == 0); 654 683 m_nCookie = RegisterActiveObject(pUnknown, ClassIdentifier, nFlags); 655 ATLASSERT(m_nCookie);684 _A(m_nCookie); 656 685 } 657 686 VOID Unregister() 658 687 { 659 if(m_nCookie) 660 { 661 RevokeActiveObject(m_nCookie); 662 m_nCookie = 0; 663 } 688 if(!m_nCookie) 689 return; 690 RevokeActiveObject(m_nCookie); 691 m_nCookie = 0; 664 692 } 665 693 };
Note: See TracChangeset
for help on using the changeset viewer.