You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
3.4 KiB
C++

#include "StdAfx.h"
#include "ValString.h"
CValString::CValString(void)
{
m_bValStr = false;//<2F>Ƿ<EFBFBD><C7B7>ɱ<EFBFBD>
}
CValString::~CValString(void)
{
m_ValStrVec.clear();
}
//<2F><><EFBFBD><EFBFBD>
void CValString::Copy(CValString &rhs)
{
m_ValStrVec.clear();
m_bValStr = rhs.m_bValStr;//<2F>Ƿ<EFBFBD><C7B7>ɱ<EFBFBD>
m_String = rhs.m_String;
//<2F>ɱ<EFBFBD><C9B1>ı<EFBFBD><C4B1>б<EFBFBD>
vector<Sptr<CValStrBase>>::iterator iter = rhs.m_ValStrVec.begin();
vector<Sptr<CValStrBase>>::iterator iter_end = rhs.m_ValStrVec.end();
for(;iter!=iter_end;iter++)
{
CValStrBase *p = (*iter)->Clone();
AddValStr(p);
}
}
void CValString::AddValStr(CValStrBase *p)
{
//<2F><><EFBFBD><EFBFBD><E6B5BD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
Sptr<CValStrBase> sPtr(p);
m_ValStrVec.push_back(sPtr);
}
void CValString::InsertList(CListCtrl &List)
{
int size = m_ValStrVec.size();
for(int i=0;i<size;i++)
{
List.InsertItem(i," ");//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
List.SetItemText(i,0,m_ValStrVec[i]->GetTypeStr());//<2F><>һ<EFBFBD><D2BB>
List.SetItemText(i,1,m_ValStrVec[i]->GetValStr());//<2F>ڶ<EFBFBD><DAB6><EFBFBD>
}
}
//<2F><><EFBFBD><EFBFBD>idx <20>Ƿ<EFBFBD><C7B7><EFBFBD>Ч
bool CValString::IdxValid(int idx)
{
int size = m_ValStrVec.size();
if(idx<0 || idx>= size)
return false;
return true;
}
void CValString::DelSelValStr(int &idx)
{
if(!IdxValid(idx))
return;
vector<Sptr<CValStrBase>>::iterator iter = m_ValStrVec.begin();
vector<Sptr<CValStrBase>>::iterator iter_end = m_ValStrVec.end();
int i=0;
for(;iter!=iter_end;iter++)
{
if(i==idx)
{
m_ValStrVec.erase(iter);
idx = -1;
break;
}
i++;
}
}
//<2F><>ȡidx <20><>Ӧ<EFBFBD>ɱ<EFBFBD><C9B1>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
VAL_STR_TYPR CValString::GetSelValStrType(int idx)
{
if(!IdxValid(idx))
return _STR_ERROR;
vector<Sptr<CValStrBase>>::iterator iter = m_ValStrVec.begin();
vector<Sptr<CValStrBase>>::iterator iter_end = m_ValStrVec.end();
int i=0;
for(;iter!=iter_end;iter++)
{
if(i==idx)
{
return m_ValStrVec[i]->GetValStrType();
break;
}
i++;
}
return _STR_ERROR;
}
//<2F><><EFBFBD><EFBFBD>
void CValString::SwapValStr(int idx1,int idx2)
{
if(!IdxValid(idx1) || !IdxValid(idx2))
return;
Sptr<CValStrBase> p = m_ValStrVec[idx1];
m_ValStrVec[idx1] = m_ValStrVec[idx2];
m_ValStrVec[idx2] = p;
}
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>idx <20><>Ӧ<EFBFBD>Ŀɱ<C4BF><C9B1>ַ<EFBFBD><D6B7><EFBFBD>ָ<EFBFBD><D6B8>
CValStrBase *CValString::GetValStrPtr(int idx)
{
if(!IdxValid(idx))
return NULL;
return m_ValStrVec[idx].GetPtr();
}
//<2F><>ȡ<EFBFBD>ɱ<EFBFBD><C9B1>ı<EFBFBD><C4B1><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
CString CValString::GetString()
{
if(m_bValStr)//<2F>ɱ<EFBFBD><C9B1>ı<EFBFBD>
{
m_String = "";
vector<Sptr<CValStrBase>>::iterator iter = m_ValStrVec.begin();
vector<Sptr<CValStrBase>>::iterator iter_end = m_ValStrVec.end();
for(;iter!=iter_end;iter++)
{
m_String += (*iter)->GetValStr();
}
}
if(m_String == "")//<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
{
//m_String = "TEXT";
m_String = "Text";
}
return m_String;
}
void CValString::SetString(CString str)
{
//<2F>ǿɱ<C7BF><C9B1>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(!m_bValStr)
{
m_String = str;
}
}
//<2F><><EFBFBD>¿ɱ<C2BF><C9B1>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
void CValString::UpdateValStr()
{
vector<Sptr<CValStrBase>>::iterator iter = m_ValStrVec.begin();
vector<Sptr<CValStrBase>>::iterator iter_end = m_ValStrVec.end();
for(;iter!=iter_end;iter++)
{
(*iter)->UpdateValStr();
}
}