📄 itembase.cpp
字号:
// ItemBase.cpp: implementation of the CItemBase class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ItemBase.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CItemBase::CItemBase()
{
}
CItemBase::~CItemBase()
{
}
int CItemBase::SetAttr(CString strAttrName, CString strAttrValue)
{
int nErr=ERROR_NONE;
if (!strAttrName.IsEmpty())
{
m_mapAttr[strAttrName] = strAttrValue;
}
else
{
nErr=ERROR_FUNC_PARAM_INVALID;
}
return nErr;
}
int CItemBase::GetAttr(CString strAttrName, CString& strAttrValue)
{
int nErr=ERROR_NONE;
if (!strAttrName.IsEmpty())
{
strAttrValue = m_mapAttr[strAttrName];
}
else
{
nErr=ERROR_FUNC_PARAM_INVALID;
}
return nErr;
}
int CItemBase::GetAttr(CString strAttrName, int& nAttrValue)
{
CString strAttrValue;
int nErr=GetAttr(strAttrName, strAttrValue);
nAttrValue = atoi(strAttrValue);
return nErr;
}
int CItemBase::SetItem(CItemBase* pItemBase)
{
return ERROR_FUNC_NOT_IMPLEMENT;
}
CItemBase* CItemBase::GetItem(CString strItemName)
{
CItemBase* pRet=NULL;
return pRet;
}
BOOL CItemBase::FindAttr(CString strAttrName, CItemBase** pItemBase)
{
*pItemBase = NULL;
CString strAttrValue;
BOOL bRet=m_mapAttr.Lookup(strAttrName, strAttrValue);
if (bRet) *pItemBase = this;
return bRet;
}
CItemBase* CItemBase::GetItem(CStringArray aAttrName, CStringArray aAttrValue)
{
CItemBase* pRet=NULL;
return pRet;
}
//////////////////////////////////////////////////////////////////////////
// CItemComposite
//////////////////////////////////////////////////////////////////////////
CItemComposite::CItemComposite()
{
}
CItemComposite::~CItemComposite()
{
for (POSITION pos=m_plItem.GetHeadPosition(); pos!=NULL;)
{
CItemBase* pItemBase=(CItemBase*)m_plItem.GetNext(pos);
if (pItemBase!=NULL) delete pItemBase;
}
m_plItem.RemoveAll();
}
int CItemComposite::SetItem(CItemBase* pItemBase)
{
int nErr=ERROR_NONE;
if (pItemBase==NULL)
{
nErr = ERROR_FUNC_PARAM_INVALID;
return nErr;
}
BOOL bFindItem=FALSE;
for (POSITION pos=m_plItem.GetHeadPosition(); pos!=NULL;)
{
CItemBase* pItemChild=(CItemBase*)m_plItem.GetNext(pos);
if (pItemChild==pItemBase)
{
bFindItem = TRUE;
break;
}
}
if (!bFindItem) m_plItem.AddHead(pItemBase);
else nErr = ERROR_ITEMCOMPOSITE_FIND_ITEM;
return nErr;
}
CItemBase* CItemComposite::GetItem(CString strItemName)
{
CItemBase* pRet=NULL;
CString strCheckName;
for (POSITION pos=m_plItem.GetHeadPosition(); pos!=NULL;)
{
CItemBase* pItemChild=(CItemBase*)m_plItem.GetNext(pos);
if (pItemChild==NULL) continue;
pItemChild->GetAttr(XML_ATTR_ITEM_NAME, strCheckName);
if (strCheckName.CompareNoCase(strItemName)==0)
{
pRet = pItemChild;
break;
}
}
return pRet;
}
BOOL CItemComposite::FindAttr(CString strAttrName, CItemBase** pItemBase)
{
*pItemBase = NULL;
BOOL bRet=CItemBase::FindAttr(strAttrName, pItemBase);
if(!bRet)
{
for (POSITION pos=m_plItem.GetHeadPosition(); pos!=NULL;)
{
CItemBase* pItemChild=(CItemBase*)m_plItem.GetNext(pos);
if (pItemChild==NULL) continue;
bRet = pItemChild->FindAttr(strAttrName, pItemBase);
if (bRet) break;
}
}
return bRet;
}
CItemBase* CItemComposite::GetItem(CStringArray aAttrName, CStringArray aAttrValue)
{
CItemBase* pRet=NULL;
if (aAttrName.GetSize()==0 ||
aAttrName.GetSize()!=aAttrValue.GetSize())
return pRet;
CString strAttrName, strAttrValue, strCheckValue;
for (POSITION pos=m_plItem.GetHeadPosition(); pos!=NULL;)
{
CItemBase* pItemChild=(CItemBase*)m_plItem.GetNext(pos);
if (pItemChild==NULL) continue;
BOOL bAttrMatch=TRUE;
for (int i=0; i<aAttrName.GetSize(); i++)
{
strAttrName=aAttrName[i];
strAttrValue=aAttrValue[i];
pItemChild->GetAttr(strAttrName, strCheckValue);
if (strCheckValue.CompareNoCase(strAttrValue)!=0)
{
bAttrMatch = FALSE;
break;
}
}
if (bAttrMatch)
{
pRet = pItemChild;
break;
}
}
return pRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -