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

📄 cppiface.h

📁 设计模式模板源码
💻 H
字号:
/////////////////////////////////////////////////////////////////////////////
// CppIface.h : Definitions and templates for C++ interfaces.
//
// $Header: $

#ifndef _XP_CPPIFACE_H__
#define _XP_CPPIFACE_H__


#include "GuidCast.h"
#include "RefCount.h"

/////////////////////////////////////////////////////////////////////////////
// CIQueryGuidImpl
//
// CIUnknownImpl is derived from this and QueryInterface is implemented in
// terms if guid_cast. This is for backward compatibility.
template<class base, const XPIID *piid = &(base::IID())>
class CIQueryGuidImpl : public base
{
public:
	virtual XPBool QueryGuid(XPREFIID guid, void **ppvObj)
	{
		*ppvObj = 0;

		if (guid == *piid) {
			*ppvObj = static_cast<base*>(this);
		}

		return (*ppvObj != 0);
	}
};


/////////////////////////////////////////////////////////////////////////////
// RefCountImpl_T

//@doc RefCountImpl_T
//@mfunc | RefCountImpl_T | RefCountImpl_T | Default constructor sets reference
// count to zero.

//@doc RefCountImpl_T
//@mfunc XPUint32 | RefCountImpl_T | AddRef | Add a reference to this object.
//@rdesc New reference count value.

//@doc RefCountImpl_T
//@mfunc XPUint32 | RefCountImpl_T | Release | Release a reference to this object.
//@rdesc New reference count value.

//@class Template to implement reference counting for an interface. This class
// derives itself from the template parameter passed in and overrides AddRef
// and Release.

template<class base_t>
class RefCountImpl_T : public base_t
{
public:

	//@cmember
	/* Constructor to set reference count to zero. */
	RefCountImpl_T()
	{
		m_ulRefCount = 0;
	}

	//@cmember
	/* Constructor to set reference count to zero. */
	XPUint32 XPSTDMETHODCALLTYPE AddRef()
	{
		return ++m_ulRefCount;
	}

	//@cmember
	/* Constructor to set reference count to zero. */
	XPUint32 XPSTDMETHODCALLTYPE Release()
	{
		XPUint32 ulRefCount = --m_ulRefCount;
		if (m_ulRefCount == 0)
			delete this;
		return ulRefCount;
	}

protected:
	//@cmember
	/* Stores reference count for object. */
	XPUint32 m_ulRefCount;
};


#endif   // _XP_CPPIFACE_H__

⌨️ 快捷键说明

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