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.

137 lines
3.7 KiB
C++

#pragma once
#include "GlobalDefine.h"
#include "WorkFileLable.h"
//存储数据的类型
enum VAL_TYPE
{
_TYPE_NULL = 0,//表示无数据
_TYPE_INT,
_TYPE_DOUBLE,
_TYPE_STRING,
_TYPE_BOOL,
};
//一个用于存储的标签
class CLab
{
public:
CLab()
{
m_ValType = _TYPE_NULL;
};
CLab(LAB_TYPE LabType)
{
m_ValType = _TYPE_NULL;
m_LabType = LabType;
};
CLab(LAB_TYPE LabType,int val)
{
m_ValType = _TYPE_INT;
m_LabType = LabType;
m_Int = val;
};
CLab(LAB_TYPE LabType,double val)
{
m_ValType = _TYPE_DOUBLE;
m_LabType = LabType;
m_Double = val;
};
CLab(LAB_TYPE LabType,bool val)
{
m_ValType = _TYPE_BOOL;
m_LabType = LabType;
m_Bool = val;
};
CLab(LAB_TYPE LabType,CString val)
{
m_ValType = _TYPE_STRING;
m_LabType = LabType;
m_String = val;
};
~CLab(void){};
void Serialize( CArchive& ar)
{
if(ar.IsStoring())
{
ar<<(int)m_ValType;//数据的类型
ar<<(int)m_LabType;//标签的类型
switch(m_ValType)//根据数据的类型来选择存储对象
{
case _TYPE_INT:
ar<<m_Int;
break;
case _TYPE_DOUBLE:
ar<<m_Double;
break;
case _TYPE_BOOL:
ar<<m_Bool;
break;
case _TYPE_STRING:
ar<<m_String;
break;
default:
break;
}
}
else
{
int tmp;
ar>>tmp;//数据的类型
m_ValType = (VAL_TYPE)tmp;
ar>>tmp;//标签的类型
m_LabType = (LAB_TYPE)tmp;
switch(m_ValType)//根据数据的类型来选择存储对象
{
case _TYPE_INT:
ar>>m_Int;
break;
case _TYPE_DOUBLE:
ar>>m_Double;
break;
case _TYPE_BOOL:
ar>>m_Bool;
break;
case _TYPE_STRING:
ar>>m_String;
break;
default:
break;
}
}
}
public:
VAL_TYPE m_ValType;//数据的类型
LAB_TYPE m_LabType;//标签的类型
int m_Int;//用于存储整型
double m_Double;//用于存储双精度
bool m_Bool;//用于存储布尔型
CString m_String;
};
//管理vector<CString> 的一段范围,目的是增加读取文件算法的速度
class CLabVecRang
{
public:
CLabVecRang(vector<CLab> &vec,size_t start,size_t End)
:m_vec(vec),m_start(start),m_End(End)
{
};
~CLabVecRang(void){};
int GetStart(){return m_start;}
int GetEnd(){return m_End;}
CLab &GetLab(int idx){return m_vec[idx];};
LAB_TYPE GetLabType(int idx){return m_vec[idx].m_LabType;};
int GetInt(int idx){return m_vec[idx].m_Int;};
double GetDouble(int idx){return m_vec[idx].m_Double;};
bool GetBool(int idx){return m_vec[idx].m_Bool;};
vector<CLab> &GetVec(){return m_vec;};
private:
vector<CLab> &m_vec;
size_t m_start;
size_t m_End;
};