?? myobjcollection.cpp
字號:
// MyObjCollection.cpp: implementation of the CMyObjCollection class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "TestUndo.h"
#include "MyObjCollection.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMyObjCollection::CMyObjCollection()
{
}
CMyObjCollection::~CMyObjCollection()
{
Clear();
}
int CMyObjCollection::getCount()
{
return m_vecMyObjects.size();
}
CMyObject* CMyObjCollection::getItem(int index)
{
return m_vecMyObjects[index];
}
bool CMyObjCollection::IsEmpty()
{
return (m_vecMyObjects.size() == 0);
}
void CMyObjCollection::Add(CMyObject* pItem)
{
ASSERT(Find(pItem) == -1); // 不能多次加入同一對象
m_vecMyObjects.push_back(pItem);
pItem->AddRef();
}
void CMyObjCollection::Remove(CMyObject* pItem)
{
for (vector<CMyObject*>::iterator it = m_vecMyObjects.begin();
it != m_vecMyObjects.end(); it++)
{
if (*it == pItem)
{
m_vecMyObjects.erase(it);
pItem->Release();
return;
}
}
}
void CMyObjCollection::RemoveAt(int index)
{
CMyObject* pItem = m_vecMyObjects[index];
m_vecMyObjects.erase(m_vecMyObjects.begin() + index);
pItem->Release();
}
void CMyObjCollection::Clear()
{
for (int i = 0; i < m_vecMyObjects.size(); i++)
m_vecMyObjects[i]->Release();
m_vecMyObjects.erase(m_vecMyObjects.begin(), m_vecMyObjects.end());
}
bool CMyObjCollection::Contains(CMyObject* pItem)
{
return (Find(pItem) != -1);
}
int CMyObjCollection::Find(CMyObject* pItem)
{
for (int i = 0; i < m_vecMyObjects.size(); i++)
{
if (m_vecMyObjects[i] == pItem)
return i;
}
return -1;
}
CMyObject* CMyObjCollection::operator [] (int index)
{
return m_vecMyObjects[index];
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -