Changed ref counting, removed the kiknown for ref counting

reworked and reformated the code.
This commit is contained in:
rods%netscape.com 1999-05-04 22:44:21 +00:00
parent 58c3d70d11
commit b07217f0e1
2 changed files with 136 additions and 156 deletions

View File

@ -1,21 +1,23 @@
/*
* IENUMFE.CPP
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* Standard implementation of a FORMATETC enumerator with the
* IEnumFORMATETC interface that will generally not need
* modification.
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Copyright (c)1993-1994 Microsoft Corporation, All Rights Reserved
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "ienumfe.h"
#include <stdio.h>
/*
@ -23,29 +25,27 @@
* CEnumFormatEtc::~CEnumFormatEtc
*
* Parameters (Constructor):
* pUnkRef LPUNKNOWN to use for reference counting.
* cFE ULONG number of FORMATETCs in pFE
* prgFE LPFORMATETC to the array to enumerate.
*/
CEnumFormatEtc::CEnumFormatEtc(LPUNKNOWN pUnkRef, ULONG cFE, LPFORMATETC prgFE)
CEnumFormatEtc::CEnumFormatEtc(ULONG aNumFEs, LPFORMATETC aFEList)
{
UINT i;
m_cRef=0;
m_pUnkRef=pUnkRef;
mRefCnt = 0;
m_iCur = 0;
m_cfe = cFE;
m_maxcfe = cFE;
m_prgfe=new FORMATETC[(UINT)cFE];
mCurrentInx = 0;
mNumFEs = aNumFEs;
mMaxNumFEs = aNumFEs;
mFEList = new FORMATETC[(UINT)aNumFEs];
if (NULL!=m_prgfe) {
for (i=0; i < cFE; i++)
m_prgfe[i]=prgFE[i];
if (NULL!=mFEList) {
for (i=0; i < aNumFEs; i++) {
mFEList[i] = aFEList[i];
}
}
return;
}
/*
@ -57,30 +57,30 @@ CEnumFormatEtc::CEnumFormatEtc(LPUNKNOWN pUnkRef, ULONG cFE, LPFORMATETC prgFE)
* cFE ULONG number of FORMATETCs in pFE
*/
CEnumFormatEtc::CEnumFormatEtc(LPUNKNOWN pUnkRef, ULONG cMaxFE)
CEnumFormatEtc::CEnumFormatEtc(ULONG aMaxFE)
{
//UINT i;
mRefCnt = 0;
m_cRef=0;
m_pUnkRef=pUnkRef;
m_iCur = 0;
m_cfe = 0;
m_maxcfe = cMaxFE;
m_prgfe=new FORMATETC[(UINT)cMaxFE];
mCurrentInx = 0;
mNumFEs = 0;
mMaxNumFEs = aMaxFE;
mFEList = new FORMATETC[(UINT)aMaxFE];
}
//----------------------------------------------------
CEnumFormatEtc::~CEnumFormatEtc(void)
{
if (NULL!=m_prgfe)
delete [] m_prgfe;
if (NULL != mFEList) {
delete [] mFEList;
}
}
//----------------------------------------------------
void CEnumFormatEtc::AddFE(LPFORMATETC aFE)
{
m_prgfe[m_cfe++] = *aFE;
mFEList[mNumFEs++] = *aFE;
}
/*
@ -122,34 +122,27 @@ STDMETHODIMP CEnumFormatEtc::QueryInterface(REFIID riid, LPVOID *ppv)
return ResultFromScode(E_NOINTERFACE);
}
STDMETHODIMP_(ULONG) CEnumFormatEtc::AddRef(void)
{
++m_cRef;
m_pUnkRef->AddRef();
return m_cRef;
++mRefCnt;
//printf("CEnumFormatEtc::AddRef >>>>>>>>>>>>>>>>>> %d on %p\n", mRefCnt, this);
return mRefCnt;
}
STDMETHODIMP_(ULONG) CEnumFormatEtc::Release(void)
{
ULONG cRefT;
cRefT=--m_cRef;
cRefT = --mRefCnt;
m_pUnkRef->Release();
if (0L==m_cRef)
if (0L == mRefCnt)
delete this;
//printf("CEnumFormatEtc::Release >>>>>>>>>>>>>>>>>> %d on %p\n", mRefCnt, this);
return cRefT;
}
/*
* CEnumFormatEtc::Next
*
@ -171,7 +164,7 @@ STDMETHODIMP CEnumFormatEtc::Next(ULONG cFE, LPFORMATETC pFE, ULONG * pulFE)
{
ULONG cReturn=0L;
if (NULL==m_prgfe)
if (NULL==mFEList)
return ResultFromScode(S_FALSE);
if (NULL==pulFE)
@ -182,12 +175,12 @@ STDMETHODIMP CEnumFormatEtc::Next(ULONG cFE, LPFORMATETC pFE, ULONG * pulFE)
else
*pulFE=0L;
if (NULL==pFE || m_iCur >= m_cfe)
if (NULL==pFE || mCurrentInx >= mNumFEs)
return ResultFromScode(S_FALSE);
while (m_iCur < m_cfe && cFE > 0)
while (mCurrentInx < mNumFEs && cFE > 0)
{
*pFE++=m_prgfe[m_iCur++];
*pFE++=mFEList[mCurrentInx++];
cReturn++;
cFE--;
}
@ -198,12 +191,6 @@ STDMETHODIMP CEnumFormatEtc::Next(ULONG cFE, LPFORMATETC pFE, ULONG * pulFE)
return NOERROR;
}
/*
* CEnumFormatEtc::Skip
*
@ -220,18 +207,13 @@ STDMETHODIMP CEnumFormatEtc::Next(ULONG cFE, LPFORMATETC pFE, ULONG * pulFE)
STDMETHODIMP CEnumFormatEtc::Skip(ULONG cSkip)
{
if (((m_iCur+cSkip) >= m_cfe) || NULL==m_prgfe)
if (((mCurrentInx+cSkip) >= mNumFEs) || NULL==mFEList)
return ResultFromScode(S_FALSE);
m_iCur+=cSkip;
mCurrentInx+=cSkip;
return NOERROR;
}
/*
* CEnumFormatEtc::Reset
*
@ -247,15 +229,10 @@ STDMETHODIMP CEnumFormatEtc::Skip(ULONG cSkip)
STDMETHODIMP CEnumFormatEtc::Reset(void)
{
m_iCur=0;
mCurrentInx=0;
return NOERROR;
}
/*
* CEnumFormatEtc::Clone
*
@ -277,13 +254,13 @@ STDMETHODIMP CEnumFormatEtc::Clone(LPENUMFORMATETC *ppEnum)
*ppEnum=NULL;
//Create the clone
pNew=new CEnumFormatEtc(m_pUnkRef, m_cfe, m_prgfe);
pNew = new CEnumFormatEtc(mNumFEs, mFEList);
if (NULL==pNew)
return ResultFromScode(E_OUTOFMEMORY);
pNew->AddRef();
pNew->m_iCur=m_iCur;
pNew->mCurrentInx=mCurrentInx;
*ppEnum=pNew;
return NOERROR;

View File

@ -1,15 +1,19 @@
/*
* IENUMFE.H
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* Definitions of a template IDataObject interface implementation.
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Copyright (c)1993-1994 Microsoft Corporation, All Right Reserved
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
@ -33,16 +37,15 @@ typedef class CEnumFormatEtc *LPCEnumFormatEtc;
class CEnumFormatEtc : public IEnumFORMATETC
{
private:
ULONG m_cRef; //Object reference count
LPUNKNOWN m_pUnkRef; //IUnknown for ref counting
ULONG m_iCur; //Current element
ULONG m_cfe; //Number of FORMATETCs in us
LPFORMATETC m_prgfe; //Source of FORMATETCs
ULONG m_maxcfe; // Max number of us
ULONG mRefCnt; // Object reference count
ULONG mCurrentInx; // Current element
ULONG mNumFEs; // Number of FORMATETCs in us
LPFORMATETC mFEList; // Source of FORMATETCs
ULONG mMaxNumFEs; // Max number of us
public:
CEnumFormatEtc(LPUNKNOWN, ULONG, LPFORMATETC);
CEnumFormatEtc(LPUNKNOWN, ULONG aMaxSize);
CEnumFormatEtc(ULONG, LPFORMATETC);
CEnumFormatEtc(ULONG aMaxSize);
~CEnumFormatEtc(void);
//IUnknown members that delegate to m_pUnkOuter.