pred@1922: /**
pred@1922: * vim: set ts=4 :
pred@1922: * =============================================================================
pred@1922: * SourceMod SDKTools Extension
pred@1922: * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
pred@1922: * =============================================================================
pred@1922: *
pred@1922: * This program is free software; you can redistribute it and/or modify it under
pred@1922: * the terms of the GNU General Public License, version 3.0, as published by the
pred@1922: * Free Software Foundation.
pred@1922: *
pred@1922: * This program is distributed in the hope that it will be useful, but WITHOUT
pred@1922: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
pred@1922: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
pred@1922: * details.
pred@1922: *
pred@1922: * You should have received a copy of the GNU General Public License along with
pred@1922: * this program. If not, see .
pred@1922: *
pred@1922: * As a special exception, AlliedModders LLC gives you permission to link the
pred@1922: * code of this program (as well as its derivative works) to "Half-Life 2," the
pred@1922: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
pred@1922: * by the Valve Corporation. You must obey the GNU General Public License in
pred@1922: * all respects for all other code used. Additionally, AlliedModders LLC grants
pred@1922: * this exception to all derivative works. AlliedModders LLC defines further
pred@1922: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
pred@1922: * or .
pred@1922: *
pred@1922: * Version: $Id: vcallbuilder.h 1566 2007-10-14 22:12:46Z faluco $
pred@1922: */
pred@1922:
pred@1922: #ifndef _INCLUDE_SOURCEMOD_UTIL_H_
pred@1922: #define _INCLUDE_SOURCEMOD_UTIL_H_
pred@1922:
pred@1922: #include "utldict.h"
pred@1922:
pred@1922: abstract_class IEntityFactory
pred@1922: {
pred@1922: public:
pred@1922: virtual IServerNetworkable *Create( const char *pClassName ) = 0;
pred@1922: virtual void Destroy( IServerNetworkable *pNetworkable ) = 0;
pred@1922: virtual size_t GetEntitySize() = 0;
pred@1922: };
pred@1922:
pred@1922: template
pred@1922: class CEntityFactory : public IEntityFactory
pred@1922: {
pred@1922: public:
pred@1922: CEntityFactory( const char *pClassName )
pred@1922: {
pred@1922: EntityFactoryDictionary()->InstallFactory( this, pClassName );
pred@1922: }
pred@1922:
pred@1922: IServerNetworkable *Create( const char *pClassName )
pred@1922: {
pred@1922: T* pEnt = _CreateEntityTemplate((T*)NULL, pClassName);
pred@1922: return pEnt->NetworkProp();
pred@1922: }
pred@1922:
pred@1922: void Destroy( IServerNetworkable *pNetworkable )
pred@1922: {
pred@1922: if ( pNetworkable )
pred@1922: {
pred@1922: pNetworkable->Release();
pred@1922: }
pred@1922: }
pred@1922:
pred@1922: virtual size_t GetEntitySize()
pred@1922: {
pred@1922: return sizeof(T);
pred@1922: }
pred@1922: };
pred@1922:
pred@1922: abstract_class IEntityFactoryDictionary
pred@1922: {
pred@1922: public:
pred@1922: virtual void InstallFactory( IEntityFactory *pFactory, const char *pClassName ) = 0;
pred@1922: virtual IServerNetworkable *Create( const char *pClassName ) = 0;
pred@1922: virtual void Destroy( const char *pClassName, IServerNetworkable *pNetworkable ) = 0;
pred@1922: virtual IEntityFactory *FindFactory( const char *pClassName ) = 0;
pred@1922: virtual const char *GetCannonicalName( const char *pClassName ) = 0;
pred@1922: };
pred@1922:
pred@1922:
pred@1922: class CEntityFactoryDictionary : public IEntityFactoryDictionary
pred@1922: {
pred@1922: public:
pred@1922: CEntityFactoryDictionary();
pred@1922:
pred@1922: virtual void InstallFactory( IEntityFactory *pFactory, const char *pClassName );
pred@1922: virtual IServerNetworkable *Create( const char *pClassName );
pred@1922: virtual void Destroy( const char *pClassName, IServerNetworkable *pNetworkable );
pred@1922: virtual const char *GetCannonicalName( const char *pClassName );
pred@1922: void ReportEntitySizes();
pred@1922:
pred@1922: private:
pred@1922: IEntityFactory *FindFactory( const char *pClassName );
pred@1922: public:
pred@1922: CUtlDict< IEntityFactory *, unsigned short > m_Factories;
pred@1922: };
pred@1922:
pred@1922: #endif //_INCLUDE_SOURCEMOD_UTIL_H_