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++
144 lines
3.4 KiB
C++
#include "StdAfx.h"
|
|
#include "ValString.h"
|
|
|
|
|
|
CValString::CValString(void)
|
|
{
|
|
m_bValStr = false;//是否可变
|
|
}
|
|
CValString::~CValString(void)
|
|
{
|
|
m_ValStrVec.clear();
|
|
}
|
|
//复制
|
|
void CValString::Copy(CValString &rhs)
|
|
{
|
|
m_ValStrVec.clear();
|
|
|
|
m_bValStr = rhs.m_bValStr;//是否可变
|
|
m_String = rhs.m_String;
|
|
//可变文本列表
|
|
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)
|
|
{
|
|
//保存到智能指针
|
|
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," ");//插入一行
|
|
List.SetItemText(i,0,m_ValStrVec[i]->GetTypeStr());//第一列
|
|
List.SetItemText(i,1,m_ValStrVec[i]->GetValStr());//第二列
|
|
}
|
|
}
|
|
//检查idx 是否有效
|
|
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++;
|
|
}
|
|
}
|
|
//获取idx 对应可变文本的类型
|
|
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;
|
|
}
|
|
//交换
|
|
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;
|
|
}
|
|
//获取索引idx 对应的可变字符的指针
|
|
CValStrBase *CValString::GetValStrPtr(int idx)
|
|
{
|
|
if(!IdxValid(idx))
|
|
return NULL;
|
|
return m_ValStrVec[idx].GetPtr();
|
|
}
|
|
//获取可变文本当前的字符串
|
|
CString CValString::GetString()
|
|
{
|
|
if(m_bValStr)//可变文本
|
|
{
|
|
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 == "")//防止产生空字符串
|
|
{
|
|
//m_String = "TEXT";
|
|
m_String = "Text";
|
|
}
|
|
return m_String;
|
|
}
|
|
void CValString::SetString(CString str)
|
|
{
|
|
//非可变文本才能设置
|
|
if(!m_bValStr)
|
|
{
|
|
m_String = str;
|
|
}
|
|
}
|
|
//更新可变文本内容
|
|
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();
|
|
}
|
|
} |