Changeset 553


Ignore:
Timestamp:
Dec 12, 2015, 1:43:20 PM (8 years ago)
Author:
roman
Message:
 
Location:
trunk/Common/alax.info
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/alax.info/roatlcollections.h

    r482 r553  
    576576        typedef CAtlArray<_Element, _ElementTraits> CBaseArray;
    577577        typedef _Element CCollectionElement;
     578        typedef CRoArrayT<_Element, _ElementTraits> CRoArray;
    578579
    579580private:
     
    637638                return nIndex;
    638639        }
     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        }
    639689};
    640690
     
    896946        typedef CAtlMap<_KeyElement, _Element, _KeyElementTraits, _ElementTraits> CBaseMap;
    897947        typedef CRoMapT<_KeyElement, _Element, _KeyElementTraits, _ElementTraits> CMap;
     948        typedef _KeyElement CCollectionKeyElement;
    898949        typedef _Element CCollectionElement;
    899950
     
    9751026
    9761027        ////////////////////////////////////////////////////////
     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        ////////////////////////////////////////////////////////
    9771103        // CValueRangeIterator
    9781104
     
    10611187        {
    10621188                return CPositions(this);
     1189        }
     1190        CKeys GetKeys() const
     1191        {
     1192                return CKeys(this);
    10631193        }
    10641194        CValues GetValues() const
  • trunk/Common/alax.info/roatlcom.h

    r482 r553  
    101101#if _TRACE
    102102
     103inline 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
    103129#define DECLARE_QI_TRACE(_Class) \
    104130        static HRESULT WINAPI InternalQueryInterface(VOID* pThis, const _ATL_INTMAP_ENTRY* pEntries, REFIID InterfaceIdentifier, void** ppvObject) throw()\
     
    108134                _V(StringFromGUID2(InterfaceIdentifier, pszInterfaceIdentifier, DIM(pszInterfaceIdentifier))); \
    109135                ::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); \
    112139                ATLTRACE(atlTraceQI, SUCCEEDED(nResult) ? 4 : 3, _T("0x%p, Interface %s, Result 0x%08X\n"), pThis, sInterfaceName, nResult); \
    113140                return nResult;\
     
    561588public:
    562589// 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;
    568593                return 1;
    569594        }
    570         static VOID RevokeActiveObject(DWORD nCookie) throw()
    571         {
    572                 ATLASSERT(nCookie == 1);
     595        static VOID RevokeActiveObject(DWORD nCookie)
     596        {
     597                _A(nCookie == 1);
    573598        }
    574599};
     
    581606        {
    582607                DWORD nCookie;
    583                 ATLCHECK(::RegisterActiveObject(pUnknown, ClassIdentifier, nFlags, &nCookie));
     608                __C(::RegisterActiveObject(pUnknown, ClassIdentifier, nFlags, &nCookie));
    584609                return nCookie;
    585610        }
    586611        static VOID RevokeActiveObject(DWORD nCookie)
    587612        {
    588                 ATLCHECK(::RevokeActiveObject(nCookie, NULL));
     613                __C(::RevokeActiveObject(nCookie, NULL));
    589614        }
    590615};
     
    597622        {
    598623                WCHAR pszIdentifierString[64] = { 0 };
    599                 ATLVERIFY(StringFromGUID2(Identifier, pszIdentifierString, _countof(pszIdentifierString)));
     624                _W(StringFromGUID2(Identifier, pszIdentifierString, _countof(pszIdentifierString)));
    600625                return pszIdentifierString;
    601626        }
     
    604629                // NOTE: Direct registration into ROT allows us to specify ROTFLAGS_ALLOWANYCLIENT flag and
    605630                //       allow interaction between server *service* and client application
    606                 ATLASSERT(nFlags == ACTIVEOBJECT_STRONG);
     631                _A(nFlags == ACTIVEOBJECT_STRONG);
    607632                CComPtr<IRunningObjectTable> pRunningObjectTable;
    608                 ATLCHECK(GetRunningObjectTable(0, &pRunningObjectTable));
     633                __C(GetRunningObjectTable(0, &pRunningObjectTable));
    609634                CComPtr<IMoniker> pMoniker;
    610                 ATLCHECK(CreateItemMoniker(OLESTR("!"), StringFromIdentifier(ClassIdentifier), &pMoniker));
     635                __C(CreateItemMoniker(OLESTR("!"), StringFromIdentifier(ClassIdentifier), &pMoniker));
    611636                DWORD nCookie;
    612                 ATLCHECK(pRunningObjectTable->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE | ROTFLAGS_ALLOWANYCLIENT, pUnknown, pMoniker, &nCookie));
     637                __C(pRunningObjectTable->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE | ROTFLAGS_ALLOWANYCLIENT, pUnknown, pMoniker, &nCookie));
    613638                return nCookie;
    614639        }
     
    616641        {
    617642                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
     648template <typename CHandler = CRunningObjectActiveObjectHandler>
    624649class CActiveObjectT :
    625         protected _Handler
     650        protected CHandler
    626651{
    627652private:
    628         DWORD m_nCookie;                // Active object identifier
     653        DWORD m_nCookie;
    629654
    630655public:
    631656// CActiveObjectT
    632         CActiveObjectT() throw() :
     657        CActiveObjectT() :
    633658                m_nCookie(0)
    634659        {
    635660        }
    636         ~CActiveObjectT() throw()
     661        ~CActiveObjectT()
    637662        {
    638663                _ATLTRY
     
    645670                }
    646671        }
    647         DWORD GetCookie() const throw()
     672        DWORD GetCookie() const
    648673        {
    649674                return m_nCookie;
    650675        }
     676        BOOL IsRegistered() const
     677        {
     678                return GetCookie() != 0;
     679        }
    651680        VOID Register(IUnknown* pUnknown, const CLSID& ClassIdentifier, DWORD nFlags = ACTIVEOBJECT_STRONG)
    652681        {
    653                 ATLASSERT(m_nCookie == 0);
     682                _A(m_nCookie == 0);
    654683                m_nCookie = RegisterActiveObject(pUnknown, ClassIdentifier, nFlags);
    655                 ATLASSERT(m_nCookie);
     684                _A(m_nCookie);
    656685        }
    657686        VOID Unregister()
    658687        {
    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;
    664692        }
    665693};
Note: See TracChangeset for help on using the changeset viewer.