#include "StdAfx.h"
|
#include "MBBaseDocMgr.h"
|
|
IMPLEMENT_DYNAMIC(CMBBaseDocMgr, CMBAbstBaseObj)
|
|
CMBBaseDocMgr::CMBBaseDocMgr(void)
|
{
|
RemoveAllDocObj();
|
}
|
|
|
CMBBaseDocMgr::~CMBBaseDocMgr(void)
|
{
|
RemoveAllDocObj();
|
}
|
|
bool CMBBaseDocMgr::AddDocObj(CMBBaseDocObj *pDocObj)
|
{
|
if( NULL == pDocObj || pDocObj->m_strID.IsEmpty() )
|
return false;
|
|
CMBBaseDocObjMap::iterator it;
|
CString strID;
|
|
strID = pDocObj->m_strID;
|
it = m_mapDocObj.find(strID);
|
|
// Èç¹ûÕҵõ½ ·µ»Ø
|
if( it != m_mapDocObj.end() )
|
return false;
|
|
m_mapDocObj[strID] = pDocObj;
|
m_vecotrDocObj.push_back(pDocObj);
|
return true;
|
}
|
|
CMBBaseDocObj* CMBBaseDocMgr::GetDocObj( CString strID )
|
{
|
if( strID.IsEmpty() )
|
{
|
return NULL;
|
}
|
|
CMBBaseDocObjMap::iterator it;
|
CMBBaseDocObj *pDocInfo = NULL;
|
|
it = m_mapDocObj.find(strID);
|
|
if( it!= m_mapDocObj.end() )
|
pDocInfo = it->second;
|
|
return pDocInfo;
|
}
|
|
// Çå¿ÕÈÝÆ÷
|
void CMBBaseDocMgr::EmptyContainer()
|
{
|
m_mapDocObj.clear();
|
m_vecotrDocObj.clear();
|
}
|
|
bool CMBBaseDocMgr::RemoveAllDocObj()
|
{
|
CMBBaseDocObjMap::iterator it;
|
CMBBaseDocObj *pDocObj = NULL;
|
|
for( it = m_mapDocObj.begin();it != m_mapDocObj.end();it++ )
|
{
|
pDocObj = it->second;
|
delete pDocObj;
|
pDocObj = NULL;
|
}
|
m_mapDocObj.clear();
|
m_vecotrDocObj.clear();
|
return true;
|
}
|
|
bool CMBBaseDocMgr::GetBaseObjVector( CMBBaseObjVector &vectorObj )
|
{
|
CMBBaseDocObjVector::iterator it;
|
CMBBaseDocObj *pDocObj = NULL;
|
|
for( it = m_vecotrDocObj.begin();it != m_vecotrDocObj.end();it++ )
|
{
|
pDocObj = *it;
|
vectorObj.push_back(pDocObj);
|
}
|
|
return true;
|
}
|
|
bool CMBBaseDocMgr::RemoveDocObj( CMBBaseDocObj *pDocObj )
|
{
|
bool bDelte = false;
|
if( NULL == pDocObj )
|
return false;
|
CMBBaseDocObjMap::iterator it = m_mapDocObj.find(pDocObj->m_strID);
|
|
if( it!= m_mapDocObj.end() )
|
{
|
bDelte = true;
|
m_mapDocObj.erase(it);
|
}
|
CMBBaseDocObjVector::iterator it1 = std::find(m_vecotrDocObj.begin( ), m_vecotrDocObj.end( ), pDocObj); //²éÕÒ3
|
if( it1 != m_vecotrDocObj.end( ) ){
|
bDelte = true;
|
m_vecotrDocObj.erase(it1);
|
}
|
if( bDelte ){
|
delete pDocObj;
|
pDocObj = NULL;
|
}
|
return true;
|
}
|
|
// ÒÆ³ýÎļþÐÅÏ¢
|
bool CMBBaseDocMgr::RemoveDocObj( CString strID )
|
{
|
CMBBaseDocObj *pBase= GetDocObj( strID );
|
return RemoveDocObj( pBase );
|
}
|
|
void CMBBaseDocMgr::GetDocObjMap( CMBBaseDocObjMap &mapDocObj)
|
{
|
mapDocObj.clear();
|
mapDocObj = m_mapDocObj;
|
}
|
|
void CMBBaseDocMgr::GetDocObjVector( CMBBaseDocObjVector &vecotrDocObj)
|
{
|
vecotrDocObj.clear();
|
vecotrDocObj = m_vecotrDocObj;
|
}
|
|
// ÒÀ¸½ÓÚ¶ÔÏóÊý×é
|
//void CMBBaseDocMgr::AttachObjVector( CMBBaseObjVector &objVecotr )
|
//{
|
//
|
//}
|
|
void CMBBaseDocMgr::SetAllCheck( bool bCheck )
|
{
|
CMBBaseDocObjMap::iterator it;
|
CMBBaseDocObj *pDocObj = NULL;
|
|
for( it = m_mapDocObj.begin();it != m_mapDocObj.end();it++ )
|
{
|
pDocObj = it->second;
|
pDocObj->m_bCheck = bCheck;
|
}
|
}
|
|
|
int CMBBaseDocMgr::GetCount()
|
{
|
return m_mapDocObj.size();
|
}
|
|
|