64,642
社区成员
发帖
与我相关
我的任务
分享
class UnitRuntimeInfomation
{
//来自实体模型的字段
//READONLY_PROPERTY(private,int,ID)
READONLY_PROPERTY(private,QString,ClassName)
READONLY_PROPERTY(private,QString,Name)
READONLY_PROPERTY(private,QString,Comment)
//来自单元实体的字段
READONLY_PROPERTY(private,int,PlatformID)
READONLY_PROPERTY(private,QString,PlatformName)
READONLY_PROPERTY(private,double,DamageDegree)
READONLY_PROPERTY(private,double,PriTargetX )
READONLY_PROPERTY(private,double,PriTargetY )
READONLY_PROPERTY(private,QString,Script)
READONLY_PROPERTY(private,UnitRuntimeItem,GraphItem)
friend class UnitRuntimeInfomationHandler;
int useCount;
UnitRuntimeInfomation(const DataAccess::UnitEntity::DataRow& _unit):GraphItem(_unit)
{
ClassName=_unit.GetClassName();
Name=_unit.GetName();
Comment=_unit.GetComment();
PlatformID=_unit.GetPlatformID();
PlatformName=_unit.GetPlatformName();
DamageDegree=_unit.GetDamageDegree();
PriTargetX=_unit.GetPriTargetX();
PriTargetY=_unit.GetPriTargetY();
Script=_unit.GetScript();
}
~UnitRuntimeInfomation(){}
UnitRuntimeInfomation& operator=(const UnitRuntimeInfomation& h);
};
class UnitRuntimeInfomationHandler
{
UnitRuntimeInfomation *p;
public:
UnitRuntimeInfomationHandler():p(0){}
UnitRuntimeInfomationHandler(const DataAccess::UnitEntity::DataRow& _unit)
{
p=new UnitRuntimeInfomation(_unit);
p->useCount=1;
}
UnitRuntimeInfomationHandler(const UnitRuntimeInfomationHandler& handler ):p(handler.p){++p->useCount;}
~UnitRuntimeInfomationHandler()
{
if(p==0)return;
if(--p->useCount==0)
delete p;
}
UnitRuntimeInfomationHandler& operator=(const UnitRuntimeInfomationHandler& h)
{
++h.p->useCount;
if(--p->useCount==0)
delete p;
p=h.p;
return *this;
}
const QString GetName() const
{
return p->GetName();
}
};
void CImageW::GetDTImage(CString strPath)
{
CReadD readDicom;
//delete掉以前的m_pImage
if(m_pImage != NULL)
{
delete m_pImage;
}
m_pImage = readDicom.LocalImageData(strPath); readDicom.~CReadDicom();
}
void CImageW::GetDTImage(CString strPath)
{
CReadD readDicom;
m_pImage = readDicom.LocalImageData(strPath);
//没必要,自动析构了 readDicom.~CReadDicom();
//既然你开辟了m_pImage只是在当前函数里做一些操作,那用完就delete;
m_pImage->dosth();
delete m_pImage;
//注意,不要使用::operator delete,这个只释放内存不析构的,要使用delete;
}
CxImage* CReadDicom::LocalImageData(CString inPath)
{
CxImage * pImage = new CxImage;
......................
......................
return pImage;//这里返回即可,由上边的函数析构.
}