objreg.h

来自「C++、MFC源代码Singleton_demo」· C头文件 代码 · 共 55 行

H
55
字号
// ObjReg.h : interface and implementation of CObjRegistry class
//
/////////////////////////////////////////////////////////////////////////////

// Object registry is used for storing, runtime class information of the 
// objects.  Given the key or the class name, it queries and returns the Runtime Class
// to the client

// Written by : T. Kulathu Sarma

// This file is part of Singleton application to demonstrate the concept of Singleton classes.
// This file is provided "as is" with no expressed or implied warranty.

#ifndef _OBJ_REGISTRY
#define _OBJ_REGISTRY

class CObjRegistry
{
	// Constructor
	public :
		CObjRegistry( CRuntimeClass * pRuntimeClass, LPCSTR lpszKey = NULL )
		{
			ASSERT( pRuntimeClass != NULL );
			if( lpszKey == NULL )
			{
				GetRegistry().SetAt( pRuntimeClass->m_lpszClassName, pRuntimeClass );
			}
			else
			{
				GetRegistry().SetAt( lpszKey, pRuntimeClass );
			}
		}

	// Static members, to operate on the registry
	public :
		static BOOL GetRuntimeClass( LPCSTR lpszKey, CRuntimeClass * & rpRuntimeClass )
		{
			return GetRegistry().Lookup( lpszKey, ( LPVOID & ) rpRuntimeClass );
		}
		static INT GetCount()
		{
			return GetRegistry().GetCount();
		}

	// Implementation - Method to return reference to Static Registry object
	private :
		static CMapStringToPtr & GetRegistry()
		{
			static CMapStringToPtr	Registry;

			return Registry;
		}
};
#endif

⌨️ 快捷键说明

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