diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /datamodel/dmelementfactoryhelper.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'datamodel/dmelementfactoryhelper.cpp')
| -rw-r--r-- | datamodel/dmelementfactoryhelper.cpp | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/datamodel/dmelementfactoryhelper.cpp b/datamodel/dmelementfactoryhelper.cpp new file mode 100644 index 0000000..4a71c87 --- /dev/null +++ b/datamodel/dmelementfactoryhelper.cpp @@ -0,0 +1,100 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "datamodel/dmelementfactoryhelper.h" +#include "tier0/dbg.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +CDmElementFactoryHelper *CDmElementFactoryHelper::s_pHelpers[2] = { NULL, NULL }; + + +//----------------------------------------------------------------------------- +// Constructor +//----------------------------------------------------------------------------- +CDmElementFactoryHelper::CDmElementFactoryHelper( const char *classname, IDmElementFactoryInternal *pFactory, bool bIsStandardFactory ) +{ + m_pNext = s_pHelpers[bIsStandardFactory]; + s_pHelpers[bIsStandardFactory] = this; + + // Set attributes + Assert( pFactory ); + m_pFactory = pFactory; + Assert( classname ); + m_pszClassname = classname; +} + +//----------------------------------------------------------------------------- +// Purpose: Returns next object in list +// Output : CDmElementFactoryHelper +//----------------------------------------------------------------------------- +CDmElementFactoryHelper *CDmElementFactoryHelper::GetNext( void ) +{ + return m_pNext; +} + + +//----------------------------------------------------------------------------- +// Installs all factories into the datamodel system +//----------------------------------------------------------------------------- +// NOTE: The name of this extern is defined by the macro IMPLEMENT_ELEMENT_FACTORY +extern CDmElementFactoryHelper g_CDmElement_Helper; + +void CDmElementFactoryHelper::InstallFactories( ) +{ + // Just set up the type symbols of the other factories + CDmElementFactoryHelper *p = s_pHelpers[0]; + while ( p ) + { + // Add factories to database + if ( !p->GetFactory()->IsAbstract() ) + { + g_pDataModel->AddElementFactory( p->GetClassname(), p->GetFactory() ); + } + + // Set up the type symbol. Note this can't be done at + // constructor time since we don't have a DataModel pointer then + p->GetFactory()->SetElementTypeSymbol( g_pDataModel->GetSymbol( p->GetClassname() ) ); + p = p->GetNext(); + } + + p = s_pHelpers[1]; + while ( p ) + { + // Add factories to database, but not if they've been overridden + if ( !g_pDataModel->HasElementFactory( p->GetClassname() ) ) + { + if ( !p->GetFactory()->IsAbstract() ) + { + g_pDataModel->AddElementFactory( p->GetClassname(), p->GetFactory() ); + } + + // Set up the type symbol. Note this can't be done at + // constructor time since we don't have a DataModel pointer then + + // Backward compat--don't let the type symbol be 'DmeElement' + if ( Q_stricmp( p->GetClassname(), "DmeElement" ) ) + { + p->GetFactory()->SetElementTypeSymbol( g_pDataModel->GetSymbol( p->GetClassname() ) ); + } + } + + p = p->GetNext(); + } + + // Also install the DmElement factory as the default factory + g_pDataModel->SetDefaultElementFactory( g_CDmElement_Helper.GetFactory() ); +} + + +//----------------------------------------------------------------------------- +// Installs all DmElement factories +//----------------------------------------------------------------------------- +void InstallDmElementFactories( ) +{ + CDmElementFactoryHelper::InstallFactories( ); +} |