⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myobject.cpp

📁 SQLBig5BugTool 宽字符操作问题
💻 CPP
字号:
// MyObject.cpp: implementation of the CMyObject class.
//
//////////////////////////////////////////////////////////////////////

#pragma warning(disable:4786)

#include "basefunc.H"

#include <assert.h>
#include "MyObject.h"

#include <set>

#define MY_TRY //try
#define MY_CATCH() //catch(...)

/////////////////////////////////////////////////////////////////////////////
// Runtime Typing

// special runtime-class structure for CMyObject (no base class)
#ifdef _MY_OBJ_OPTIMIZE
CMyRuntimeClass* PASCAL CMyObject::_GetBaseClass()
	{ return NULL; }
CLASS_COMDAT const  struct CMyRuntimeClass CMyObject::classCMyObject =
	{ "CMyObject", sizeof(CMyObject), 0xffff, NULL, &CMyObject::_GetBaseClass, NULL,CLASSID_MY_OBJECT};
#else
CLASS_COMDAT const  struct CMyRuntimeClass CMyObject::classCMyObject =
{ "CMyObject", sizeof(CMyObject), 0xffff, NULL, NULL, NULL,CLASSID_MY_OBJECT};
#endif

BOOL WINAPI IsValidAddress( const void* lp, UINT nBytes, BOOL bReadWrite  )
{
	if(IsBadReadPtr(lp,nBytes))
	{
		return FALSE;
	}
	if(bReadWrite)
	{
		if(IsBadWritePtr((void*)lp,nBytes))
		{
			return FALSE;
		}
	}
	return TRUE;
}; 

CMyRuntimeClass* CMyObject::GetRuntimeClass() const
{
	return GET_RUNTIME_CLASS(CMyObject);
}

BOOL CMyObject::IsKindOf(const CMyRuntimeClass* pClass) const
{
	assert(this != NULL);
	// it better be in valid memory, at least for CMyObject size
	assert(IsValidAddress(this, sizeof(CMyObject)));

	// simple SI case
	CMyRuntimeClass* pClassThis = GetRuntimeClass();
	return pClassThis->IsDerivedFrom(pClass);
}

CMyObject* _cdecl MyDynamicDownCast(CMyRuntimeClass* pClass, CMyObject* pObject)
{
	if (pObject != NULL && pObject->IsKindOf(pClass))
		return pObject;
	else
		return NULL;
}

#ifdef _DEBUG
CMyObject* _cdecl MyStaticDownCast(CMyRuntimeClass* pClass, CMyObject* pObject)
{
	assert(pObject == NULL || pObject->IsKindOf(pClass));
	return pObject;
}
#endif

/////////////////////////////////////////////////////////////////////////////
// Diagnostic Support


////////////////////////////////////////////////////////////////////////////
// Allocation/Creation

CMyObject* CMyRuntimeClass::CreateObject()
{
	if (m_pfnCreateObject == NULL)
	{
		DebugMsg("m_pfnCreateObject is null");
		return NULL;
	}

	CMyObject* pObject = NULL;
	MY_TRY
	{
		pObject = (*m_pfnCreateObject)();
	}
	MY_CATCH()
	{
	}

	return pObject;
}

////////////////////////////////////////////////////////////////////////////
// Class 

BOOL CMyRuntimeClass::IsDerivedFrom(const CMyRuntimeClass* pBaseClass) const
{
	assert(this != NULL);
	assert(IsValidAddress(this, sizeof(CMyRuntimeClass), FALSE));
	assert(pBaseClass != NULL);
	assert(IsValidAddress(pBaseClass, sizeof(CMyRuntimeClass), FALSE));

	// simple SI case
	const CMyRuntimeClass* pClassThis = this;
	while (pClassThis != NULL)
	{
		if (pClassThis == pBaseClass)
			return TRUE;
#ifdef _MY_OBJ_OPTIMIZE
		pClassThis = (*pClassThis->m_pfnGetBaseClass)();
#else
		pClassThis = pClassThis->m_pBaseClass;
#endif
	}
	return FALSE;       // walked to the top, no match
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -