一个郁闷的问题,请高手指点!(一部分代码)
本人用到以下三个类,在VC++6.0中编译不过,请高手给予指点,谢谢!
//CPersistBase.h如下:
//////////////////////////////////////////////////////////////////////
//模块功能: 定义持久化对象的接口,任何对象如果实现了该接口,即声明它是持久对象。它有如下访问器属性:
// Oid:对象的唯一标识符。
// IsProxy:表示对象只是一个代理。每个持久对象都可以有自己的代理,
// TimeStamp:时间戳
// Persisted:用于指示对象数据是否已经保存在持久机制。false表示新建对象,其数据从来没有
// 保存到机制,或已从持久机制永久删除。
// Location:只是存取对象的持久机制是哪个,也就是持久机制在连接结构树中的位置。
// GenerateOid:产生对象的OID号
// ClassName:持久化类的名称
// 方法如下:
// Retrieve:请求从持久机制装载对象的数据。
// Save:请求将对象数据保存到持久机制,若Persisted为False,则在持久机制新增对象数据,
// 否则更新对象数据。
// Delete:请求从持久机制删除对象。
// Clear:对象将自己的状态改变到默认状态。
//---------------------------------------------------------------------------
#if !defined(AFX_PERSISTBASE_H__F6A0F199_96BD_4699_A602_EA5B8DC5EDD9__INCLUDED_)
#define AFX_PERSISTBASE_H__F6A0F199_96BD_4699_A602_EA5B8DC5EDD9__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "stdafx.h"
#include <string>
using std::string;
//声明作为持久化类的部分成员变量和方法
#define DECLARE_PERSIST \
public: \
void Clear();\
bool Retrieve(); \
bool Save(); \
bool Delete(); \
double GenerateOid();\
string GetClassName();\ protected:\
static string m_strClassName;
//初始化成员变量并实现部分持久化类的方法
#define IMPLEMENT_PERSIST(CLASSNAME,DBCLASS) \
string CLASSNAME::m_strClassName=#CLASSNAME;\
bool CLASSNAME::Retrieve() \
{ \
if(GetOid()==0) return false;\
return DBCLASS::Load(this); \
} \
bool CLASSNAME::Save()\
{ \
if(GetOid()==0) return false;\
if(GetPersisted()) \
{ \
return DBCLASS::Update(this);\
} \
else \
{ \
return DBCLASS::Insert(this);\
} \
} \
bool CLASSNAME::Delete()\
{ \
if(GetOid()==0) return false;\
return DBCLASS::Delete(this);\
} \
double CLASSNAME::GenerateOid()\
{ \
return DBCLASS::GenerateSequence(this);\
} \
string CLASSNAME::GetClassName()\
{\
return m_strClassName;\
}
//--------------------------------------------------------------------------
class CPersistBase
{
public:
CPersistBase();
virtual ~CPersistBase();
double GetOid();
void SetOid(double blnOid);
bool GetIsProxy();
void SetIsProxy(bool blnIsProxy);
void SetTimestamp(CTime datetime);
CTime GetTimestamp();
void SetPersisted(bool blnPersisted);
bool GetPersisted();
virtual string GetLocation();
virtual void SetLocation(const string location);
virtual void Clear();//清空对象状态,派生类需要改写,并调用基类的该方法
virtual string GetClassName()=0;//该方法在派生类中由IMPLEMENTCLASSNAME宏来实现
virtual bool Retrieve()=0;
virtual bool Save()=0;
virtual bool Delete()=0;
virtual double GenerateOid()=0;//产生对象的OID号
private:
bool m_blnIsPersisted;//true--数据已持久化(默认值),false--新建对象
bool m_blnIsProxy; //是否是个代理,默认值为false
CTime m_Timestamp;//时间戳,默认为空
double m_dblOid; //对象ID,默认值为0,当为零时不能对其进行持久化
string m_strLocation;//持持久化机制的位置,默认为空,目前没有使用
//DECLARECLASSNAME //派生类在此添加该宏来声明对类名的支持
};
#endif // !defined(AFX_PERSISTBASE_H__F6A0F199_96BD_4699_A602_EA5B8DC5EDD9__INCLUDED_)
// PersistBase.cpp如下:
#include "stdafx.h"
#include "PersistBase.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//IMPLEMENTCLASSNAME(KPersistentObject)//派生类在此添加该宏来支持类名
CPersistBase::CPersistBase()
:m_Timestamp(0),m_strLocation("")
{
m_dblOid=0;
m_blnIsPersisted=true;
m_blnIsProxy=false;
}
//////////////////////////////////////////////////////////////////////////
CPersistBase::~CPersistBase()
{
}
//////////////////////////////////////////////////////////////////////////
double CPersistBase::GetOid()
{
return m_dblOid;
}
//////////////////////////////////////////////////////////////////////////
void CPersistBase::SetOid(double blnOid)
{
m_dblOid=blnOid;
}//////////////////////////////////////////////////////////////////////////
bool CPersistBase::GetIsProxy()
{
return m_blnIsProxy;
}
//////////////////////////////////////////////////////////////////////////
void CPersistBase::SetIsProxy(bool blnIsProxy)
{
m_blnIsProxy=blnIsProxy;
}
//////////////////////////////////////////////////////////////////////////
void CPersistBase::SetTimestamp(CTime datetime)
{
m_Timestamp=datetime;
}
//////////////////////////////////////////////////////////////////////////
CTime CPersistBase::GetTimestamp()
{
return m_Timestamp;
}
//////////////////////////////////////////////////////////////////////////
void CPersistBase::SetPersisted(bool blnPersisted)
{
m_blnIsPersisted=blnPersisted;
}
//////////////////////////////////////////////////////////////////////////
bool CPersistBase::GetPersisted()
{
return m_blnIsPersisted;
}
//////////////////////////////////////////////////////////////////////////
string CPersistBase::GetLocation()
{
return m_strLocation;
}
//////////////////////////////////////////////////////////////////////////
void CPersistBase::SetLocation(const string location)
{
m_strLocation=location;
}
//////////////////////////////////////////////////////////////////////////
void CPersistBase::Clear()//清空对象状态
{
m_blnIsPersisted=true; //true--数据已持久化(默认值),false--新建对象
m_blnIsProxy=false; //是否是个代理,默认值为false
m_Timestamp=0; //时间戳,默认为空
m_dblOid=0; //对象ID,默认值为0,当为零时不能对其进行持久化
m_strLocation=""; //持久化机制的位置,默认为空,目前没有使用
}
//////////////////////////////////////////////////////////////////////////
问题点数:0、回复次数:1Top
1 楼ycliycli(杏林居士)回复于 2006-03-03 20:40:51 得分 0
还有两个类的代码如下:
// DBDepartment.h如下
#if !defined(AFX_DBDEPARTMENT_H__34AF42EC_F955_4146_ACF2_75E39BC3A7D5__INCLUDED_)
#define AFX_DBDEPARTMENT_H__34AF42EC_F955_4146_ACF2_75E39BC3A7D5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "pdepartment.h"
class CPDepartment;
class CDBDepartment
{
public:
CDBDepartment();
~CDBDepartment();
public:
static bool Load(CPDepartment *pCP);
static bool Insert(CPDepartment *const pCP);
static bool Update(CPDepartment *const pCP);
static bool Delete(CPDepartment *const pCP);
static double GenerateSequence(CPDepartment* const pCP);
};
#endif // !defined(AFX_DBDEPARTMENT_H__34AF42EC_F955_4146_ACF2_75E39BC3A7D5__INCLUDED_)
// DBDepartment.cpp如下
#include "stdafx.h"
#include "DBDepartment.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDBDepartment::CDBDepartment()
{
}
CDBDepartment::~CDBDepartment()
{
}
bool CDBDepartment::Load(CPDepartment *pCP)
{
return true;
}
bool CDBDepartment::Insert(CPDepartment *const pCP)
{
return true;
}
bool CDBDepartment::Update(CPDepartment *const pCP)
{
return true;
}
bool CDBDepartment::Delete(CPDepartment *const pCP)
{
return true;
}
double CDBDepartment::GenerateSequence(CPDepartment* const pCP)
{
if(!pCP)return 0;
}
/////////////////////////////////////////////////////////////////////////////////////
// PDepartment.h如下
#if !defined(AFX_PDEPARTMENT_H__5E9AF338_D71B_4EEF_B6AE_3C0759A309B1__INCLUDED_)
#define AFX_PDEPARTMENT_H__5E9AF338_D71B_4EEF_B6AE_3C0759A309B1__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "dbdepartment.h"
#include "PersistBase.h"
class CDBDepartment;
class CPDepartment : public CPersistBase
{
public:
CPDepartment();
virtual ~CPDepartment();
DECLARE_PERSIST
};
#endif // !defined(AFX_PDEPARTMENT_H__5E9AF338_D71B_4EEF_B6AE_3C0759A309B1__INCLUDED_)
// PDepartment.cpp如下
#include "stdafx.h"
#include "PDepartment.h"
#include "DBDepartment.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_PERSIST(CPDepartment,CDBDepartment)
CPDepartment::CPDepartment()
{
}
CPDepartment::~CPDepartment()
{
}
Top




