📄 speeddialenum.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#include "SpeedDialEnum.h"
/*------------------------------------------------------------------------------
CSpeedDialEnumerator::CSpeedDialEnumerator
Ctor
------------------------------------------------------------------------------*/
CSpeedDialEnumerator::CSpeedDialEnumerator()
{
m_Iterator = m_RecordList.begin();
}
/*------------------------------------------------------------------------------
CSpeedDialEnumerator::~CSpeedDialEnumerator
Dtor
------------------------------------------------------------------------------*/
CSpeedDialEnumerator::~CSpeedDialEnumerator()
{
RecordList::iterator it = m_RecordList.begin();
while (it != m_RecordList.end())
{
SpeedDialRecord* pRecord = *it;
pRecord->m_pRecord->Release();
delete pRecord;
it++;
}
m_RecordList.clear();
}
/*------------------------------------------------------------------------------
CSpeedDialEnumerator::Next
Standard IEnumerator Next
------------------------------------------------------------------------------*/
HRESULT STDMETHODCALLTYPE CSpeedDialEnumerator::Next(
unsigned long celt,
IVoIPCallerInfoRecord **rgCallerInfoRecord,
unsigned long FAR* pceltFetched
)
{
if (! rgCallerInfoRecord)
{
return E_FAIL;
}
if (! celt)
{
return S_FALSE;
}
int LeftToGet = celt;
int Added = 0;
while (LeftToGet)
{
if (m_Iterator == m_RecordList.end())
{
break;
}
rgCallerInfoRecord[Added] = (*m_Iterator)->m_pRecord;
rgCallerInfoRecord[Added]->AddRef();
Added++;
LeftToGet--;
m_Iterator++;
}
return (Added == celt) ? S_OK : S_FALSE;
}
/*------------------------------------------------------------------------------
CSpeedDialEnumerator::Skip
Standard IEnumerator Skip
------------------------------------------------------------------------------*/
HRESULT STDMETHODCALLTYPE CSpeedDialEnumerator::Skip(
unsigned long celt
)
{
int LeftToMove = celt;
while (LeftToMove)
{
if (m_Iterator == m_RecordList.end())
{
return S_FALSE;
}
m_Iterator++;
LeftToMove--;
}
return S_OK;
}
/*------------------------------------------------------------------------------
CSpeedDialEnumerator::Reset
Reset the seek pointer
Returns (HRESULT):
------------------------------------------------------------------------------*/
HRESULT STDMETHODCALLTYPE CSpeedDialEnumerator::Reset()
{
m_Iterator = m_RecordList.begin();
return S_OK;
}
/*------------------------------------------------------------------------------
CSpeedDialEnumerator::AddRecord
Add a record to our sorted list
------------------------------------------------------------------------------*/
HRESULT CSpeedDialEnumerator::AddRecord(
int Index,
IVoIPCallerInfoRecord* pRecord
)
{
SpeedDialRecord* pNewRecord = new SpeedDialRecord;
if (! pNewRecord)
{
return E_OUTOFMEMORY;
}
pNewRecord->m_pRecord = pRecord;
pNewRecord->m_SpeedDialIndex = Index;
pRecord->AddRef();
RecordList::iterator it = m_RecordList.begin();
RecordList::iterator Previous = m_RecordList.begin();
while (it != m_RecordList.end())
{
if ((*it)->m_SpeedDialIndex >= Index)
{
break;
}
Previous = it;
it++;
}
int PrevSize = m_RecordList.size();
//insertion logic
if (it == m_RecordList.begin())
{
m_RecordList.push_front(pNewRecord);
}
else if (it == m_RecordList.end())
{
m_RecordList.push_back(pNewRecord);
}
else
{
m_RecordList.insert(it, pNewRecord);
}
if (m_RecordList.size() <= PrevSize)
{
delete pNewRecord;
return E_OUTOFMEMORY;
}
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -