📄 cookiecollection.cpp
字号:
}
return TRUE;
}
/********************************************************************/
/* */
/* Function name : RemoveAll */
/* Description : Delete all items from the Cookie Collection. */
/* */
/********************************************************************/
void CCookieCollection::RemoveAll()
{
CCookie *pCookie;
CString strKey;
POSITION pos = m_CookieMap.GetStartPosition();
while (pos != NULL)
{
m_CookieMap.GetNextAssoc(pos, strKey, (CObject *&)pCookie);
delete pCookie;
}
m_CookieMap.RemoveAll();
}
/********************************************************************/
/* */
/* Function name : Remove */
/* Description : Delete an item from the cookie collection. */
/* */
/********************************************************************/
void CCookieCollection::Remove(const VARIANT FAR& VarKey)
{
int nIndex = -1;
if (VarKey.vt == VT_BSTR)
{
CString strName = VarKey.bstrVal;
CCookie *pCookie = NULL;
// lookup value of specified name
if (m_CookieMap.Lookup(strName, (CObject *&)pCookie))
{
m_CookieMap.RemoveKey(strName);
delete pCookie;
}
}
else
if (VarKey.vt == VT_I2)
{
nIndex = VarKey.iVal;
}
else
if (VarKey.vt == VT_I4)
{
nIndex = VarKey.lVal;
}
if (nIndex != -1)
{
int nCurIndex = 0;
CString strKey;
CCookie *pCookie;
POSITION pos = m_CookieMap.GetStartPosition();
while (pos != NULL)
{
m_CookieMap.GetNextAssoc(pos, strKey, (CObject *&)pCookie);
if (nCurIndex == nIndex)
{
m_CookieMap.RemoveKey(strKey);
delete pCookie;
break;
}
nCurIndex++;
}
}
}
/************************************************************************/
/* */
/* Function name : CCookieCollectionEnum */
/* Description : Construct enumarator class */
/* */
/************************************************************************/
CCookieCollectionEnum::CCookieCollectionEnum(CCookieCollection *pCollection)
{
m_pCollection = pCollection;
EnableAutomation();
}
CCookieCollectionEnum::~CCookieCollectionEnum()
{
}
/************************************************************************/
/* */
/* Function name : OnFinalRelease */
/* Description : Last reference is released -> delete the object. */
/* */
/************************************************************************/
void CCookieCollectionEnum::OnFinalRelease()
{
delete this;
}
BEGIN_MESSAGE_MAP(CCookieCollectionEnum, CCmdTarget)
//{{AFX_MSG_MAP(CCookieCollectionEnum)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_INTERFACE_MAP(CCookieCollectionEnum, CCmdTarget)
INTERFACE_PART(CCookieCollectionEnum, IID_IEnumVARIANT, EnumVARIANT)
END_INTERFACE_MAP()
/************************************************************************/
/* */
/* Function name : XEnumVARIANT */
/* Description : Enumerator constructor */
/* */
/************************************************************************/
CCookieCollectionEnum::XEnumVARIANT::XEnumVARIANT()
{
m_posCurrent = NULL;
}
/************************************************************************/
/* */
/* Function name : AddRef */
/* Description : */
/* */
/************************************************************************/
STDMETHODIMP_(ULONG) CCookieCollectionEnum::XEnumVARIANT::AddRef()
{
METHOD_PROLOGUE(CCookieCollectionEnum, EnumVARIANT)
return pThis->ExternalAddRef();
}
/************************************************************************/
/* */
/* Function name : IEnumVARIANT::Release */
/* Description : */
/* */
/************************************************************************/
STDMETHODIMP_(ULONG) CCookieCollectionEnum::XEnumVARIANT::Release()
{
METHOD_PROLOGUE(CCookieCollectionEnum, EnumVARIANT)
return pThis->ExternalRelease();
}
/************************************************************************/
/* */
/* Function name : IEnumVARIANT::QueryInterface */
/* Description : */
/* */
/************************************************************************/
STDMETHODIMP CCookieCollectionEnum::XEnumVARIANT::QueryInterface(REFIID iid, void FAR* FAR* ppvObj )
{
METHOD_PROLOGUE(CCookieCollectionEnum, EnumVARIANT)
return (HRESULT)pThis->ExternalQueryInterface((void FAR*)&iid, ppvObj);
}
/************************************************************************/
/* */
/* Function name : IEnumVARIANT::Next */
/* Description : Get the next celt items in the enumeration sequence. */
/* */
/************************************************************************/
STDMETHODIMP CCookieCollectionEnum::XEnumVARIANT::Next(ULONG celt, VARIANT FAR* rgvar, ULONG FAR* pceltFetched)
{
// This sets up the "pThis" pointer so that it points to the CCookieCollectionEnum instance
METHOD_PROLOGUE(CCookieCollectionEnum, EnumVARIANT)
HRESULT hr;
ULONG l;
CCookie *pCookie = NULL;
CString strKey;
// pceltFetched can legally == 0
if (pceltFetched != NULL)
{
*pceltFetched = 0;
}
else
if (celt > 1)
{
return ResultFromScode(E_INVALIDARG);
}
// initialize variants
for (l=0; l < celt; l++)
{
VariantInit(&rgvar[l]);
}
// Retrieve the next celt elements.
hr = NOERROR;
for (l = 0 ; m_posCurrent != NULL && celt != 0 ; l++)
{
pThis->m_pCollection->m_CookieMap.GetNextAssoc(m_posCurrent, strKey, (CObject *&)pCookie);
celt--;
if (pCookie)
{
CString strName;
pCookie->GetName(strName);
rgvar[l].bstrVal = strName.AllocSysString();
rgvar[l].vt = VT_BSTR;
if (pceltFetched != NULL)
(*pceltFetched)++;
}
else
return ResultFromScode(E_UNEXPECTED);
}
if (celt != 0)
{
hr = ResultFromScode(S_FALSE);
}
return hr;
}
/************************************************************************/
/* */
/* Function name : IEnumVARIANT::Skip */
/* Description : Skip over the next celt elements in the enumeration */
/* sequence. */
/* */
/************************************************************************/
STDMETHODIMP CCookieCollectionEnum::XEnumVARIANT::Skip(unsigned long celt)
{
METHOD_PROLOGUE(CCookieCollectionEnum, EnumVARIANT)
ASSERT(pThis->m_pCollection);
if (pThis->m_pCollection == NULL)
{
return ResultFromScode(E_UNEXPECTED);
}
CCookie *pCookie = NULL;
CString strKey;
while (m_posCurrent != NULL && celt--)
pThis->m_pCollection->m_CookieMap.GetNextAssoc(m_posCurrent, strKey, (CObject *&)pCookie);
return (celt == 0 ? NOERROR : ResultFromScode(S_FALSE));
}
/************************************************************************/
/* */
/* Function name : IEnumVARIANT::Reset */
/* Description : Reset postion pointer */
/* */
/************************************************************************/
STDMETHODIMP CCookieCollectionEnum::XEnumVARIANT::Reset()
{
METHOD_PROLOGUE(CCookieCollectionEnum, EnumVARIANT)
ASSERT(pThis->m_pCollection);
m_posCurrent = pThis->m_pCollection->m_CookieMap.GetStartPosition();
return NOERROR;
}
/************************************************************************/
/* */
/* Function name : IEnumVARIANT::Clone */
/* Description : Clone the collection */
/* */
/************************************************************************/
STDMETHODIMP CCookieCollectionEnum::XEnumVARIANT::Clone(IEnumVARIANT FAR* FAR* ppenum)
{
METHOD_PROLOGUE(CCookieCollectionEnum, EnumVARIANT)
CCookieCollectionEnum* p = new CCookieCollectionEnum(pThis->m_pCollection);
if (p)
{
p->m_xEnumVARIANT.m_posCurrent = m_posCurrent;
return NOERROR;
}
else
return ResultFromScode(E_OUTOFMEMORY);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -